]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/daemon/daemon.8
Bring lld (release_39 branch, r279477) to contrib
[FreeBSD/FreeBSD.git] / usr.sbin / daemon / daemon.8
1 .\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
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.
14 .\"
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
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .Dd March 2, 2016
30 .Dt DAEMON 8
31 .Os
32 .Sh NAME
33 .Nm daemon
34 .Nd run detached from the controlling terminal
35 .Sh SYNOPSIS
36 .Nm
37 .Op Fl cfr
38 .Op Fl p Ar child_pidfile
39 .Op Fl P Ar supervisor_pidfile
40 .Op Fl t Ar title
41 .Op Fl u Ar user
42 .Ar command arguments ...
43 .Sh DESCRIPTION
44 The
45 .Nm
46 utility detaches itself from the controlling terminal and
47 executes the program specified by its arguments.
48 Privileges may be lowered to the specified user.
49 .Pp
50 The options are as follows:
51 .Bl -tag -width indent
52 .It Fl c
53 Change the current working directory to the root
54 .Pq Dq Pa / .
55 .It Fl f
56 Redirect standard input, standard output and standard error to
57 .Pa /dev/null .
58 .It Fl p Ar child_pidfile
59 Write the ID of the created process into the
60 .Ar child_pidfile
61 using the
62 .Xr pidfile 3
63 functionality.
64 The program is executed in a spawned child process while the
65 .Nm
66 waits until it terminates to keep the
67 .Ar child_pidfile
68 locked and removes it after the process exits.
69 The
70 .Ar child_pidfile
71 owner is the user who runs the
72 .Nm
73 regardless of whether the
74 .Fl u
75 option is used or not.
76 .It Fl P Ar supervisor_pidfile
77 Write the ID of the
78 .Nm
79 process into the
80 .Ar supervisor_pidfile
81 using the
82 .Xr pidfile 3
83 functionality.
84 The program is executed in a spawned child process while the
85 .Nm
86 waits until it terminates to keep the
87 .Ar supervisor_pidfile
88 locked and removes it after the process exits.
89 The
90 .Ar supervisor_pidfile
91 owner is the user who runs the
92 .Nm
93 regardless of whether the
94 .Fl u
95 option is used or not.
96 .It Fl r
97 Supervise and restart the program if it has been terminated.
98 .It Fl t Ar title
99 Process title for the daemon to make it easily identifiable.
100 .It Fl u Ar user
101 Login name of the user to execute the program under.
102 Requires adequate superuser privileges.
103 .El
104 .Pp
105 If the
106 .Fl p ,
107 .Fl P
108 or
109 .Fl r
110 option is specified the program is executed in a spawned child process.
111 The
112 .Nm
113 waits until it terminates to keep the pid file(s) locked and removes them
114 after the process exits or restarts the program.
115 In this case if the monitoring
116 .Nm
117 receives software termination signal (SIGTERM) it forwards it to the
118 spawned process.
119 Normally it will cause the child to exit, remove the pidfile(s)
120 and then terminate.
121 .Pp
122 The
123 .Fl P
124 option is useful combined with the
125 .Fl r
126 option as
127 .Ar supervisor_pidfile
128 contains the ID of the supervisor
129 not the child.
130 This is especially important if you use
131 .Fl r
132 in an rc script as the
133 .Fl p
134 option will give you the child's ID to signal when you attempt to
135 stop the service, causing
136 .Nm
137 to restart the child.
138 .Sh EXIT STATUS
139 The
140 .Nm
141 utility exits 1 if an error is returned by the
142 .Xr daemon 3
143 library routine, 2 if
144 .Ar child_pidfile
145 or
146 .Ar supervisor_pidfile
147 is requested, but cannot be opened, 3 if process is already running (pidfile
148 exists and is locked),
149 otherwise 0.
150 .Sh DIAGNOSTICS
151 If the command cannot be executed, an error message is displayed on
152 standard error unless the
153 .Fl f
154 flag is specified.
155 .Sh SEE ALSO
156 .Xr setregid 2 ,
157 .Xr setreuid 2 ,
158 .Xr daemon 3 ,
159 .Xr exec 3 ,
160 .Xr pidfile 3 ,
161 .Xr termios 4 ,
162 .Xr tty 4
163 .Sh HISTORY
164 The
165 .Nm
166 utility first appeared in
167 .Fx 4.7 .