1 .\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
11 .\" 3. Berkeley Software Design Inc's name may not be used to endorse or
12 .\" promote products derived from this software without specific prior
13 .\" written permission.
15 .\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .Dd September 18, 2023
32 .Nd run detached from the controlling terminal
36 .Op Fl p Ar child_pidfile
37 .Op Fl P Ar supervisor_pidfile
40 .Op Fl m Ar output_mask
41 .Op Fl o Ar output_file
42 .Op Fl s Ar syslog_priority
43 .Op Fl T Ar syslog_tag
44 .Op Fl l Ar syslog_facility
45 .Op Fl R Ar restart_delay_seconds
46 .Ar command arguments ...
50 utility detaches itself from the controlling terminal and
51 executes the program specified by its arguments.
52 Privileges may be lowered to the specified user.
53 The output of the daemonized process may be redirected to syslog and to a
56 The options are as follows:
57 .Bl -tag -width indent
58 .It Fl c , Fl -change-dir
59 Change the current working directory to the root
61 .It Fl f , Fl -close-fds
62 Redirect standard input, standard output and standard error to
64 When this option is used together with any of the options related to file
65 or syslog output, the standard file descriptors are first redirected to
67 then stdout and/or stderr is redirected to a file or to syslog as
68 specified by the other options.
72 and re-open it when signal
74 is received, for interoperability with
76 and similar log rotation / archival mechanisms. If
78 is not specified, this flag is ignored.
79 .It Fl l , Fl -syslog-facility Ar syslog_facility
80 These facilities are accepted:
81 .Cm auth , authpriv , console , cron , daemon ,
82 .Cm ftp , kern , lpr , mail , news , ntp , security ,
83 .Cm syslog , user , uucp ,
91 .It Fl m , Fl -output-mask Ar output_mask
92 Redirect output from the child process stdout
98 This value specifies what is sent to syslog and the log file.
101 .It Fl o , Fl -output-file Ar output_file
102 Append output from the daemonized process to
104 If the file does not exist, it is created with permissions 0600.
105 When this option is used together with options
109 the absolute path needs to be provided to ensure
111 can re-open the file after a
113 .It Fl P , Fl -supervisor-pidfile Ar supervisor_pidfile
117 .Ar supervisor_pidfile
121 The program is executed in a spawned child process while the
123 waits until it terminates to keep the
124 .Ar supervisor_pidfile
125 locked and removes it after the process exits.
127 .Ar supervisor_pidfile
128 owner is the user who runs the
130 regardless of whether the
132 option is used or not.
133 .It Fl p , Fl -child-pidfile Ar child_pidfile
134 Write the ID of the created process into the
139 The program is executed in a spawned child process while the
141 waits until it terminates to keep the
143 locked and removes it after the process exits.
146 owner is the user who runs the
148 regardless of whether the
150 option is used or not.
151 .It Fl R , Fl -restart-delay Ar restart_delay_seconds
152 Supervise and restart the program after the specified delay
153 if it has been terminated.
154 .It Fl r , Fl -restart
155 Supervise and restart the program after a one-second delay if it has
157 .It Fl S , Fl -syslog
158 Enable syslog output.
159 This is implicitly applied if other syslog parameters are provided.
160 The default values are daemon, notice, and daemon for facility, priority, and
162 .It Fl s , Fl -syslog-priority Ar syslog_priority
163 These priorities are accepted:
164 .Cm emerg , alert , crit , err , warning ,
170 .It Fl T , Fl -syslog-tag Ar syslog_tag
171 Set the tag which is appended to all syslog messages.
174 .It Fl t , Fl -title Ar title
175 Set the title for the daemon process.
176 The default is the daemonized invocation.
177 .It Fl u , Fl -user Ar user
178 Login name of the user to execute the program under.
179 Environment variables
184 Requires adequate superuser privileges.
187 If any of the options
192 .Fl -supervisor-pidfile ,
195 .Fl -syslog-priority ,
199 are specified, the program is executed in a spawned child process.
202 waits until it terminates to keep the pid file(s) locked and removes them
203 after the process exits or restarts the program.
204 In this case if the monitoring
206 receives software termination signal
208 it forwards it to the
210 Normally it will cause the child to exit, remove the pidfile(s)
213 If neither file or syslog output are selected, all output is redirected to the
215 process and written to stdout.
218 option may be used to suppress the stdout output completely.
221 .Fl -supervisor-pidfile
222 option is useful combined with the
225 .Ar supervisor_pidfile
226 contains the ID of the supervisor
228 This is especially important if you use
230 in an rc script as the
232 option will give you the child's ID to signal when you attempt to
233 stop the service, causing
235 to restart the child.
239 utility exits 1 if an error is returned by the
241 library routine, 2 if
244 .Ar supervisor_pidfile
245 is requested, but cannot be opened, 3 if process is already running (pidfile
246 exists and is locked), 4 if
248 is not accepted, 5 if
250 is not accepted, 6 if
252 is not within the accepted range, 7 if
254 cannot be opened for appending, and otherwise 0.
256 If the command cannot be executed, an error message is printed to
258 The exact behavior depends on the logging parameters and the
273 utility first appeared in