start-stop-daemon.8 12 KB

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