start-stop-daemon.8 11 KB

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