Supervisor in Cloud Containers

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

Unlike system-wide daemons like systemd, Supervisor is not designed to control the system from the ground up, but instead it's supposed to handle 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. All of these features make Supervisor perfect for isolated systems like Cloud Containers.

If you want to know more about Supervisor, check out their documentation.

Modifying supervisor.conf

The implementation of Supervisor in Cloud Containers is configured to read /container/config/supervisor.conf, which is an ini-style configuration file. You can configure multiple processes, if you need to, using separate [program] blocks. An example block, in this case taken from the default configuration of the Python + Conda image, might look something like this:

command=/bin/bash -c "source activate pyapp && python -m app"

Some of these options are necessary for an application to run in a Cloud Container. Your user should be www-data; and your directory should be the root or a subdirectory of /container/application/, depending on where you've placed your application files. You'll also need to set a command, to tell Supervisor what to do to run your application. The rest of the options are optional, though more often than not you'll want to set up logging and autostart/autorestart.

Once you've made changes, you will need to apply them with a container restart (or, if your container image supports supervisorctl, see using supervisorctl below).

If you're unfamiliar with Supervisor, you may want to read further about program configuration over at the Supervisor docs.

Using Supervisorctl

The Cloud Container supervisorctl integration is only currently available for the Python + Conda container image. For now, if you're using a different image, you'll need to restart your Cloud Container for any supervisor changes to take effect.

Supervisor Control - commanded with supervisorctl - is a command you can use to directly control Supervisor and any subprocesses spawned by it. Essentially, it's a shortcut so that you don't need to restart 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

Anytime you make changes to supervisor.conf you'll need to run supervisorctl reload to apply those changes. If you just make changes to your application files, or for any other reason need to stop/restart/start the application, you can use the relevant stop/start/restart command for that process.