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