xref: /freebsd/usr.sbin/daemon/daemon.8 (revision 32b17786bdf640a0ec86dee11c2d9fe1665b999d)
1bd06a3ecSMike Barcroft.\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
2bd06a3ecSMike Barcroft.\"
3bd06a3ecSMike Barcroft.\" Redistribution and use in source and binary forms, with or without
4bd06a3ecSMike Barcroft.\" modification, are permitted provided that the following conditions
5bd06a3ecSMike Barcroft.\" are met:
6bd06a3ecSMike Barcroft.\" 1. Redistributions of source code must retain the above copyright
7bd06a3ecSMike Barcroft.\"    notice, this list of conditions and the following disclaimer.
8bd06a3ecSMike Barcroft.\" 2. Redistributions in binary form must reproduce the above copyright
9bd06a3ecSMike Barcroft.\"    notice, this list of conditions and the following disclaimer in the
10bd06a3ecSMike Barcroft.\"    documentation and/or other materials provided with the distribution.
11bd06a3ecSMike Barcroft.\" 3. Berkeley Software Design Inc's name may not be used to endorse or
12bd06a3ecSMike Barcroft.\"    promote products derived from this software without specific prior
13bd06a3ecSMike Barcroft.\"    written permission.
14bd06a3ecSMike Barcroft.\"
15bd06a3ecSMike Barcroft.\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
16bd06a3ecSMike Barcroft.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17bd06a3ecSMike Barcroft.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18bd06a3ecSMike Barcroft.\" ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
19bd06a3ecSMike Barcroft.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20bd06a3ecSMike Barcroft.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21bd06a3ecSMike Barcroft.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22bd06a3ecSMike Barcroft.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23bd06a3ecSMike Barcroft.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24bd06a3ecSMike Barcroft.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25bd06a3ecSMike Barcroft.\" SUCH DAMAGE.
26bd06a3ecSMike Barcroft.\"
27bd06a3ecSMike Barcroft.\" $FreeBSD$
28bd06a3ecSMike Barcroft.\"
29*32b17786SJohn-Mark Gurney.Dd September 13, 2013
30bd06a3ecSMike Barcroft.Dt DAEMON 8
31217758f8SRuslan Ermilov.Os
32bd06a3ecSMike Barcroft.Sh NAME
33bd06a3ecSMike Barcroft.Nm daemon
34bd06a3ecSMike Barcroft.Nd run detached from the controlling terminal
35bd06a3ecSMike Barcroft.Sh SYNOPSIS
36217758f8SRuslan Ermilov.Nm
3776462499SMikolaj Golub.Op Fl cfr
38*32b17786SJohn-Mark Gurney.Op Fl p Ar child_pidfile
39*32b17786SJohn-Mark Gurney.Op Fl P Ar supervisor_pidfile
40e6d4b388STom Rhodes.Op Fl u Ar user
41217758f8SRuslan Ermilov.Ar command arguments ...
42bd06a3ecSMike Barcroft.Sh DESCRIPTION
43bd06a3ecSMike BarcroftThe
44bd06a3ecSMike Barcroft.Nm
45bd06a3ecSMike Barcroftutility detaches itself from the controlling terminal and
46bd06a3ecSMike Barcroftexecutes the program specified by its arguments.
47e6d4b388STom RhodesPrivileges may be lowered to the specified user.
48bd06a3ecSMike Barcroft.Pp
49bd06a3ecSMike BarcroftThe options are as follows:
50217758f8SRuslan Ermilov.Bl -tag -width indent
51bd06a3ecSMike Barcroft.It Fl c
52217758f8SRuslan ErmilovChange the current working directory to the root
53217758f8SRuslan Ermilov.Pq Dq Pa / .
54bd06a3ecSMike Barcroft.It Fl f
55bd06a3ecSMike BarcroftRedirect standard input, standard output and standard error to
56bd06a3ecSMike Barcroft.Pa /dev/null .
57*32b17786SJohn-Mark Gurney.It Fl p Ar child_pidfile
582410103cSRuslan ErmilovWrite the ID of the created process into the
59*32b17786SJohn-Mark Gurney.Ar child_pidfile
60e6d4b388STom Rhodesusing the
61c6262cb6SPawel Jakub Dawidek.Xr pidfile 3
62c6262cb6SPawel Jakub Dawidekfunctionality.
632ad43027SMikolaj GolubThe program is executed in a spawned child process while the
642ad43027SMikolaj Golub.Nm
652ad43027SMikolaj Golubwaits until it terminates to keep the
66*32b17786SJohn-Mark Gurney.Ar child_pidfile
672ad43027SMikolaj Golublocked and removes it after the process exits.
682ad43027SMikolaj GolubThe
69*32b17786SJohn-Mark Gurney.Ar child_pidfile
70*32b17786SJohn-Mark Gurneyowner is the user who runs the
71*32b17786SJohn-Mark Gurney.Nm
72*32b17786SJohn-Mark Gurneyregardless of whether the
73*32b17786SJohn-Mark Gurney.Fl u
74*32b17786SJohn-Mark Gurneyoption is used or not.
75*32b17786SJohn-Mark Gurney.It Fl P Ar supervisor_pidfile
76*32b17786SJohn-Mark GurneyWrite the ID of the
77*32b17786SJohn-Mark Gurney.Nm
78*32b17786SJohn-Mark Gurneyprocess into the
79*32b17786SJohn-Mark Gurney.Ar supervisor_pidfile
80*32b17786SJohn-Mark Gurneyusing the
81*32b17786SJohn-Mark Gurney.Xr pidfile 3
82*32b17786SJohn-Mark Gurneyfunctionality.
83*32b17786SJohn-Mark GurneyThe program is executed in a spawned child process while the
84*32b17786SJohn-Mark Gurney.Nm
85*32b17786SJohn-Mark Gurneywaits until it terminates to keep the
86*32b17786SJohn-Mark Gurney.Ar supervisor_pidfile
87*32b17786SJohn-Mark Gurneylocked and removes it after the process exits.
88*32b17786SJohn-Mark GurneyThe
89*32b17786SJohn-Mark Gurney.Ar supervisor_pidfile
902ad43027SMikolaj Golubowner is the user who runs the
912ad43027SMikolaj Golub.Nm
922ad43027SMikolaj Golubregardless of whether the
93704523b0SGuy Helmer.Fl u
942ad43027SMikolaj Goluboption is used or not.
95b6193c24SMikolaj Golub.It Fl r
96b6193c24SMikolaj GolubSupervise and restart the program if it has been terminated.
97b6193c24SMikolaj Golub.It Fl u Ar user
98b6193c24SMikolaj GolubLogin name of the user to execute the program under.
99b6193c24SMikolaj GolubRequires adequate superuser privileges.
100b6193c24SMikolaj Golub.El
101b6193c24SMikolaj Golub.Pp
102b6193c24SMikolaj GolubIf the
103*32b17786SJohn-Mark Gurney.Fl p ,
104*32b17786SJohn-Mark Gurney.Fl P
105b6193c24SMikolaj Golubor
106b6193c24SMikolaj Golub.Fl r
107b6193c24SMikolaj Goluboption is specified the program is executed in a spawned child process.
108b6193c24SMikolaj GolubThe
109b6193c24SMikolaj Golub.Nm
110*32b17786SJohn-Mark Gurneywaits until it terminates to keep the pid file(s) locked and removes them
111b6193c24SMikolaj Golubafter the process exits or restarts the program.
112b6193c24SMikolaj GolubIn this case if the monitoring
113195fc497SMikolaj Golub.Nm
114195fc497SMikolaj Golubreceives software termination signal (SIGTERM) it forwards it to the
115195fc497SMikolaj Golubspawned process.
116*32b17786SJohn-Mark GurneyNormally it will cause the child to exit, remove the pidfile(s)
117*32b17786SJohn-Mark Gurneyand then terminate.
118*32b17786SJohn-Mark Gurney.Pp
119*32b17786SJohn-Mark GurneyThe
120*32b17786SJohn-Mark Gurney.Fl P
121*32b17786SJohn-Mark Gurneyoption is useful combined with the
122*32b17786SJohn-Mark Gurney.Fl r
123*32b17786SJohn-Mark Gurneyoption as
124*32b17786SJohn-Mark Gurney.Ar supervisor_pidfile
125*32b17786SJohn-Mark Gurneycontains the ID of the supervisor
126*32b17786SJohn-Mark Gurneynot the child. This is especially important if you use
127*32b17786SJohn-Mark Gurney.Fl r
128*32b17786SJohn-Mark Gurneyin an rc script as the
129*32b17786SJohn-Mark Gurney.Fl p
130*32b17786SJohn-Mark Gurneyoption will give you the child's ID to signal when you attempt to
131*32b17786SJohn-Mark Gurneystop the service, causing
132*32b17786SJohn-Mark Gurney.Nm
133*32b17786SJohn-Mark Gurneyto restart the child.
134a866e170SRuslan Ermilov.Sh EXIT STATUS
135bd06a3ecSMike BarcroftThe
136bd06a3ecSMike Barcroft.Nm
137bd06a3ecSMike Barcroftutility exits 1 if an error is returned by the
138bd06a3ecSMike Barcroft.Xr daemon 3
139*32b17786SJohn-Mark Gurneylibrary routine, 2 if
140*32b17786SJohn-Mark Gurney.Ar child_pidfile
141*32b17786SJohn-Mark Gurneyor
142*32b17786SJohn-Mark Gurney.Ar supervisor_pidfile
143c6262cb6SPawel Jakub Dawidekis requested, but cannot be opened, 3 if process is already running (pidfile
144c6262cb6SPawel Jakub Dawidekexists and is locked),
145846be7bdSPoul-Henning Kampotherwise 0.
146a866e170SRuslan Ermilov.Sh DIAGNOSTICS
147bd06a3ecSMike BarcroftIf the command cannot be executed, an error message is displayed on
148bd06a3ecSMike Barcroftstandard error unless the
149bd06a3ecSMike Barcroft.Fl f
150bd06a3ecSMike Barcroftflag is specified.
151bd06a3ecSMike Barcroft.Sh SEE ALSO
15212d7249eSTom Rhodes.Xr setregid 2 ,
15312d7249eSTom Rhodes.Xr setreuid 2 ,
154bd06a3ecSMike Barcroft.Xr daemon 3 ,
155bd06a3ecSMike Barcroft.Xr exec 3 ,
156c6262cb6SPawel Jakub Dawidek.Xr pidfile 3 ,
157bd06a3ecSMike Barcroft.Xr termios 4 ,
158bd06a3ecSMike Barcroft.Xr tty 4
159bd06a3ecSMike Barcroft.Sh HISTORY
160bd06a3ecSMike BarcroftThe
161bd06a3ecSMike Barcroft.Nm
162bd06a3ecSMike Barcroftutility first appeared in
163a7d4e017STom Rhodes.Fx 4.7 .
164