start-stop-daemon.8 11 KB

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