start-stop-daemon.8 11 KB

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