start-stop-daemon.8 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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-2014 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 "2014-03-26" "Debian Project" "dpkg utilities"
  24. .SH NAME
  25. start\-stop\-daemon \- start and stop system daemon programs
  26. .
  27. .SH SYNOPSIS
  28. .B start\-stop\-daemon
  29. .RI [ option "...] " command
  30. .
  31. .SH DESCRIPTION
  32. .B start\-stop\-daemon
  33. is used to control the creation and termination of system-level processes.
  34. Using one of the matching options, \fBstart\-stop\-daemon\fP
  35. can be configured to find existing instances of a running process.
  36. .PP
  37. Note: unless
  38. .B \-\-pid
  39. or
  40. .B \-\-pidfile
  41. are specified,
  42. .B start\-stop\-daemon
  43. behaves similar to
  44. .BR killall (1).
  45. .B start\-stop\-daemon
  46. will scan the process table looking for any processes which
  47. match the process name, parent pid, uid, and/or gid (if specified). Any
  48. matching process will prevent
  49. .BR \-\-start
  50. from starting the daemon. All matching processes will be sent the TERM
  51. signal (or the one specified via \fB\-\-signal\fP or \fB\-\-retry\fP) if
  52. .BR \-\-stop
  53. is specified. For daemons which have long-lived children
  54. which need to live through a
  55. .BR \-\-stop ,
  56. you must specify a pidfile.
  57. .
  58. .SH COMMANDS
  59. .TP
  60. .BR \-S ", " \-\-start " [" \-\- "] \fIarguments\fP"
  61. Check for the existence of a specified process.
  62. If such a process exists,
  63. .B start\-stop\-daemon
  64. does nothing, and exits with error status 1 (0 if
  65. .BR \-\-oknodo
  66. is specified).
  67. If such a process does not exist, it starts an
  68. instance, using either the executable specified by
  69. .B \-\-exec
  70. or, if specified, by
  71. .BR \-\-startas .
  72. Any arguments given after
  73. .BR \-\-
  74. on the command line are passed unmodified to the program being
  75. started.
  76. .TP
  77. .BR \-K ", " \-\-stop
  78. Checks for the existence of a specified process.
  79. If such a process exists,
  80. .B start\-stop\-daemon
  81. sends it the signal specified by
  82. .BR \-\-signal ,
  83. and exits with error status 0.
  84. If such a process does not exist,
  85. .B start\-stop\-daemon
  86. exits with error status 1
  87. (0 if
  88. .BR \-\-oknodo
  89. is specified). If
  90. .B \-\-retry
  91. is specified, then
  92. .B start\-stop\-daemon
  93. will check that the process(es) have terminated.
  94. .TP
  95. .BR \-T ", " \-\-status
  96. Check for the existence of a specified process, and returns an exit status
  97. code, according to the LSB Init Script Actions.
  98. .TP
  99. .BR \-H ", " \-\-help
  100. Show usage information and exit.
  101. .TP
  102. .BR \-V ", " \-\-version
  103. Show the program version and exit.
  104. .
  105. .SH OPTIONS
  106. .SS Matching options
  107. .TP
  108. .BR \-\-pid " \fIpid\fP"
  109. Check for a process with the specified \fIpid\fP. The \fIpid\fP must be a
  110. number greater than 0.
  111. .TP
  112. .BR \-\-ppid " \fIppid\fP"
  113. Check for a process with the specified \fIppid\fP (parent pid).
  114. The \fIppid\fP must be a number greater than 0.
  115. .TP
  116. .BR \-p ", " \-\-pidfile " \fIpid-file\fP"
  117. Check whether a process has created the file \fIpid-file\fP. Note: using this
  118. matching option alone might cause unintended processes to be acted on, if the
  119. old process terminated without being able to remove the \fIpid-file\fP.
  120. .TP
  121. .BR \-x ", " \-\-exec " \fIexecutable\fP"
  122. Check for processes that are instances of this \fIexecutable\fP. The
  123. \fIexecutable\fP argument should be an absolute pathname. Note: this might
  124. not work as intended with interpreted scripts, as the executable will point
  125. to the interpreter. Take into account processes running from inside a chroot
  126. will also be matched, so other match restrictions might be needed.
  127. .TP
  128. .BR \-n ", " \-\-name " \fIprocess-name\fP"
  129. Check for processes with the name \fIprocess-name\fP. The \fIprocess-name\fP
  130. is usually the process filename, but it could have been changed by the
  131. process itself. Note: on most systems this information is retrieved from
  132. the process comm name from the kernel, which tends to have a relatively
  133. short length limit (assuming more than 15 characters is non-portable).
  134. .TP
  135. .BR \-u ", " \-\-user " \fIusername\fP|\fIuid\fP
  136. Check for processes owned by the user specified by \fIusername\fP or
  137. \fIuid\fP. Note: using this matching option alone will cause all processes
  138. matching the user to be acted on.
  139. .
  140. .SS Generic options
  141. .TP
  142. .BR \-g ", " \-\-group " \fIgroup\fP|\fIgid\fP"
  143. Change to \fIgroup\fP or \fIgid\fP when starting the process.
  144. .TP
  145. .BR \-s ", " \-\-signal " \fIsignal\fP"
  146. With
  147. .BR \-\-stop ,
  148. specifies the signal to send to processes being stopped (default TERM).
  149. .TP
  150. .BR \-R ", " \-\-retry " \fItimeout\fP|\fIschedule\fP"
  151. With
  152. .BR \-\-stop ,
  153. specifies that
  154. .B start\-stop\-daemon
  155. is to check whether the process(es)
  156. do finish. It will check repeatedly whether any matching processes
  157. are running, until none are. If the processes do not exit it will
  158. then take further action as determined by the schedule.
  159. If
  160. .I timeout
  161. is specified instead of
  162. .IR schedule ,
  163. then the schedule
  164. .IB signal / timeout /KILL/ timeout
  165. is used, where
  166. .I signal
  167. is the signal specified with
  168. .BR \-\-signal .
  169. .I schedule
  170. is a list of at least two items separated by slashes
  171. .RB ( / );
  172. each item may be
  173. .BI \- signal-number
  174. or [\fB\-\fP]\fIsignal-name\fP,
  175. which means to send that signal,
  176. or
  177. .IR timeout ,
  178. which means to wait that many seconds for processes to
  179. exit,
  180. or
  181. .BR forever ,
  182. which means to repeat the rest of the schedule forever if
  183. necessary.
  184. If the end of the schedule is reached and
  185. .BR forever
  186. is not specified, then
  187. .B start\-stop\-daemon
  188. exits with error status 2.
  189. If a schedule is specified, then any signal specified
  190. with
  191. .B \-\-signal
  192. is ignored.
  193. .TP
  194. .BR \-a ", " \-\-startas " \fIpathname\fP"
  195. With
  196. .BR \-\-start ,
  197. start the process specified by
  198. .IR pathname .
  199. If not specified, defaults to the argument given to
  200. .BR \-\-exec .
  201. .TP
  202. .BR \-t ", " \-\-test
  203. Print actions that would be taken and set appropriate return value,
  204. but take no action.
  205. .TP
  206. .BR \-o ", " \-\-oknodo
  207. Return exit status 0 instead of 1 if no actions are (would be) taken.
  208. .TP
  209. .BR \-q ", " \-\-quiet
  210. Do not print informational messages; only display error messages.
  211. .TP
  212. .BR \-c ", " \-\-chuid " \fIusername\fR|\fIuid\fP[\fB:\fP\fIgroup\fR|\fIgid\fP]"
  213. Change to this username/uid before starting the process. You can also
  214. specify a group by appending a
  215. .BR : ,
  216. then the group or gid in the same way
  217. as you would for the `chown' command (\fIuser\fP\fB:\fP\fIgroup\fP).
  218. If a user is specified without a group, the primary GID for that user is used.
  219. When using this option
  220. you must realize that the primary and supplemental groups are set as well,
  221. even if the
  222. .B \-\-group
  223. option is not specified. The
  224. .B \-\-group
  225. option is only for
  226. groups that the user isn't normally a member of (like adding per process
  227. group membership for generic users like
  228. .BR nobody ).
  229. .TP
  230. .BR \-r ", " \-\-chroot " \fIroot\fP"
  231. Chdir and chroot to
  232. .I root
  233. before starting the process. Please note that the pidfile is also written
  234. after the chroot.
  235. .TP
  236. .BR \-d ", " \-\-chdir " \fIpath\fP"
  237. Chdir to
  238. .I path
  239. before starting the process. This is done after the chroot if the
  240. \fB\-r\fP|\fB\-\-chroot\fP option is set. When not specified,
  241. .B start\-stop\-daemon
  242. will chdir to the root directory before starting the process.
  243. .TP
  244. .BR \-b ", " \-\-background
  245. Typically used with programs that don't detach on their own. This option
  246. will force
  247. .B start\-stop\-daemon
  248. to fork before starting the process, and force it into the background.
  249. .B WARNING: start\-stop\-daemon
  250. cannot check the exit status if the process fails to execute for
  251. .B any
  252. reason. This is a last resort, and is only meant for programs that either
  253. make no sense forking on their own, or where it's not feasible to add the
  254. code for them to do this themselves.
  255. .TP
  256. .BR \-C ", " \-\-no\-close
  257. Do not close any file descriptor when forcing the daemon into the background.
  258. Used for debugging purposes to see the process output, or to redirect file
  259. descriptors to log the process output.
  260. Only relevant when using \fB\-\-background\fP.
  261. .TP
  262. .BR \-N ", " \-\-nicelevel " \fIint\fP"
  263. This alters the priority of the process before starting it.
  264. .TP
  265. .BR \-P ", " \-\-procsched " \fIpolicy\fP\fB:\fP\fIpriority\fP"
  266. This alters the process scheduler policy and priority of the process before
  267. starting it. The priority can be optionally specified by appending a \fB:\fP
  268. followed by the value. The default \fIpriority\fP is 0. The currently
  269. supported policy values are \fBother\fP, \fBfifo\fP and \fBrr\fP.
  270. .TP
  271. .BR \-I ", " \-\-iosched " \fIclass\fP\fB:\fP\fIpriority\fP"
  272. This alters the IO scheduler class and priority of the process before starting
  273. it. The priority can be optionally specified by appending a \fB:\fP followed
  274. by the value. The default \fIpriority\fP is 4, unless \fIclass\fP is \fBidle\fP,
  275. then \fIpriority\fP will always be 7. The currently supported values for
  276. \fIclass\fP are \fBidle\fP, \fBbest-effort\fP and \fBreal-time\fP.
  277. .TP
  278. .BR \-k ", " \-\-umask " \fImask\fP"
  279. This sets the umask of the process before starting it.
  280. .TP
  281. .BR \-m ", " \-\-make\-pidfile
  282. Used when starting a program that does not create its own pid file. This
  283. option will make
  284. .B start\-stop\-daemon
  285. create the file referenced with
  286. .B \-\-pidfile
  287. and place the pid into it just before executing the process. Note, the
  288. file will only be removed when stopping the program if
  289. \fB\-\-remove\-pidfile\fP is used.
  290. .B NOTE:
  291. This feature may not work in all cases. Most notably when the program
  292. being executed forks from its main process. Because of this, it is usually
  293. only useful when combined with the
  294. .B \-\-background
  295. option.
  296. .TP
  297. .B \-\-remove\-pidfile
  298. Used when stopping a program that does not remove its own pid file. This
  299. option will make
  300. .B start\-stop\-daemon
  301. remove the file referenced with
  302. .B \-\-pidfile
  303. after terminating the process.
  304. .TP
  305. .BR \-v ", " \-\-verbose
  306. Print verbose informational messages.
  307. .
  308. .SH EXIT STATUS
  309. .TP
  310. .B 0
  311. The requested action was performed. If
  312. .B \-\-oknodo
  313. was specified, it's also possible that nothing had to be done.
  314. This can happen when
  315. .B \-\-start
  316. was specified and a matching process was already running, or when
  317. .B \-\-stop
  318. was specified and there were no matching processes.
  319. .TP
  320. .B 1
  321. If
  322. .B \-\-oknodo
  323. was not specified and nothing was done.
  324. .TP
  325. .B 2
  326. If
  327. .B \-\-stop
  328. and
  329. .B \-\-retry
  330. were specified, but the end of the schedule was reached and the processes were
  331. still running.
  332. .TP
  333. .B 3
  334. Any other error.
  335. .PP
  336. When using the \fB\-\-status\fP command, the following status codes are
  337. returned:
  338. .TP
  339. .B 0
  340. Program is running.
  341. .TP
  342. .B 1
  343. Program is not running and the pid file exists.
  344. .TP
  345. .B 3
  346. Program is not running.
  347. .TP
  348. .B 4
  349. Unable to determine program status.
  350. .
  351. .SH EXAMPLE
  352. Start the \fBfood\fP daemon, unless one is already running (a process named
  353. food, running as user food, with pid in food.pid):
  354. .IP
  355. .nf
  356. start\-stop\-daemon \-\-start \-\-oknodo \-\-user food \-\-name food \\
  357. \-\-pidfile /run/food.pid \-\-startas /usr/sbin/food \\
  358. \-\-chuid food \-\- \-\-daemon
  359. .fi
  360. .PP
  361. Send \fBSIGTERM\fP to \fBfood\fP and wait up to 5 seconds for it to stop:
  362. .IP
  363. .nf
  364. start\-stop\-daemon \-\-stop \-\-oknodo \-\-user food \-\-name food \\
  365. \-\-pidfile /run/food.pid \-\-retry 5
  366. .fi
  367. .PP
  368. Demonstration of a custom schedule for stopping \fBfood\fP:
  369. .IP
  370. .nf
  371. start\-stop\-daemon \-\-stop \-\-oknodo \-\-user food \-\-name food \\
  372. \-\-pidfile /run/food.pid \-\-retry=TERM/30/KILL/5
  373. .fi