Code Monkey home page Code Monkey logo

Comments (1)

poor-bob avatar poor-bob commented on August 15, 2024

I actually can't recall why I did it this way, but here's how I implemented this package for our readinessProbe

A health route:

	// health routes
	Route::get('/health', 'HealthCheckController@index');

A custom HealthCheckController:

<?php

namespace App\Http\Controllers;

use PragmaRX\Health\Http\Controllers\Health;

class HealthCheckController extends Controller {

    public function index() {
        $services = array_map('strtolower', config('health.resources.enabled'));

        foreach($services as $service){
            $serviceHealth = app('pragmarx.health')->checkResource($service)->isHealthy();
            if (!$serviceHealth) {
                return "Service: $service is not healthy";
            }
        }
        return 'Healthy!';
    }
}

a PHP file to call call this health check by-passing laravel (this is where I'm not sure why I did it this way)

<?php

// Start output buffering (Capture STDOUT)
ob_start();

// Check that artisan ran through start.sh
//if (!file_exists('/ready')) { exit(1); }

// Check that php-fpm is running as well
$output = shell_exec('ps aux | grep [p]hp-fpm');
if (empty($output)){
    echo "Can't find php-fpm, exiting with error";
    exit(1);
}

$host = getenv('PLACEHOLDER_API_URL_NO_PROTOCOL');
if (empty($host)){
    $host = 'local.api.REMOVED.com';
}
$_SERVER['REQUEST_URI'] = '/v1.0/health';
$_SERVER['HTTP_ACCEPT'] = '*/*';
$_SERVER['HTTP_USER_AGENT'] = 'curl/7.47.0';
$_SERVER['HTTP_CONNECTION'] = 'close';
$_SERVER['HTTP_HOST'] = $host;

// Start output buffering (Capture STDOUT)
ob_start();

require_once 'server.php';

$content = ob_get_contents();

if (strpos($content, 'Healthy!') !== false) {
    // Success
    exit(0);
} else {
    // Failure
    echo "Content is not Healthy! val: $content";
    exit(1);
}
ob_end_clean();

and lastly the readinessProbe config:

        readinessProbe:
          exec:
            command:
            - php 
            - /var/www/health_check.php

There MIGHT be a reason I decided to do the HTTP request in a "health_check" php file rather than doing it from the readinessProbe, but I couldn't explain why anymore. Sorry, that was a long time ago

from health.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.