xref: /openbsd/share/man/man8/rc.d.8 (revision 09467b48)
1.\"	$OpenBSD: rc.d.8,v 1.35 2019/08/27 20:05:02 awolk Exp $
2.\"
3.\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\"
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd $Mdocdate: August 27 2019 $
28.Dt RC.D 8
29.Os
30.Sh NAME
31.Nm rc.d
32.Nd daemon control scripts
33.Sh SYNOPSIS
34.Nm /etc/rc.d/ Ns Ar daemon
35.Op Fl df
36.Ar action
37.Sh DESCRIPTION
38The
39.Pa /etc/rc.d
40directory contains shell scripts to start, stop, and reconfigure daemon
41programs
42.Pq Dq services .
43.Pp
44Services installed from
45.Xr packages 7
46may be started at boot time in the order specified by the
47.Va pkg_scripts
48variable from
49.Xr rc.conf 8 ;
50the order will be reversed during shutdown.
51Services comprising
52.Ox
53base are started by
54.Xr rc 8 .
55.Pp
56The options are as follows:
57.Bl -tag -width Ds
58.It Fl d
59Setting this option will print the function names as they are called
60and prevent the
61.Xr rc.subr 8
62framework from redirecting stdout and stderr to /dev/null.
63This is used to allow debugging of failed
64.Ar actions .
65.It Fl f
66This option only affects the
67.Cm start
68action.
69It will forcibly start the daemon whatever value
70.Va daemon_flags
71is set to.
72If
73.Va daemon_flags
74is set to
75.Dq NO ,
76execution will continue with the script's own defaults unless other
77flags are specified.
78.El
79.Pp
80Each such script responds to the following
81.Ar actions :
82.Pp
83.Bl -tag -width restart -offset indent -compact
84.It Cm start
85Start the service, if not already running.
86.It Cm stop
87Stop the service.
88.It Cm reload
89Tell the daemon to reload its configuration.
90.It Cm restart
91Perform a stop, then a start.
92.It Cm check
93Return 0 if the daemon is running or 1 if it is not.
94.El
95.Sh ENVIRONMENT
96Daemon control scripts use a fixed number of
97.Xr sh 1
98variables when starting a daemon.
99The following can be overridden by site-specific values provided in
100.Xr rc.conf.local 8 :
101.Bl -tag -width daemon_timeout -offset indent
102.It Ar daemon Ns _flags
103Additional arguments to call the daemon with.
104These will be appended to any mandatory arguments already contained in the
105.Va daemon
106variable defined in the control script.
107If
108.Ar daemon Ns _flags
109is set to
110.Dq NO ,
111it will prevent the daemon from starting even when listed in
112.Va pkg_scripts .
113.It Ar daemon Ns _rtable
114Routing table to run the daemon under, using
115.Xr route 8 .
116.It Ar daemon Ns _timeout
117Maximum time in seconds to wait for the
118.Cm start ,
119.Cm stop
120and
121.Cm reload
122actions to return.
123This is only guaranteed with the default
124.Ic rc_start ,
125.Ic rc_stop
126and
127.Ic rc_reload
128functions.
129.It Ar daemon Ns _user
130User to run the daemon as, using
131.Xr su 1 .
132.El
133.Pp
134To obtain the actual variable names, replace
135.Ar daemon
136with the name of the script.
137For example, postgres is managed through
138.Pa /etc/rc.d/postgresql :
139.Pp
140.Dl daemon_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile
141.Pp
142To override this and increase the debug log level (keeping the existing
143flags), define the following in
144.Xr rc.conf.local 8 :
145.Pp
146.Dl postgresql_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile -d 5
147.Pp
148Each script may define its own defaults, as explained in
149.Xr rc.subr 8 .
150.Pp
151.Va daemon_class
152is a special read-only variable.
153It is set to
154.Dq daemon
155unless there is a login class configured in
156.Xr login.conf 5
157with the same name as the
158.Nm rc.d
159script itself,
160in which case it will be set to that login class.
161This allows setting many initial process properties, for example
162environment variables, scheduling priority, and process limits
163such as maximum memory use and number of files.
164.Sh FILES
165.Bl -tag -width Ds
166.It Pa /etc/rc.d/
167Directory containing daemon control scripts.
168.It Pa /etc/rc.d/rc.subr
169Functions and variables used by
170.Nm rc.d
171scripts.
172.It Pa /var/run/rc.d/
173Directory containing files recording the variables of currently running daemons.
174Some are informational and some are for matching daemons using
175.Xr pgrep 1
176and
177.Xr pkill 1 .
178.El
179.Sh SEE ALSO
180.Xr rc 8 ,
181.Xr rc.conf 8 ,
182.Xr rc.subr 8 ,
183.Xr rcctl 8
184.Sh HISTORY
185The
186.Pa /etc/rc.d
187directory
188first appeared in
189.Ox 4.9 .
190