start-stop-daemon.8 8.9 KB

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