summaryrefslogtreecommitdiff
path: root/start-stop-daemon.8
blob: 2a083f34ce03db022ecfd48166a2ec75fa7df022 (plain)
    1 .\" dpkg manual page - start-stop-daemon(8)
    2 .\"
    3 .\" Copyright © 1999 Klee Dienes <klee@mit.edu>
    4 .\" Copyright © 1999 Ben Collins <bcollins@debian.org>
    5 .\" Copyright © 2000-2001 Wichert Akkerman <wakkerma@debian.org>
    6 .\" Copyright © 2002-2003 Adam Heath <doogie@debian.org>
    7 .\" Copyright © 2004 Scott James Remnant <keybuk@debian.org>
    8 .\" Copyright © 2008-2016, 2018 Guillem Jover <guillem@debian.org>
    9 .\"
   10 .\" This is free software; you can redistribute it and/or modify
   11 .\" it under the terms of the GNU General Public License as published by
   12 .\" the Free Software Foundation; either version 2 of the License, or
   13 .\" (at your option) any later version.
   14 .\"
   15 .\" This is distributed in the hope that it will be useful,
   16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
   17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18 .\" GNU General Public License for more details.
   19 .\"
   20 .\" You should have received a copy of the GNU General Public License
   21 .\" along with this program.  If not, see <https://www.gnu.org/licenses/>.
   22 .
   23 .TH start\-stop\-daemon 8 "%RELEASE_DATE%" "%VERSION%" "dpkg suite"
   24 .nh
   25 .SH NAME
   26 start\-stop\-daemon \- start and stop system daemon programs
   27 .
   28 .SH SYNOPSIS
   29 .B start\-stop\-daemon
   30 .RI [ option "...] " command
   31 .
   32 .SH DESCRIPTION
   33 .B start\-stop\-daemon
   34 is used to control the creation and termination of system-level processes.
   35 Using one of the matching options, \fBstart\-stop\-daemon\fP
   36 can be configured to find existing instances of a running process.
   37 .PP
   38 Note: unless
   39 .B \-\-pid
   40 or
   41 .B \-\-pidfile
   42 are specified,
   43 .B start\-stop\-daemon
   44 behaves similar to
   45 .BR killall (1).
   46 .B start\-stop\-daemon
   47 will scan the process table looking for any processes which
   48 match the process name, parent pid, uid, and/or gid (if specified). Any
   49 matching process will prevent
   50 .BR \-\-start
   51 from starting the daemon. All matching processes will be sent the TERM
   52 signal (or the one specified via \fB\-\-signal\fP or \fB\-\-retry\fP) if
   53 .BR \-\-stop
   54 is specified. For daemons which have long-lived children
   55 which need to live through a
   56 .BR \-\-stop ,
   57 you must specify a pidfile.
   58 .
   59 .SH COMMANDS
   60 .TP
   61 .BR \-S ", " \-\-start " [" \-\- "] \fIarguments\fP"
   62 Check for the existence of a specified process.
   63 If such a process exists,
   64 .B start\-stop\-daemon
   65 does nothing, and exits with error status 1 (0 if
   66 .BR \-\-oknodo
   67 is specified).
   68 If such a process does not exist, it starts an
   69 instance, using either the executable specified by
   70 .B \-\-exec
   71 or, if specified, by
   72 .BR \-\-startas .
   73 Any arguments given after
   74 .BR \-\-
   75 on the command line are passed unmodified to the program being
   76 started.
   77 .TP
   78 .BR \-K ", " \-\-stop
   79 Checks for the existence of a specified process.
   80 If such a process exists,
   81 .B start\-stop\-daemon
   82 sends it the signal specified by
   83 .BR \-\-signal ,
   84 and exits with error status 0.
   85 If such a process does not exist,
   86 .B start\-stop\-daemon
   87 exits with error status 1
   88 (0 if
   89 .BR \-\-oknodo
   90 is specified). If
   91 .B \-\-retry
   92 is specified, then
   93 .B start\-stop\-daemon
   94 will check that the process(es) have terminated.
   95 .TP
   96 .BR \-T ", " \-\-status
   97 Check for the existence of a specified process, and returns an exit status
   98 code, according to the LSB Init Script Actions (since version 1.16.1).
   99 .TP
  100 .BR \-H ", " \-\-help
  101 Show usage information and exit.
  102 .TP
  103 .BR \-V ", " \-\-version
  104 Show the program version and exit.
  105 .
  106 .SH OPTIONS
  107 .SS Matching options
  108 .TP
  109 .BR \-\-pid " \fIpid\fP"
  110 Check for a process with the specified \fIpid\fP (since version 1.17.6).
  111 The \fIpid\fP must be a number greater than 0.
  112 .TP
  113 .BR \-\-ppid " \fIppid\fP"
  114 Check for a process with the specified parent pid \fIppid\fP
  115 (since version 1.17.7).
  116 The \fIppid\fP must be a number greater than 0.
  117 .TP
  118 .BR \-p ", " \-\-pidfile " \fIpid-file\fP"
  119 Check whether a process has created the file \fIpid-file\fP.
  120 .IP
  121 Note: using this matching option alone might cause unintended processes to
  122 be acted on, if the old process terminated without being able to remove the
  123 \fIpid-file\fP.
  124 .IP
  125 \fBWarning:\fP using this match option with a world-writable pidfile or using
  126 it alone with a daemon that writes the pidfile as an unprivileged (non-root)
  127 user will be refused with an error (since version 1.19.3) as this is a
  128 security risk, because either any user can write to it, or if the daemon
  129 gets compromised, the contents of the pidfile cannot be trusted, and then
  130 a privileged runner (such as an init script executed as root) would end up
  131 acting on any system process.
  132 Using \fI/dev/null\fP is exempt from these checks.
  133 .TP
  134 .BR \-x ", " \-\-exec " \fIexecutable\fP"
  135 Check for processes that are instances of this \fIexecutable\fP. The
  136 \fIexecutable\fP argument should be an absolute pathname. Note: this might
  137 not work as intended with interpreted scripts, as the executable will point
  138 to the interpreter. Take into account processes running from inside a chroot
  139 will also be matched, so other match restrictions might be needed.
  140 .TP
  141 .BR \-n ", " \-\-name " \fIprocess-name\fP"
  142 Check for processes with the name \fIprocess-name\fP. The \fIprocess-name\fP
  143 is usually the process filename, but it could have been changed by the
  144 process itself. Note: on most systems this information is retrieved from
  145 the process comm name from the kernel, which tends to have a relatively
  146 short length limit (assuming more than 15 characters is non-portable).
  147 .TP
  148 .BR \-u ", " \-\-user " \fIusername\fP|\fIuid\fP
  149 Check for processes owned by the user specified by \fIusername\fP or
  150 \fIuid\fP. Note: using this matching option alone will cause all processes
  151 matching the user to be acted on.
  152 .
  153 .SS Generic options
  154 .TP
  155 .BR \-g ", " \-\-group " \fIgroup\fP|\fIgid\fP"
  156 Change to \fIgroup\fP or \fIgid\fP when starting the process.
  157 .TP
  158 .BR \-s ", " \-\-signal " \fIsignal\fP"
  159 With
  160 .BR \-\-stop ,
  161 specifies the signal to send to processes being stopped (default TERM).
  162 .TP
  163 .BR \-R ", " \-\-retry " \fItimeout\fP|\fIschedule\fP"
  164 With
  165 .BR \-\-stop ,
  166 specifies that
  167 .B start\-stop\-daemon
  168 is to check whether the process(es)
  169 do finish. It will check repeatedly whether any matching processes
  170 are running, until none are. If the processes do not exit it will
  171 then take further action as determined by the schedule.
  172 
  173 If
  174 .I timeout
  175 is specified instead of
  176 .IR schedule ,
  177 then the schedule
  178 .IB signal / timeout /KILL/ timeout
  179 is used, where
  180 .I signal
  181 is the signal specified with
  182 .BR \-\-signal .
  183 
  184 .I schedule
  185 is a list of at least two items separated by slashes
  186 .RB ( / );
  187 each item may be
  188 .BI \- signal-number
  189 or [\fB\-\fP]\fIsignal-name\fP,
  190 which means to send that signal,
  191 or
  192 .IR timeout ,
  193 which means to wait that many seconds for processes to
  194 exit,
  195 or
  196 .BR forever ,
  197 which means to repeat the rest of the schedule forever if
  198 necessary.
  199 
  200 If the end of the schedule is reached and
  201 .BR forever
  202 is not specified, then
  203 .B start\-stop\-daemon
  204 exits with error status 2.
  205 If a schedule is specified, then any signal specified
  206 with
  207 .B \-\-signal
  208 is ignored.
  209 .TP
  210 .BR \-a ", " \-\-startas " \fIpathname\fP"
  211 With
  212 .BR \-\-start ,
  213 start the process specified by
  214 .IR pathname .
  215 If not specified, defaults to the argument given to
  216 .BR \-\-exec .
  217 .TP
  218 .BR \-t ", " \-\-test
  219 Print actions that would be taken and set appropriate return value,
  220 but take no action.
  221 .TP
  222 .BR \-o ", " \-\-oknodo
  223 Return exit status 0 instead of 1 if no actions are (would be) taken.
  224 .TP
  225 .BR \-q ", " \-\-quiet
  226 Do not print informational messages; only display error messages.
  227 .TP
  228 .BR \-c ", " \-\-chuid " \fIusername\fR|\fIuid\fP[\fB:\fP\fIgroup\fR|\fIgid\fP]"
  229 Change to this username/uid before starting the process. You can also
  230 specify a group by appending a
  231 .BR : ,
  232 then the group or gid in the same way
  233 as you would for the \fBchown\fP(1) command (\fIuser\fP\fB:\fP\fIgroup\fP).
  234 If a user is specified without a group, the primary GID for that user is used.
  235 When using this option
  236 you must realize that the primary and supplemental groups are set as well,
  237 even if the
  238 .B \-\-group
  239 option is not specified. The
  240 .B \-\-group
  241 option is only for
  242 groups that the user isn't normally a member of (like adding per process
  243 group membership for generic users like
  244 .BR nobody ).
  245 .TP
  246 .BR \-r ", " \-\-chroot " \fIroot\fP"
  247 Chdir and chroot to
  248 .I root
  249 before starting the process. Please note that the pidfile is also written
  250 after the chroot.
  251 .TP
  252 .BR \-d ", " \-\-chdir " \fIpath\fP"
  253 Chdir to
  254 .I path
  255 before starting the process. This is done after the chroot if the
  256 \fB\-r\fP|\fB\-\-chroot\fP option is set. When not specified,
  257 .B start\-stop\-daemon
  258 will chdir to the root directory before starting the process.
  259 .TP
  260 .BR \-b ", " \-\-background
  261 Typically used with programs that don't detach on their own. This option
  262 will force
  263 .B start\-stop\-daemon
  264 to fork before starting the process, and force it into the background.
  265 .B Warning: start\-stop\-daemon
  266 cannot check the exit status if the process fails to execute for
  267 .B any
  268 reason. This is a last resort, and is only meant for programs that either
  269 make no sense forking on their own, or where it's not feasible to add the
  270 code for them to do this themselves.
  271 .TP
  272 .BR \-\-notify\-await
  273 Wait for the background process to send a readiness notification before
  274 considering the service started (since version 1.19.3).
  275 This implements parts of the systemd readiness procotol, as specified
  276 in the \fBsd_notify\fP(3) man page.
  277 The following variables are supported:
  278 .RS
  279 .TP
  280 .B READY=1
  281 The program is ready to give service, so we can exit safely.
  282 .TP
  283 .BI EXTEND_TIMEOUT_USEC= number
  284 The program requests to extend the timeout by \fInumber\fP microseconds.
  285 This will reset the current timeout to the specified value.
  286 .TP
  287 .BI ERRNO= number
  288 The program is exiting with an error.
  289 Do the same and print the user-friendly string for the \fBerrno\fP value.
  290 .RE
  291 .
  292 .TP
  293 .BI \-\-notify\-timeout timeout
  294 Set a timeout for the \fB\-\-notify\-await\fP option (since version 1.19.3).
  295 When the timeout is reached, \fBstart\-stop\-daemon\fP will exit with an
  296 error code, and no readiness notification will be awaited.
  297 The default is \fB60\fP seconds.
  298 .TP
  299 .BR \-C ", " \-\-no\-close
  300 Do not close any file descriptor when forcing the daemon into the background
  301 (since version 1.16.5).
  302 Used for debugging purposes to see the process output, or to redirect file
  303 descriptors to log the process output.
  304 Only relevant when using \fB\-\-background\fP.
  305 .TP
  306 .BR \-N ", " \-\-nicelevel " \fIint\fP"
  307 This alters the priority of the process before starting it.
  308 .TP
  309 .BR \-P ", " \-\-procsched " \fIpolicy\fP\fB:\fP\fIpriority\fP"
  310 This alters the process scheduler policy and priority of the process before
  311 starting it (since version 1.15.0).
  312 The priority can be optionally specified by appending a \fB:\fP
  313 followed by the value. The default \fIpriority\fP is 0. The currently
  314 supported policy values are \fBother\fP, \fBfifo\fP and \fBrr\fP.
  315 .TP
  316 .BR \-I ", " \-\-iosched " \fIclass\fP\fB:\fP\fIpriority\fP"
  317 This alters the IO scheduler class and priority of the process before starting
  318 it (since version 1.15.0).
  319 The priority can be optionally specified by appending a \fB:\fP followed
  320 by the value. The default \fIpriority\fP is 4, unless \fIclass\fP is \fBidle\fP,
  321 then \fIpriority\fP will always be 7. The currently supported values for
  322 \fIclass\fP are \fBidle\fP, \fBbest-effort\fP and \fBreal-time\fP.
  323 .TP
  324 .BR \-k ", " \-\-umask " \fImask\fP"
  325 This sets the umask of the process before starting it (since version 1.13.22).
  326 .TP
  327 .BR \-m ", " \-\-make\-pidfile
  328 Used when starting a program that does not create its own pid file. This
  329 option will make
  330 .B start\-stop\-daemon
  331 create the file referenced with
  332 .B \-\-pidfile
  333 and place the pid into it just before executing the process. Note, the
  334 file will only be removed when stopping the program if
  335 \fB\-\-remove\-pidfile\fP is used.
  336 .B Note:
  337 This feature may not work in all cases. Most notably when the program
  338 being executed forks from its main process. Because of this, it is usually
  339 only useful when combined with the
  340 .B \-\-background
  341 option.
  342 .TP
  343 .B \-\-remove\-pidfile
  344 Used when stopping a program that does not remove its own pid file
  345 (since version 1.17.19).
  346 This option will make
  347 .B start\-stop\-daemon
  348 remove the file referenced with
  349 .B \-\-pidfile
  350 after terminating the process.
  351 .TP
  352 .BR \-v ", " \-\-verbose
  353 Print verbose informational messages.
  354 .
  355 .SH EXIT STATUS
  356 .TP
  357 .B 0
  358 The requested action was performed. If
  359 .B \-\-oknodo
  360 was specified, it's also possible that nothing had to be done.
  361 This can happen when
  362 .B \-\-start
  363 was specified and a matching process was already running, or when
  364 .B \-\-stop
  365 was specified and there were no matching processes.
  366 .TP
  367 .B 1
  368 If
  369 .B \-\-oknodo
  370 was not specified and nothing was done.
  371 .TP
  372 .B 2
  373 If
  374 .B \-\-stop
  375 and
  376 .B \-\-retry
  377 were specified, but the end of the schedule was reached and the processes were
  378 still running.
  379 .TP
  380 .B 3
  381 Any other error.
  382 .PP
  383 When using the \fB\-\-status\fP command, the following status codes are
  384 returned:
  385 .TP
  386 .B 0
  387 Program is running.
  388 .TP
  389 .B 1
  390 Program is not running and the pid file exists.
  391 .TP
  392 .B 3
  393 Program is not running.
  394 .TP
  395 .B 4
  396 Unable to determine program status.
  397 .
  398 .SH EXAMPLE
  399 Start the \fBfood\fP daemon, unless one is already running (a process named
  400 food, running as user food, with pid in food.pid):
  401 .IP
  402 .nf
  403 start\-stop\-daemon \-\-start \-\-oknodo \-\-user food \-\-name food \\
  404 	\-\-pidfile /run/food.pid \-\-startas /usr/sbin/food \\
  405 	\-\-chuid food \-\- \-\-daemon
  406 .fi
  407 .PP
  408 Send \fBSIGTERM\fP to \fBfood\fP and wait up to 5 seconds for it to stop:
  409 .IP
  410 .nf
  411 start\-stop\-daemon \-\-stop \-\-oknodo \-\-user food \-\-name food \\
  412 	\-\-pidfile /run/food.pid \-\-retry 5
  413 .fi
  414 .PP
  415 Demonstration of a custom schedule for stopping \fBfood\fP:
  416 .IP
  417 .nf
  418 start\-stop\-daemon \-\-stop \-\-oknodo \-\-user food \-\-name food \\
  419 	\-\-pidfile /run/food.pid \-\-retry=TERM/30/KILL/5
  420 .fi

Generated by cgit