2

I'm trying to stop about 20 services running on a remote server managed by Supervisord in one XMLRPC call.

However, I want to exclude certain processes from it, it would be great if I could do something along the lines of:

stopAllProcesses(exclude=["monitorapp","nagios"])

Alternatively, I do have a list of all the processes available to me so even doing something like the below is better than actually stopping ALL services or doing 20 individual calls:

stopProcess(["process1","process2","process3"])

which is much better than doing:

stopProcess("process1")
stopProcess("process2")
stopProcess("process3")

Any help would be greatly appreciated!

Thanks

user1741694
  • 237
  • 4
  • 13

2 Answers2

1

The XML-RPC server in supervisord supports the system.multicall() endpoint. Use that to send a group of stopProcess calls, using the MultiCall XML-RPC proxy:

multicall = xmlrpclib.MultiCall(serverproxy)
for proc in procs:
    if proc in exclude:
        continue
    multicall.supervisor.stopProcess(proc)
res = multicall()

where serverproxy is your XML-RPC proxy to the supervisord server. The calls will be sent as one HTTP request and processed on the server in series, being no faster or slower than stopAllProcesses(); the latter internally calls stopProcess for each process found anyway.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks for the response - definitely getting there, I'm getting a {'results': [{'faultCode': 1, 'faultString': ":'stopProcess'"}]} - doesn't seem to like the 'stopProcess' bit – user1741694 Dec 21 '12 at 10:37
  • @user1741694: Does simply calling `stopProcess()` through XML-RPC work at all for you? – Martijn Pieters Dec 21 '12 at 10:51
  • @user1741694: ah, I suspect the namespace needs to be included; `multicall.supervisor.stopProcess(proc)` should do it. – Martijn Pieters Dec 21 '12 at 10:55
0

you have a list of all process names:

procs = ['monitorapp', 'nagios', 'process1', 'process2', 'process3']

and a list of process names to exclude:

exclude = ['monitorapp', 'nagios']

you can call them, one at a time...

this will make a call to 'stopProcess()' for each process that is not in the exclude list:

stop_procs = [p for p in procs if p not in exclude]
for proc in stop_procs:
    stopProcess(proc)

better would be to refactor the API (if possible) to handle a list of processes in one call with include/exclude.

Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
  • This is what I was trying to get away from as I could potentially have 100 processes and therefore would need to make 100 calls - not ideal. I found a method called multicall(calls) - but I'm still trying to figure out how to use it... – user1741694 Dec 20 '12 at 18:19