start-stop-daemon.man 12 KB

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