Je voulais faire fonctionner le processus sur le superviseur à partir d'un programme Python, j'ai donc essayé l'interface XMLRPC.
Activez ʻ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
Ce n'est pas important, mais juste au cas où. Paramètres côté programme. Puisqu'il est exploité par virtualenv, ajoutez le paramètre ʻenvironment`. Le programme lui-même appelle simplement le module standard serveur HTTP simple.
[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)
L'introduction est écrite à http://supervisord.org/api.html, vous devriez donc y regarder.
Ce qui suit est exploité à partir d'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
Vérifiez l'état du processus pour voir s'il s'est correctement arrêté.
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}
Il s'est arrêté parce qu'il était "STOPPED".
In [13]: server.supervisor.startProcess('simplehttp') Out[13]: True
J'ai pu reprendre.
Recommended Posts