LinuxCommandLibrary

start-stop-daemon

Start, stop, and manage daemon processes

SYNOPSIS

start-stop-daemon [options] [--] [arguments]

Common Modes:
start-stop-daemon --start [options] [--] executable [arguments]
start-stop-daemon --stop [options]
start-stop-daemon --status [options]

PARAMETERS

--start
    Checks if a process exists and starts it if it doesn't. Requires a process identifier and the executable path.

--stop
    Checks if a process exists and stops it. Requires a process identifier.

--status
    Checks if a process exists and returns its status. Returns 0 if found, 1 if not found.

--test
    Activates test mode; no actions are performed, only what would be done is printed.

--pidfile <file>
    Identifies the process by its PID, which is read from the specified file.

--exec <executable>
    Identifies the process by its absolute executable path. Required with --start.

--name <process-name>
    Identifies the process by its process name (e.g., 'apache2'). Less reliable than --pidfile or --exec.

--user <user>
    Runs the process as the specified user, or identifies processes owned by this user.

--group <group>
    Runs the process as the specified group, or identifies processes owned by this group.

--background
    Detaches the process from the controlling terminal and runs it in the background (daemonizes).

--make-pidfile
    Used with --start, creates the PID file after the process has successfully started.

--remove-pidfile
    Used with --stop, removes the PID file after the process has successfully stopped.

--signal <signal>
    Specifies the signal to send to the process when stopping (default is SIGTERM).

--retry <schedule>
    Specifies a retry schedule for stopping a process (e.g., TERM/30/KILL/5).

--chroot <directory>
    Changes the root directory to the specified path before executing the process.

--chdir <directory>
    Changes the current working directory before executing the process.

--nicelevel <level>
    Sets the process's niceness level (priority).

--quiet
    Suppresses most output messages.

--oknodo
    Returns an exit status of 0 even if no process was found or no action was taken.

DESCRIPTION

start-stop-daemon is a utility designed to control the starting and stopping of system-level daemon processes. Primarily used within init.d scripts on Debian-based Linux distributions, it ensures that daemons are started correctly, run under appropriate user/group permissions, are properly backgrounded, and can be reliably stopped. It identifies processes by their PID file, executable path, or process name. Its robust features help prevent multiple instances of a daemon, ensure clean shutdowns, and handle process isolation through options like changing root directory or current working directory. It is a cornerstone for traditional service management on systems predating systemd.

CAVEATS

start-stop-daemon is primarily designed for and used in Debian-based distributions and their init.d scripts. While powerful for its intended use, it has limitations:

  • Its reliance on PID files requires careful management within scripts to ensure correctness.
  • Identifying processes solely by --name can be unreliable if multiple processes share the same name or if the process name is truncated by the kernel.
  • On modern Linux systems, systemd has largely superseded traditional init.d scripts, and thus start-stop-daemon's direct usage by administrators is less common, though it remains crucial for older service management.

PROCESS IDENTIFICATION METHODS

start-stop-daemon offers multiple ways to identify a target process: via a --pidfile (the most reliable), by the full path to the --executable, or by its --name. For stopping or status checks, at least one identification method is required. For starting, --exec is mandatory to specify the program to run, and usually combined with --pidfile or --name for subsequent identification.

DAEMONIZATION AND PROCESS CONTROL

When starting a process with --background, start-stop-daemon performs standard daemonization steps: forking twice, redirecting standard I/O to /dev/null, and detaching from the controlling terminal. It also provides options to drop privileges (--user, --group), change the process's root (--chroot) or working directory (--chdir), and set niceness (--nicelevel) or I/O scheduling (--iosched), offering fine-grained control over the daemon's environment.

HISTORY

start-stop-daemon is part of the dpkg package, developed as a utility for managing daemons in Debian's traditional System V-style init.d scripts. It was created to provide a robust and standardized way for init scripts to start, stop, and check the status of services, addressing common issues like orphaned processes or incorrect daemonization. Its development predates the widespread adoption of modern init systems like Upstart and systemd, serving as a cornerstone for process management in its era on Debian-derived systems.

SEE ALSO

systemctl(1), service(8), kill(1), killall(1), nohup(1), daemon(3)

Copied to clipboard