forked from josexie/supervisord
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.php
More file actions
78 lines (57 loc) · 2.03 KB
/
Copy pathexample.php
File metadata and controls
78 lines (57 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Supervisord;
use \Supervisord\Connection\Stream;
use \Supervisord\Connection\StreamConnection;
use \Supervisord\Connection\StreamException;
require_once sprintf( '%s/vendor/autoload.php', __DIR__ );
// Connect to server
try {
$stream = new Stream( '127.0.0.1:9900' );
$connection = new StreamConnection( $stream );
}
// Connection Error
catch( StreamException $e ) {
die( "Can't connect to server at 127.0.0.1:9900\n" );
}
try
{
// Create client
$client = new Client( $connection );
// Output header
printf( "Supervisord v%s\n\n", $client->getAPIVersion() );
// Output process info
printf( "Processes:\n%s\n", print_r( $client->getAllProcessInfo(), true ) );
// Add a group
$client->addGroup( 'log', 999 );
// Create a new process
$client->addProgramToGroup( 'log', 'syslog01', array(
'command' => 'tail -f /var/log/syslog',
'autostart' => 'false',
'autorestart' => 'true',
'startsecs' => 1,
));
// Start the process
$client->startProcess( 'log:syslog01', 'false' );
// Start the whole group
$client->startProcessGroup( 'log', 'false' );
// Output single process info
printf( "Single Process:\n%s\n", print_r( $client->getProcessInfo( 'log:syslog01' ), true ) );
// Output process stdout
printf( "StdOut:\n%s\n", print_r( $client->tailProcessStdoutLog( 'log:syslog01', 0, 1024 ), true ) );
// Output process stderr
printf( "StdErr:\n%s\n", print_r( $client->tailProcessStderrLog( 'log:syslog01', 0, 1024 ), true ) );
// Send process stdin
$client->sendProcessStdin( 'log:syslog01', 'hello world!' );
// Stop the process
$client->stopProcess( 'log:syslog01', 'false' );
// Stop the whole group
$client->stopProcessGroup( 'log', 'false' );
// Add a group
$client->removeProcessGroup( 'log' );
// Reset server
$client->reloadConfig();
}
catch( \Exception $e )
{
printf( "Error %s: %s\n", $e->getCode(), $e->getMessage() );
}