Daemonizing any command with SUPERVISOR

Demonizing a command means to make it run as a background process.

so when we have a command that we want to daemonize there are many ways to do it, most common methods are:

  1. using upstart
  2. adding it to /etc/rc.local
  3. creating a script in /etc/init.d and adding them to runlevel folders manually (i.e. incase you want to start, stop a command)

Most easiest seems to be using supervisor

Installing Supervisor and sample configuration file:

installing it in ubuntu or any Debian based system is as simple as

sudo apt-get install supervisor

now you can create your configurations in /etc/supervisor/conf.d/ folder with extension ".conf"

a simple configuration file at /etc/supervisor/conf.d/test-program.conf will look as

[program:]

command = 

stdout_logfile = 

stderr_logfile = 

logfile_maxbytes = 50MB      ; optional 

logfile_backups = 10         ; needed if you want to rotate log files

user = root                  ; user as which the script should be executed

environment=variable1='value',variable2='value'    ; environment variale to pass if any

Daemonizig the command:

supervisorctl reread
supervisorctl update

The first command re-reads the configuration files and detects any changes

The second command updates the supervisor process with the new or changed configurations.

Now you have daemonized the command as background process

Other useful commands: 

Stopping a process:

sudo supervisorctl stop 

sudo supervisorctl stop all 

starting a process

sudo supervisorctl stop 

restarting a process

sudo supervisorctl restart 

sudo supervisorctl restart all

Posted On 12 September 2012 By MicroPyramid


Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
How to deploy django with uwsgi and nginx using Ansible play book.

Ansible is a scripting language mostly used to automate installing applications, deploying apps etc..
Why Ansible:
You may think why learn new language if I ...

Continue Reading...
php7 hosting on Ubuntu Server with Nginx(LEMP stack)

PHP7 is the latest version with lot of performance improvements and every one want to update their servers and code to it. Lets see how ...

Continue Reading...
HTTP2 and SPDY Protocols - Make HTTP Faster and Safer

HTTP/2, next version of HTTP/1, http/1 can not handle the present web which has become more resource intensive, it cannot processes multiple requests in an ...

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties