Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is start-stop-daemon in linux scripting?

What is start-stop-daemon and how should it be used?

I am trying to automate a particular program to run. Whenever the system starts, the program should run. For that I am writing script in /etc/init.d/ location.

like image 729
Rajeev Das Avatar asked Apr 22 '13 05:04

Rajeev Das


People also ask

What is daemon in Linux?

In Unix and Linux, a daemon is a program that runs in the background without requiring any user interaction. The file name of a software daemon usually ends in the letter d.

How do you stop a daemon in Linux?

Issue the kill -15 command with the process identifier number to stop the daemons. For AIX® and Linux x86_64 GPFS™ file systems, issue the command dmkilld to stop the recall daemons. Verify that the daemons are no longer running.

What is daemon used for?

Pronounced "dee-mun" as in the word for devil, as well as "day-mun," a daemon is a Unix/Linux program that executes in the background ready to perform an operation when required. Functioning like an extension to the operating system, a daemon is usually an unattended process that is initiated at startup.


1 Answers

It is a program to manage the start and stop of system level background processes (daemons). You use it by passing in parameters (such as the pid file to create/check) and command arguments for the process you want to launch.

Then, you do one of two things:

start-stop-daemon -S [other arguments] something

start something, if something wasn't already running. If it was running, do nothing.

start-stop-daemon -K [other arguments] something

stop something. If something wasn't running, do nothing.

The man page provides more information on the various arguments. Typically a template is provided in /etc/init.d/ which has other commands for the init process that controls the running of background processes.


What does it mean?

start-stop-daemon --start --background -m --oknodo --pidfile ${PIDFILE} --exec ${DAEMON} -- ${TARGETDIR}

  • --background = launch as a background process
  • -m = make a PID file. This is used when your process doesn't create its own PID file, and is used with --background
  • --oknodo = return 0, not 1 if no actions are taken by the daemon
  • --pidfile ${PIDFILE} = check whether the PID file has been created or not
  • --exec = make sure the processes are instances of this executable (in your case, DAEMON)
like image 190
Burhan Khalid Avatar answered Sep 30 '22 17:09

Burhan Khalid