122

I'm running a few processes using supervisord, named process1, process2, ..., process8. If I want to restart process{1-4}, how can I do that with supervisorctl?

Thi Duong Nguyen
  • 1,745
  • 2
  • 12
  • 18

2 Answers2

211

supervisord supports process groups. You can group processes into named groups and manage them collectively.

[unix_http_server]
file=%(here)s/supervisor.sock

[supervisord]
logfile=supervisord.log
pidfile=supervisord.pid

[program:cat1]
command=cat

[program:cat2]
command=cat

[program:cat3]
command=cat

[group:foo]
programs=cat1,cat3

[supervisorctl]
serverurl=unix://%(here)s/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

supervisorctl command can be called with a group name:

supervisorctl restart foo:

as well as with multiple process names:

supervisorctl restart foo:cat1 cat2
mher
  • 10,508
  • 2
  • 35
  • 27
  • 57
    It's amazing how non-trivial it was to find out that a colon needs to be appended when issuing commands to a process group. Thank you. – mafrosis Aug 17 '13 at 07:47
  • 6
    Agreed. I think `supervisorctl restart foo:*` makes what's happening clearer. – Tom Jul 13 '16 at 14:29
  • So to directly answer the OP's question, you can't directly restart a specific process. You can only restart groups, which requires a group tag? – Cerin Dec 04 '16 at 23:37
  • @Cerin From my own testing, I came that exact same conclusion. Speaking anecdotally, I have tended to see a group at the end of .conf files containing all processes. As a repeated observation, this made no sense. Now it makes complete sense :) – AlanSE Feb 14 '17 at 14:46
  • You made my day :) – sumit Aug 14 '17 at 05:17
  • @mafrosis I did it in two steps: 1. enter `supervisorctl`, 2. `restart foo` It looks like no colons are needed this way – gdvalderrama Oct 31 '17 at 10:25
  • @guival, that doesn't work. Running supervisorctl on it's own opens up supervisor's own command line, and then running restart foo while omitting the colon yields the same error that would come out of running it as a single line command. @ mher, thanks for that! – thephpdev Apr 04 '18 at 09:24
13

Since supervisorctl accepts multiple processes on the command line, you can take advantage of shell brace expansion (e.g. in Bash) to control multiple processes:

supervisorctl restart process{1..4}

is expanded by the shell into

supervisorctl restart process1 process2 process3 process4

as if you had typed that out explicitly.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439