What is Supervisor

  • It is a Process Control System which allows you to monitor and control a number of processes.

What it can do

  • It can be configured to automatically restart processes on a crash.
    (operating system signals Supervisor immediately when a process terminates)
  • It can start processes on its own invocation.
  • Processes can be grouped into “process groups” and a set of logically related processes can be stopped and started as a unit.
  • It allows to assign priorities to processes and allows the user to start/restart all processes via the supervisorctl client which starts them in the preassigned priority order.
  • It also provides password protected web user-interface through which all the processes managed by the supervisor can be stopped/started/restarted when needed.
    (Example: you have node server or node web-socket running on the server and it got stopped due to some reason then client having access to web user-interface can start/restart the failed processes without disturbing the developer at midnight)

Platform Requirements

  • It will likely work fine on most UNIX systems.
  • It will not run at all under any version of Windows. the window has its own way for controlling a process like from services a process can be configured to restart automatically after it failed for around 3 times.
  • The supervisor is known to work with Python 2.4 or later but will not work under any version of Python 3.

Installation

  • sudo apt-get install supervisor
  • After installation, the path for supervisor configuration file will be either “/etc/supervisor/supervisord.conf” or “/etc/supervisord.conf” (Normally the default file is indeed /etc/supervisor.conf, but the Debian distribution patches this to look for /etc/supervisor/supervisor.conf first)
  • Refer below link for manual configuration of the file path:
    http://supervisord.org/installing.html#creating-a-configuration-file

Supervisor Components

  1. supervisord

    • It is responsible for starting child programs at its own invocation, responding to commands from clients, restarting crashed or exited sub-processes.
    • The server process uses a configuration file.
    • This is typically located in /etc/supervisord.conf.
    • This configuration file is a “Windows-INI” style config file and it’s important to keep this file secure via proper file system permissions because it may contain unencrypted usernames and passwords.
  2. supervisorctl

    • It’s a command-line client which provides a shell-like interface.
    • From this, a user can connect to different supervisord processes, get status on the sub-processes controlled by, stop and start sub-processes of, and get lists of running processes of a supervisord.
  3. Web Server

    • Its a web user interface with functionality comparable to supervisorctl may be accessed via a browser if you start supervisord against an internet socket.
  4. XML-RPC Interface

    • The same HTTP server which serves the web UI serves up an XML-RPC interface that can be used to interrogate and control supervisor and the programs it runs.

Set up Programs 

  • Add a program in supervisord.conf file in below format to run as process and to be controlled by supervisor.
  • Below command is to start the program.

Set up Group

  • Add a Group in supervisord.conf file in below format to run processes as a group and to be controlled as a group by supervisor
  • Below command is to start the programs in a group.

Set up web user-interface

  • Add below configuration at the end of supervisord.conf file or edit “[inet_http_server’] section if it already present there.
  • Restart supervisor using below command from command line/terminal.
  • Access http://localhost:9001/ in a browser to view and control process status through the web interface and control it.

Command list (Use “sudo” before each command to run as root)

  • To start, restart and stop supervisor:
  • To list all programs of supervisor with status:
  • To start, restart and stop all programs of supervisor:
  • To start, restart and stop specific programs of supervisor:
  • To start, restart and stop all programs defined in a group:

Hope this helps you to let your programs get controlled and monitored automatically.