Skip to content

Instantly share code, notes, and snippets.

@Martin91
Created June 12, 2019 07:07
Show Gist options
  • Save Martin91/c6488fc418c87113263b783f529c197c to your computer and use it in GitHub Desktop.
Save Martin91/c6488fc418c87113263b783f529c197c to your computer and use it in GitHub Desktop.
supervisord XML/RPC API demo
==================== Supported Methods ======================
['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.signalAllProcesses', 'supervisor.signalProcess', 'supervisor.signalProcessGroup', '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']
==================== Process Information =====================
{'now': 1560322893, 'group': 'say_hello', 'description': 'pid 56561, uptime 0:17:10', 'pid': 56561, 'stderr_logfile': '', 'stop': 0, 'statename': 'RUNNING', 'start': 1560321863, 'state': 20, 'stdout_logfile': '/somewhere/supervisor/log/daemon.log', 'logfile': '/somewhere/supervisor/log/daemon.log', 'exitstatus': 0, 'spawnerr': '', 'name': 'say_hello'}
import time
while True:
print("Hello")
time.sleep(3)
[unix_http_server]
file=/somewhere/supervisor/supervisor.api.sock
[inet_http_server]
port=9123
[supervisord]
logfile=/somewhere/supervisor/log/daemon.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/somewhere/supervisor/supervisor.api.pid
nodaemon=false
minfds=1024
minprocs=200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///somewhere/supervisor/supervisor.api.sock
[program:say_hello]
command=python say_hello.py
directory=/somewhere/supervisor/
user=martin91
autorestart=false
redirect_stderr=true
stdout_logfile=/somewhere/supervisor/log/daemon.log
loglevel=info
# reference to http://supervisord.org/api.html
import xmlrpclib
# port 9123 conform to the configurated port in [inet_http_server] section
server = xmlrpclib.Server("http://127.0.0.1:9123/RPC2") # a http port is required
methods = server.system.listMethods()
print "==================== Supported Methods ======================"
print methods
print "==================== Process Information ====================="
print server.supervisor.getProcessInfo('say_hello')
supervisord -c supervisor.ini
python supervisor_api_consumer.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment