Skip to content

Supervisor and Python Containers

Supervisor is a process control and monitoring system, designed to be lightweight and easy to use.

Unlike system-wide daemons like systemd, Supervisor is not designed to control the system from the ground up. Instead it handles a subset of processes, all of which are spawned as subprocesses of the Supervisor daemon. This allows Supervisor to constantly monitor the processes it manages. These features make Supervisor perfect for isolated systems like Webslice Containers.

For much, much more about this system, see Supervisor documentation.

Configuring Supervisor

In Webslice Containers, Supervisor is configured to read /container/config/supervisord.conf, which is an ini-style configuration file.

You can configure multiple processes using separate [program] blocks. An example block, in this case taken from the default configuration of the Python + Miniconda image, might look something like this:

[program:pyapp]
user=www-data
directory=/container/application/
autostart=true
autorestart=true
command=/bin/bash -c "source activate pyapp && python -m app"
stdout_logfile=/container/logs/supervisor/%(program_name)s-stdout.log
stderr_logfile=/container/logs/supervisor/%(program_name)s-stderr.log

Some of these options are necessary for Webslice Containers:

  • Your user should be www-data.
  • Your directory should be the root or a subdirectory of /container/application/, depending on where you’ve placed your application files.
  • You need to set a command to tell Supervisor what to do to run your application.

The rest is optional, but you will usually want to set up logging and autostart/autorestart.

To apply your configuration changes, restart the container or use Supervisor Control.

Using Supervisor Control

Supervisor Control is commanded with supervisorctl You can use to directly control Supervisor and any subprocesses spawned by it. Essentially, this is a shortcut around restarting your container every time you make a change. There are only a few commands you’ll usually need to use:

  • supervisorctl reload - Reloads the Supervisor configurations and restarts all supervisor processes based on any changes.
  • supervisorctl restart <program> - Restarts the specified process.
  • supervisorctl stop <program> - Stops the specified process.
  • supervisorctl start <program> - Starts the specified process.

So, for example, when you make changes to supervisord.conf, just run supervisorctl reload to apply them.