xref: /freebsd/usr.sbin/daemon/daemon.8 (revision 112bfcf5e4e4309afa9c8fcccd120e36fa2dd3fa)
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*112bfcf5SConrad Meyer.Dd March 2, 2016
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
3832b17786SJohn-Mark Gurney.Op Fl p Ar child_pidfile
3932b17786SJohn-Mark Gurney.Op Fl P Ar supervisor_pidfile
40*112bfcf5SConrad Meyer.Op Fl t Ar title
41e6d4b388STom Rhodes.Op Fl u Ar user
42217758f8SRuslan Ermilov.Ar command arguments ...
43bd06a3ecSMike Barcroft.Sh DESCRIPTION
44bd06a3ecSMike BarcroftThe
45bd06a3ecSMike Barcroft.Nm
46bd06a3ecSMike Barcroftutility detaches itself from the controlling terminal and
47bd06a3ecSMike Barcroftexecutes the program specified by its arguments.
48e6d4b388STom RhodesPrivileges may be lowered to the specified user.
49bd06a3ecSMike Barcroft.Pp
50bd06a3ecSMike BarcroftThe options are as follows:
51217758f8SRuslan Ermilov.Bl -tag -width indent
52bd06a3ecSMike Barcroft.It Fl c
53217758f8SRuslan ErmilovChange the current working directory to the root
54217758f8SRuslan Ermilov.Pq Dq Pa / .
55bd06a3ecSMike Barcroft.It Fl f
56bd06a3ecSMike BarcroftRedirect standard input, standard output and standard error to
57bd06a3ecSMike Barcroft.Pa /dev/null .
5832b17786SJohn-Mark Gurney.It Fl p Ar child_pidfile
592410103cSRuslan ErmilovWrite the ID of the created process into the
6032b17786SJohn-Mark Gurney.Ar child_pidfile
61e6d4b388STom Rhodesusing the
62c6262cb6SPawel Jakub Dawidek.Xr pidfile 3
63c6262cb6SPawel Jakub Dawidekfunctionality.
642ad43027SMikolaj GolubThe program is executed in a spawned child process while the
652ad43027SMikolaj Golub.Nm
662ad43027SMikolaj Golubwaits until it terminates to keep the
6732b17786SJohn-Mark Gurney.Ar child_pidfile
682ad43027SMikolaj Golublocked and removes it after the process exits.
692ad43027SMikolaj GolubThe
7032b17786SJohn-Mark Gurney.Ar child_pidfile
7132b17786SJohn-Mark Gurneyowner is the user who runs the
7232b17786SJohn-Mark Gurney.Nm
7332b17786SJohn-Mark Gurneyregardless of whether the
7432b17786SJohn-Mark Gurney.Fl u
7532b17786SJohn-Mark Gurneyoption is used or not.
7632b17786SJohn-Mark Gurney.It Fl P Ar supervisor_pidfile
7732b17786SJohn-Mark GurneyWrite the ID of the
7832b17786SJohn-Mark Gurney.Nm
7932b17786SJohn-Mark Gurneyprocess into the
8032b17786SJohn-Mark Gurney.Ar supervisor_pidfile
8132b17786SJohn-Mark Gurneyusing the
8232b17786SJohn-Mark Gurney.Xr pidfile 3
8332b17786SJohn-Mark Gurneyfunctionality.
8432b17786SJohn-Mark GurneyThe program is executed in a spawned child process while the
8532b17786SJohn-Mark Gurney.Nm
8632b17786SJohn-Mark Gurneywaits until it terminates to keep the
8732b17786SJohn-Mark Gurney.Ar supervisor_pidfile
8832b17786SJohn-Mark Gurneylocked and removes it after the process exits.
8932b17786SJohn-Mark GurneyThe
9032b17786SJohn-Mark Gurney.Ar supervisor_pidfile
912ad43027SMikolaj Golubowner is the user who runs the
922ad43027SMikolaj Golub.Nm
932ad43027SMikolaj Golubregardless of whether the
94704523b0SGuy Helmer.Fl u
952ad43027SMikolaj Goluboption is used or not.
96b6193c24SMikolaj Golub.It Fl r
97b6193c24SMikolaj GolubSupervise and restart the program if it has been terminated.
98*112bfcf5SConrad Meyer.It Fl t Ar title
99*112bfcf5SConrad MeyerProcess title for the daemon to make it easily identifiable.
100b6193c24SMikolaj Golub.It Fl u Ar user
101b6193c24SMikolaj GolubLogin name of the user to execute the program under.
102b6193c24SMikolaj GolubRequires adequate superuser privileges.
103b6193c24SMikolaj Golub.El
104b6193c24SMikolaj Golub.Pp
105b6193c24SMikolaj GolubIf the
10632b17786SJohn-Mark Gurney.Fl p ,
10732b17786SJohn-Mark Gurney.Fl P
108b6193c24SMikolaj Golubor
109b6193c24SMikolaj Golub.Fl r
110b6193c24SMikolaj Goluboption is specified the program is executed in a spawned child process.
111b6193c24SMikolaj GolubThe
112b6193c24SMikolaj Golub.Nm
11332b17786SJohn-Mark Gurneywaits until it terminates to keep the pid file(s) locked and removes them
114b6193c24SMikolaj Golubafter the process exits or restarts the program.
115b6193c24SMikolaj GolubIn this case if the monitoring
116195fc497SMikolaj Golub.Nm
117195fc497SMikolaj Golubreceives software termination signal (SIGTERM) it forwards it to the
118195fc497SMikolaj Golubspawned process.
11932b17786SJohn-Mark GurneyNormally it will cause the child to exit, remove the pidfile(s)
12032b17786SJohn-Mark Gurneyand then terminate.
12132b17786SJohn-Mark Gurney.Pp
12232b17786SJohn-Mark GurneyThe
12332b17786SJohn-Mark Gurney.Fl P
12432b17786SJohn-Mark Gurneyoption is useful combined with the
12532b17786SJohn-Mark Gurney.Fl r
12632b17786SJohn-Mark Gurneyoption as
12732b17786SJohn-Mark Gurney.Ar supervisor_pidfile
12832b17786SJohn-Mark Gurneycontains the ID of the supervisor
129*112bfcf5SConrad Meyernot the child.
130*112bfcf5SConrad MeyerThis is especially important if you use
13132b17786SJohn-Mark Gurney.Fl r
13232b17786SJohn-Mark Gurneyin an rc script as the
13332b17786SJohn-Mark Gurney.Fl p
13432b17786SJohn-Mark Gurneyoption will give you the child's ID to signal when you attempt to
13532b17786SJohn-Mark Gurneystop the service, causing
13632b17786SJohn-Mark Gurney.Nm
13732b17786SJohn-Mark Gurneyto restart the child.
138a866e170SRuslan Ermilov.Sh EXIT STATUS
139bd06a3ecSMike BarcroftThe
140bd06a3ecSMike Barcroft.Nm
141bd06a3ecSMike Barcroftutility exits 1 if an error is returned by the
142bd06a3ecSMike Barcroft.Xr daemon 3
14332b17786SJohn-Mark Gurneylibrary routine, 2 if
14432b17786SJohn-Mark Gurney.Ar child_pidfile
14532b17786SJohn-Mark Gurneyor
14632b17786SJohn-Mark Gurney.Ar supervisor_pidfile
147c6262cb6SPawel Jakub Dawidekis requested, but cannot be opened, 3 if process is already running (pidfile
148c6262cb6SPawel Jakub Dawidekexists and is locked),
149846be7bdSPoul-Henning Kampotherwise 0.
150a866e170SRuslan Ermilov.Sh DIAGNOSTICS
151bd06a3ecSMike BarcroftIf the command cannot be executed, an error message is displayed on
152bd06a3ecSMike Barcroftstandard error unless the
153bd06a3ecSMike Barcroft.Fl f
154bd06a3ecSMike Barcroftflag is specified.
155bd06a3ecSMike Barcroft.Sh SEE ALSO
15612d7249eSTom Rhodes.Xr setregid 2 ,
15712d7249eSTom Rhodes.Xr setreuid 2 ,
158bd06a3ecSMike Barcroft.Xr daemon 3 ,
159bd06a3ecSMike Barcroft.Xr exec 3 ,
160c6262cb6SPawel Jakub Dawidek.Xr pidfile 3 ,
161bd06a3ecSMike Barcroft.Xr termios 4 ,
162bd06a3ecSMike Barcroft.Xr tty 4
163bd06a3ecSMike Barcroft.Sh HISTORY
164bd06a3ecSMike BarcroftThe
165bd06a3ecSMike Barcroft.Nm
166bd06a3ecSMike Barcroftutility first appeared in
167a7d4e017STom Rhodes.Fx 4.7 .
168