How to Control an Entire Supervisor Process Group: Start/Stop/Restart All Programs at Once


1 views

When working with Supervisor's process groups, you might encounter situations where individual program control works while group-level commands fail. Here's what's happening:

$ supervisorctl start myappgroup
myappgroup ERROR (no such process)

However, targeting specific programs within the group works:

$ supervisorctl start myappgroup:program1
myappgroup:program1: started

Supervisor treats process groups differently from individual programs. The group name isn't directly controllable because it's a logical container rather than an executable process.

Here are three practical solutions to control entire groups:

1. Using Wildcard Pattern Matching

Supervisor allows wildcards in control commands:

$ supervisorctl start myappgroup:*
$ supervisorctl stop myappgroup:*
$ supervisorctl restart myappgroup:*

2. Creating Custom Supervisor Events

For more advanced control, configure event listeners in supervisor.conf:

[eventlistener:groupcontrol]
command=/usr/local/bin/group_handler.py
events=PROCESS_STATE

Then create a handler script (group_handler.py):

#!/usr/bin/env python
from supervisor import childutils

def main():
    while True:
        headers, payload = childutils.listener.wait()
        if headers['eventname'] == 'PROCESS_STATE_STOPPED':
            # Add your group control logic here
            pass

if __name__ == '__main__':
    main()

3. Supervisor's Process Group API

For programmatic control, use Supervisor's XML-RPC API:

import supervisor.xmlrpc

def control_group(action, group_name):
    transport = supervisor.xmlrpc.SupervisorTransport(
        None, None, 'unix:///tmp/supervisor.sock'
    )
    proxy = supervisor.xmlrpc.SupervisorProxy(transport)
    
    if action == 'start':
        return proxy.startProcessGroup(group_name)
    elif action == 'stop':
        return proxy.stopProcessGroup(group_name)
  • The wildcard approach works for all Supervisor versions
  • XML-RPC requires proper permissions in supervisor.conf
  • Event listeners add overhead but enable complex automation
  • Always test group operations in a staging environment first

When working with Supervisor's process groups, many developers encounter a frustrating limitation - the inability to control an entire group of processes with a single command. While individual processes can be managed using the groupname:processname syntax, attempting to control the whole group often results in:

$ supervisorctl stop myappgroup
myappgroup ERROR (no such process)

Supervisor's process groups are designed as organizational containers rather than operational units. The system expects explicit targeting of either:

supervisorctl start group:process  # Control single process
supervisorctl start process       # Control process not in group

To manage all processes in a group simultaneously, use the wildcard (*) pattern:

# Start all processes in group
supervisorctl start myappgroup:*

# Stop all processes in group  
supervisorctl stop myappgroup:*

# Restart entire group
supervisorctl restart myappgroup:*

Consider this Supervisor configuration where we have a web application group:

[group:webapp]
programs=nginx,uwsgi,celery

[program:nginx]
command=/usr/sbin/nginx

[program:uwsgi] 
command=/usr/local/bin/uwsgi --ini /etc/uwsgi.ini

[program:celery]
command=/usr/local/bin/celery -A tasks worker

Instead of managing each process separately, use:

# Full group management
supervisorctl stop webapp:*
supervisorctl start webapp:*
supervisorctl restart webapp:*

For more complex scenarios, you can combine group control with other supervisorctl features:

# Check status of all group members
supervisorctl status webapp:*

# Tail logs for entire group
supervisorctl tail -f webapp:*

# Signal entire group
supervisorctl signal TERM webapp:*

Remember that wildcard operations are processed in alphabetical order by process name. For ordered startups/shutdowns, you'll need to implement proper dependencies in your program configurations.