I wanted to operate the process on Supervisor from a Python program, so I tried the XMLRPC interface.
Enable ʻinet_http_server`.
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
[include]
files = conf.d/*.ini
This is not important, but just in case. Settings on the program side. Since it is operated by virtualenv, add the setting of ʻenvironment`. The program itself just calls the standard module simple HTTP server.
[program:simplehttp]
command=python -m SimpleHTTPServer ; the program (relative uses PATH, can take args)
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
directory=/tmp ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=unexpected ; whether/when to restart (default: unexpected)
stdout_logfile=/tmp/simplehttp.stdout ; stdout log path, NONE for none; default AUTO
stderr_logfile=/tmp/simplehttp.stderr ; stderr log path, NONE for none; default AUTO
environment=PATH=/Users/shrkw/.virtualenv/cpython-275/bin ; process environment additions (def no adds)
The introduction is written at http://supervisord.org/api.html, so you should look there.
The following is operated from IPython.
In [1]: import xmlrpclib In [2]: server = xmlrpclib.ServerProxy('http://localhost:9001')
In [6]: server.system.listMethods() Out[6]: ['supervisor.addProcessGroup', 'supervisor.clearAllProcessLogs', 'supervisor.clearLog', 'supervisor.clearProcessLog', 'supervisor.clearProcessLogs', 'supervisor.getAPIVersion', 'supervisor.getAllConfigInfo', 'supervisor.getAllProcessInfo', 'supervisor.getIdentification', 'supervisor.getPID', 'supervisor.getProcessInfo', 'supervisor.getState', 'supervisor.getSupervisorVersion', 'supervisor.getVersion', 'supervisor.readLog', 'supervisor.readMainLog', 'supervisor.readProcessLog', 'supervisor.readProcessStderrLog', 'supervisor.readProcessStdoutLog', 'supervisor.reloadConfig', 'supervisor.removeProcessGroup', 'supervisor.restart', 'supervisor.sendProcessStdin', 'supervisor.sendRemoteCommEvent', 'supervisor.shutdown', 'supervisor.startAllProcesses', 'supervisor.startProcess', 'supervisor.startProcessGroup', 'supervisor.stopAllProcesses', 'supervisor.stopProcess', 'supervisor.stopProcessGroup', 'supervisor.tailProcessLog', 'supervisor.tailProcessStderrLog', 'supervisor.tailProcessStdoutLog', 'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall']
In [7]: server.supervisor.getAllProcessInfo() Out[7]: [{'description': 'pid 6624, uptime 0:09:45', 'exitstatus': 0, 'group': 'simplehttp', 'logfile': '/tmp/simplehttp.stdout', 'name': 'simplehttp', 'now': 1412565184, 'pid': 6624, 'spawnerr': '', 'start': 1412564599, 'state': 20, 'statename': 'RUNNING', 'stderr_logfile': '/tmp/simplehttp.stderr', 'stdout_logfile': '/tmp/simplehttp.stdout', 'stop': 0}]
In [10]: server.supervisor.getProcessInfo('simplehttp') Out[10]: {'description': 'pid 6624, uptime 0:10:51', 'exitstatus': 0, 'group': 'simplehttp', 'logfile': '/tmp/simplehttp.stdout', 'name': 'simplehttp', 'now': 1412565250, 'pid': 6624, 'spawnerr': '', 'start': 1412564599, 'state': 20, 'statename': 'RUNNING', 'stderr_logfile': '/tmp/simplehttp.stderr', 'stdout_logfile': '/tmp/simplehttp.stdout', 'stop': 0}
In [11]: server.supervisor.stopProcess('simplehttp') Out[11]: True
Check the status of the process to see if it has stopped properly.
In [12]: server.supervisor.getProcessInfo('simplehttp') Out[12]: {'description': 'Oct 05 11:15 PM', 'exitstatus': -1, 'group': 'simplehttp', 'logfile': '/tmp/simplehttp.stdout', 'name': 'simplehttp', 'now': 1412565327, 'pid': 0, 'spawnerr': '', 'start': 1412564599, 'state': 0, 'statename': 'STOPPED', 'stderr_logfile': '/tmp/simplehttp.stderr', 'stdout_logfile': '/tmp/simplehttp.stdout', 'stop': 1412565323}
It stopped because it was STOPPED
.
In [13]: server.supervisor.startProcess('simplehttp') Out[13]: True
I was able to resume.
Recommended Posts