start-stop-daemon.8 9.3 KB

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