Change process manager dynamically via PHP API

I have setup Supervisor , which I use to manage my workflows. Now I want to dynamically change processes (stop some processes and start new ones) using the PHP API.

I found this library that seems useful for what I'm trying. In particular, I use this to change the configuration and this to control the supervisor.

I set this library up and have the following code sample that seems to work well (from here and here )

<?php    

require './vendor/autoload.php';
use Supervisor\Supervisor;
use Supervisor\Connector\XmlRpc;
use fXmlRpc\Client;
use fXmlRpc\Transport\HttpAdapterTransport;
use Ivory\HttpAdapter\Guzzle5HttpAdapter;

use Supervisor\Configuration\Configuration;
use Supervisor\Configuration\Section\Supervisord;
use Supervisor\Configuration\Section\Program;
use Indigo\Ini\Renderer;


//Create GuzzleHttp client
$guzzleClient = new \GuzzleHttp\Client(['auth' => ['user', '123']]);

// Pass the url and the guzzle client to the XmlRpc Client
$client = new Client(
    'http://127.0.0.1:9001/RPC2',
    new HttpAdapterTransport(new Guzzle5HttpAdapter($guzzleClient))
);

// Pass the client to the connector
// See the full list of connectors bellow
$connector = new XmlRpc($client);

$supervisor = new Supervisor($connector);

$processes = $supervisor->getAllProcesses();

foreach ($processes as $key => $processInfo) {
    echo $processInfo . "\r\n";
}

try{
$supervisor->stopProcess('video_convert_02');
}
catch(Exception $e){
    echo "\r\n Exception-> " . $e->getMessage();
}


$config = new Configuration;
$renderer = new Renderer;

$section = new Supervisord(['identifier' => 'supervisor']);
$config->addSection($section);

$section = new Program('test', ['command' => 'cat']);
$config->addSection($section);

echo "\r\n Config \r\n" . $renderer->render($config->toArray());

//Not sure how to use this config information to launch supervisor processes.

?>

The output to this is as follows:

pdf_convert_00
pdf_convert_01
video_convert_00
video_convert_01
video_convert_02
video_convert_03

 Exception-> BAD_NAME: video_convert_02
 Config
[supervisord]
identifier = supervisor

[program:test]
command = cat

I have two questions:

  • , ,
  • ?
+4
1

, "BAD_NAME" , .

Btw, API Supervisor, SupervisorXMLRPC. .

$supervisor = new \Supervisor\Api('127.0.0.1', 9001, 'user', '123');

$processes = $supervisor->getAllProcessInfo();
foreach ($processes as $processInfo) {
    print_r($processInfo);
}

try {
    $supervisor->stopProcess('video_convert_02');
}
catch (\Supervisor\ApiException $e){
    echo "\r\n Exception-> " . $e->getMessage();
}
+1

Source: https://habr.com/ru/post/1623620/


All Articles