name: Deployment with Supervisord

sort: 2

Supervisord

Supervisord is a very useful process manager implemented in Python. Supervisord can change your non-daemon application into a daemon application. The application needs to be a non-daemon app. So if you want to use Supervisord to manage nginx, you need to set daemon off to run nginx in non-daemon mode.

Install Supervisord

  1. install setuptools

    1. wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
    2. sh setuptools-0.6c11-py2.7.egg
    3. easy_install supervisor
    4. echo_supervisord_conf >/etc/supervisord.conf
    5. mkdir /etc/supervisord.conf.d
  2. config /etc/supervisord.conf

    1. [include]
    2. files = /etc/supervisord.conf.d/*.conf
  3. Create new application to be managed

    1. cd /etc/supervisord.conf.d
    2. vim beepkg.conf

    Configurations:

    1. [program:beepkg]
    2. directory = /opt/app/beepkg
    3. command = /opt/app/beepkg/beepkg
    4. autostart = true
    5. startsecs = 5
    6. user = root
    7. redirect_stderr = true
    8. stdout_logfile = /var/log/supervisord/beepkg.log

Supervisord Manage

Supervisord provides two commands, supervisord and supervisorctl:

  • supervisord: Initialize Supervisord, run configed processes
  • supervisorctl stop programxxx: Stop process programxxx. programxxx is configed name in [program:beepkg]. Here is beepkg.
  • supervisorctl start programxxx: Run the process.
  • supervisorctl restart programxxx: Restart the process.
  • supervisorctl stop groupworker: Restart all processes in group groupworker
  • supervisorctl stop all: Stop all processes. Notes: start, restart and stop won’t reload the latest configs.
  • supervisorctl reload: Reload the latest configs.
  • supervisorctl update: Reload all the processes who’s config has changed.

Notes: The processes stopped by stop manually won’t restart after reload or update.