start-stop-daemon.8 10 KB

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