Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Last active August 24, 2017 10:54
Show Gist options
  • Save dineshsprabu/0527c1db6588cf4abd77aac0d3619165 to your computer and use it in GitHub Desktop.
Save dineshsprabu/0527c1db6588cf4abd77aac0d3619165 to your computer and use it in GitHub Desktop.
[Linux][Supervisor] How to use supervisor to run a program as daemon?

How to use supervisor to run a program as daemon?

Install the supervisor package

sudo apt-get install supervisor

Create a config file for your daemon at /etc/supervisor/conf.d/flashpolicyd.conf

[program:flashpolicyd]
directory=/path/to/project/root
environment=ENV_VARIABLE=example,OTHER_ENV_VARIABLE=example2
command=python flashpolicyd.py
autostart=true
autorestart=true

Another example configuration

[unix_http_server]
file=./tmp/sock/supervisor.sock                       ; path to your socket file

[supervisord]
logfile=./tmp/logs/supervisord.log    ; supervisord log file
logfile_maxbytes=50MB                           ; maximum size of logfile before rotation
logfile_backups=10                              ; number of backed up logfiles
loglevel=error                                  ; info, debug, warn, trace
pidfile=./tmp/pid/supervisord.pid                ; pidfile location
nodaemon=true                                  ; run supervisord as a daemon
minfds=1024                                     ; number of startup file descriptors
minprocs=200                                    ; number of process descriptors
user=root                                       ; default user
childlogdir=./tmp/logs/               ; where child log files will live

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix://./tmp/sock/supervisor.sock         ; use a unix:// URL  for a unix socket

[inet_http_server]
port = 127.0.0.1:9001

[program:tao-app]
command=python app.py --port=8000 --server_path=ec2-54-87-125-46.compute-1.amazonaws.com
stderr_logfile = ./tmp/logs/tornado-stderr.log
stdout_logfile = ./tmp/logs/tornado-stdout.log

Restart supervisor to load your new .conf

supervisorctl update
supervisorctl restart flashpolicyd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment