2001-08-30 04:48:02 +00:00
|
|
|
.\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. Berkeley Software Design Inc's name may not be used to endorse or
|
|
|
|
.\" promote products derived from this software without specific prior
|
|
|
|
.\" written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2019-03-25 21:14:51 +00:00
|
|
|
.Dd March 25, 2019
|
2001-08-30 04:48:02 +00:00
|
|
|
.Dt DAEMON 8
|
2001-08-31 12:52:50 +00:00
|
|
|
.Os
|
2001-08-30 04:48:02 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm daemon
|
|
|
|
.Nd run detached from the controlling terminal
|
|
|
|
.Sh SYNOPSIS
|
2001-08-31 12:52:50 +00:00
|
|
|
.Nm
|
2016-10-22 11:26:22 +00:00
|
|
|
.Op Fl cfrS
|
2013-09-13 16:57:28 +00:00
|
|
|
.Op Fl p Ar child_pidfile
|
|
|
|
.Op Fl P Ar supervisor_pidfile
|
2016-03-02 19:10:39 +00:00
|
|
|
.Op Fl t Ar title
|
2007-03-19 12:12:53 +00:00
|
|
|
.Op Fl u Ar user
|
2016-10-22 11:26:22 +00:00
|
|
|
.Op Fl m Ar output_mask
|
|
|
|
.Op Fl o Ar output_file
|
|
|
|
.Op Fl s Ar syslog_priority
|
|
|
|
.Op Fl T Ar syslog_tag
|
2018-01-26 08:52:28 +00:00
|
|
|
.Op Fl l Ar syslog_facility
|
2018-04-16 03:35:43 +00:00
|
|
|
.Op Fl R Ar restart_delay_seconds
|
2001-08-31 12:52:50 +00:00
|
|
|
.Ar command arguments ...
|
2001-08-30 04:48:02 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
2001-08-31 12:52:50 +00:00
|
|
|
utility detaches itself from the controlling terminal and
|
2001-08-30 04:48:02 +00:00
|
|
|
executes the program specified by its arguments.
|
2007-03-19 12:12:53 +00:00
|
|
|
Privileges may be lowered to the specified user.
|
2016-10-22 11:26:22 +00:00
|
|
|
The output of the daemonized process may be redirected to syslog and to a
|
|
|
|
log file.
|
2001-08-30 04:48:02 +00:00
|
|
|
.Pp
|
|
|
|
The options are as follows:
|
2001-08-31 12:52:50 +00:00
|
|
|
.Bl -tag -width indent
|
2001-08-30 04:48:02 +00:00
|
|
|
.It Fl c
|
2001-08-31 12:52:50 +00:00
|
|
|
Change the current working directory to the root
|
|
|
|
.Pq Dq Pa / .
|
2001-08-30 04:48:02 +00:00
|
|
|
.It Fl f
|
|
|
|
Redirect standard input, standard output and standard error to
|
|
|
|
.Pa /dev/null .
|
2016-10-22 11:26:22 +00:00
|
|
|
.It Fl S
|
|
|
|
Enable syslog output.
|
|
|
|
This is implicitly applied if other syslog parameters are provided.
|
2018-08-01 12:18:52 +00:00
|
|
|
The default values are daemon, notice, and daemon for facility, priority, and
|
2016-10-22 11:26:22 +00:00
|
|
|
tag, respectively.
|
|
|
|
.It Fl o Ar output_file
|
|
|
|
Append output from the daemonized process to
|
|
|
|
.Pa output_file .
|
|
|
|
If the file does not exist, it is created with permissions 0600.
|
|
|
|
.It Fl m Ar output_mask
|
|
|
|
Redirect output from the child process stdout (1), stderr (2), or both (3).
|
|
|
|
This value specifies what is sent to syslog and the log file.
|
|
|
|
The default is 3.
|
2013-09-13 16:57:28 +00:00
|
|
|
.It Fl p Ar child_pidfile
|
2004-07-07 19:57:16 +00:00
|
|
|
Write the ID of the created process into the
|
2013-09-13 16:57:28 +00:00
|
|
|
.Ar child_pidfile
|
2007-03-19 12:12:53 +00:00
|
|
|
using the
|
2005-08-24 17:24:39 +00:00
|
|
|
.Xr pidfile 3
|
|
|
|
functionality.
|
2012-02-19 10:20:37 +00:00
|
|
|
The program is executed in a spawned child process while the
|
|
|
|
.Nm
|
|
|
|
waits until it terminates to keep the
|
2013-09-13 16:57:28 +00:00
|
|
|
.Ar child_pidfile
|
2012-02-19 10:20:37 +00:00
|
|
|
locked and removes it after the process exits.
|
|
|
|
The
|
2013-09-13 16:57:28 +00:00
|
|
|
.Ar child_pidfile
|
|
|
|
owner is the user who runs the
|
|
|
|
.Nm
|
|
|
|
regardless of whether the
|
|
|
|
.Fl u
|
|
|
|
option is used or not.
|
|
|
|
.It Fl P Ar supervisor_pidfile
|
2013-09-13 19:19:21 +00:00
|
|
|
Write the ID of the
|
2013-09-13 16:57:28 +00:00
|
|
|
.Nm
|
|
|
|
process into the
|
|
|
|
.Ar supervisor_pidfile
|
|
|
|
using the
|
|
|
|
.Xr pidfile 3
|
|
|
|
functionality.
|
|
|
|
The program is executed in a spawned child process while the
|
|
|
|
.Nm
|
|
|
|
waits until it terminates to keep the
|
|
|
|
.Ar supervisor_pidfile
|
|
|
|
locked and removes it after the process exits.
|
|
|
|
The
|
|
|
|
.Ar supervisor_pidfile
|
2012-02-19 10:20:37 +00:00
|
|
|
owner is the user who runs the
|
|
|
|
.Nm
|
|
|
|
regardless of whether the
|
2012-01-25 14:50:12 +00:00
|
|
|
.Fl u
|
2012-02-19 10:20:37 +00:00
|
|
|
option is used or not.
|
2012-02-19 10:36:29 +00:00
|
|
|
.It Fl r
|
2018-04-15 21:46:08 +00:00
|
|
|
Supervise and restart the program after a one-second delay if it has
|
|
|
|
been terminated.
|
2018-08-01 12:18:52 +00:00
|
|
|
.It Fl R Ar restart_delay_seconds
|
2018-04-15 21:46:08 +00:00
|
|
|
Supervise and restart the program after the specified delay
|
|
|
|
if it has been terminated.
|
2016-03-02 19:10:39 +00:00
|
|
|
.It Fl t Ar title
|
2016-10-22 11:26:22 +00:00
|
|
|
Set the title for the daemon process.
|
|
|
|
The default is the daemonized invocation.
|
2012-02-19 10:36:29 +00:00
|
|
|
.It Fl u Ar user
|
|
|
|
Login name of the user to execute the program under.
|
|
|
|
Requires adequate superuser privileges.
|
2016-10-22 11:26:22 +00:00
|
|
|
.It Fl s Ar syslog_priority
|
|
|
|
These priorities are accepted: emerg, alert, crit, err, warning,
|
|
|
|
notice, info, and debug.
|
2019-03-25 21:14:51 +00:00
|
|
|
The default is notice.
|
2016-10-22 11:26:22 +00:00
|
|
|
.It Fl l Ar syslog_facility
|
|
|
|
These facilities are accepted: auth, authpriv, console, cron, daemon,
|
|
|
|
ftp, kern, lpr, mail, news, ntp, security, syslog, user, uucp, and
|
|
|
|
local0, ..., local7.
|
|
|
|
The default is daemon.
|
|
|
|
.It Fl T Ar syslog_tag
|
|
|
|
Set the tag which is appended to all syslog messages.
|
|
|
|
The default is daemon.
|
2012-02-19 10:36:29 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2016-10-22 11:26:22 +00:00
|
|
|
If any of the options
|
2013-09-13 16:57:28 +00:00
|
|
|
.Fl p ,
|
2016-10-22 11:26:22 +00:00
|
|
|
.Fl P ,
|
|
|
|
.Fl r ,
|
|
|
|
.Fl o ,
|
|
|
|
.Fl s ,
|
|
|
|
.Fl T ,
|
|
|
|
.Fl m ,
|
|
|
|
.Fl S ,
|
2012-02-19 10:36:29 +00:00
|
|
|
or
|
2016-10-22 11:26:22 +00:00
|
|
|
.Fl l
|
|
|
|
are specified, the program is executed in a spawned child process.
|
2012-02-19 10:36:29 +00:00
|
|
|
The
|
|
|
|
.Nm
|
2013-09-13 16:57:28 +00:00
|
|
|
waits until it terminates to keep the pid file(s) locked and removes them
|
2012-02-19 10:36:29 +00:00
|
|
|
after the process exits or restarts the program.
|
|
|
|
In this case if the monitoring
|
2012-02-19 10:23:51 +00:00
|
|
|
.Nm
|
|
|
|
receives software termination signal (SIGTERM) it forwards it to the
|
|
|
|
spawned process.
|
2013-09-13 16:57:28 +00:00
|
|
|
Normally it will cause the child to exit, remove the pidfile(s)
|
|
|
|
and then terminate.
|
|
|
|
.Pp
|
2016-10-22 11:26:22 +00:00
|
|
|
If neither file or syslog output are selected, all output is redirected to the
|
|
|
|
.Nm
|
|
|
|
process and written to stdout.
|
|
|
|
The
|
|
|
|
.Fl f
|
|
|
|
option may be used to suppress the stdout output completely.
|
|
|
|
.Pp
|
2013-09-13 16:57:28 +00:00
|
|
|
The
|
|
|
|
.Fl P
|
|
|
|
option is useful combined with the
|
|
|
|
.Fl r
|
2013-09-13 19:19:21 +00:00
|
|
|
option as
|
2013-09-13 16:57:28 +00:00
|
|
|
.Ar supervisor_pidfile
|
|
|
|
contains the ID of the supervisor
|
2016-03-02 19:10:39 +00:00
|
|
|
not the child.
|
|
|
|
This is especially important if you use
|
2013-09-13 16:57:28 +00:00
|
|
|
.Fl r
|
|
|
|
in an rc script as the
|
|
|
|
.Fl p
|
|
|
|
option will give you the child's ID to signal when you attempt to
|
2013-09-13 19:19:21 +00:00
|
|
|
stop the service, causing
|
2013-09-13 16:57:28 +00:00
|
|
|
.Nm
|
|
|
|
to restart the child.
|
2005-01-17 07:44:44 +00:00
|
|
|
.Sh EXIT STATUS
|
2001-08-30 04:48:02 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility exits 1 if an error is returned by the
|
|
|
|
.Xr daemon 3
|
2013-09-13 16:57:28 +00:00
|
|
|
library routine, 2 if
|
|
|
|
.Ar child_pidfile
|
|
|
|
or
|
|
|
|
.Ar supervisor_pidfile
|
2005-08-24 17:24:39 +00:00
|
|
|
is requested, but cannot be opened, 3 if process is already running (pidfile
|
2016-10-22 11:26:22 +00:00
|
|
|
exists and is locked), 4 if
|
|
|
|
.Ar syslog_priority
|
|
|
|
is not accepted, 5 if
|
|
|
|
.Ar syslog_facility
|
|
|
|
is not accepted, 6 if
|
|
|
|
.Ar output_mask
|
|
|
|
is not within the accepted range, 7 if
|
|
|
|
.Ar output_file
|
|
|
|
cannot be opened for appending, and otherwise 0.
|
2005-01-17 07:44:44 +00:00
|
|
|
.Sh DIAGNOSTICS
|
2016-10-22 11:26:22 +00:00
|
|
|
If the command cannot be executed, an error message is printed to
|
|
|
|
standard error.
|
|
|
|
The exact behavior depends on the logging parameters and the
|
2001-08-30 04:48:02 +00:00
|
|
|
.Fl f
|
2016-10-22 11:26:22 +00:00
|
|
|
flag.
|
2001-08-30 04:48:02 +00:00
|
|
|
.Sh SEE ALSO
|
2018-11-09 13:47:06 +00:00
|
|
|
.Xr nohup 1 ,
|
2007-03-09 09:33:19 +00:00
|
|
|
.Xr setregid 2 ,
|
|
|
|
.Xr setreuid 2 ,
|
2001-08-30 04:48:02 +00:00
|
|
|
.Xr daemon 3 ,
|
|
|
|
.Xr exec 3 ,
|
2005-08-24 17:24:39 +00:00
|
|
|
.Xr pidfile 3 ,
|
2001-08-30 04:48:02 +00:00
|
|
|
.Xr termios 4 ,
|
|
|
|
.Xr tty 4
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility first appeared in
|
2003-02-05 19:16:18 +00:00
|
|
|
.Fx 4.7 .
|