Daemonizing 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

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

second command updates the supervisor process withe the new or changed configurations.

Noew 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

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties
Latest Comments
Related Articles
Understanding Logstash Parsing Configurations and options Jagadeesh V

In This Tutorial we will learn to customize Logstash to parse any type of Log Files. Logstash helps us to process logs and other event ...

Continue Reading...
ELK Stack for Parsing your Logs- Part 2 Jagadeesh V

In Previous Tutorial we looked into Setting up EL Server which can ingest your Syslog files. In this Post, you will learn about pushing your ...

Continue Reading...
TMUX - Sharing terminal between Users Jagadeesh V

More Often you wouldve come across sharing screens with applications like Teamviewer, Windows Remote Desktop Connection or remmina (if you're a linux user). But if ...

Continue Reading...