xref: /openbsd-src/share/man/man8/rc.d.8 (revision 5a38ef86d0b61900239c7913d24a05e7b88a58f0)
1.\"	$OpenBSD: rc.d.8,v 1.37 2021/11/09 11:43:47 kn 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: November 9 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
42.Xr ksh 1
43scripts to start, stop, and reconfigure daemon
44programs
45.Pq Dq services .
46.Pp
47Services installed from
48.Xr packages 7
49may be started at boot time in the order specified by the
50.Va pkg_scripts
51variable from
52.Xr rc.conf 8 ;
53the order will be reversed during shutdown.
54Services comprising
55.Ox
56base are started by
57.Xr rc 8 .
58.Pp
59The options are as follows:
60.Bl -tag -width Ds
61.It Fl d
62Setting this option will print the function names as they are called
63and prevent the
64.Xr rc.subr 8
65framework from redirecting stdout and stderr to /dev/null.
66This is used to allow debugging of failed
67.Ar actions .
68.It Fl f
69This option only affects the
70.Cm start
71action.
72It will forcibly start the daemon whatever value
73.Va daemon_flags
74is set to.
75If
76.Va daemon_flags
77is set to
78.Dq NO ,
79execution will continue with the script's own defaults unless other
80flags are specified.
81.El
82.Pp
83Each such script responds to the following
84.Ar actions :
85.Pp
86.Bl -tag -width restart -offset indent -compact
87.It Cm start
88Start the service, if not already running.
89.It Cm stop
90Stop the service.
91.It Cm reload
92Tell the daemon to reload its configuration.
93.It Cm restart
94Perform a stop, then a start.
95.It Cm check
96Return 0 if the daemon is running or 1 if it is not.
97.El
98.Sh ENVIRONMENT
99Daemon control scripts use a fixed number of
100.Xr ksh 1
101variables when starting a daemon.
102The following can be overridden by site-specific values provided in
103.Xr rc.conf.local 8 :
104.Bl -tag -width daemon_timeout -offset indent
105.It Ar daemon Ns _flags
106Additional arguments to call the daemon with.
107These will be appended to any mandatory arguments already contained in the
108.Va daemon
109variable defined in the control script.
110If
111.Ar daemon Ns _flags
112is set to
113.Dq NO ,
114it will prevent the daemon from starting even when listed in
115.Va pkg_scripts .
116.It Ar daemon Ns _logger
117Redirect standard output and error to
118.Xr logger 1
119using the configured priority (e.g. "daemon.info").
120.It Ar daemon Ns _rtable
121Routing table to run the daemon under, using
122.Xr route 8 .
123.It Ar daemon Ns _timeout
124Maximum time in seconds to wait for the
125.Cm start ,
126.Cm stop
127and
128.Cm reload
129actions to return.
130This is only guaranteed with the default
131.Ic rc_start ,
132.Ic rc_stop
133and
134.Ic rc_reload
135functions.
136.It Ar daemon Ns _user
137User to run the daemon as, using
138.Xr su 1 .
139.El
140.Pp
141To obtain the actual variable names, replace
142.Ar daemon
143with the name of the script.
144For example, postgres is managed through
145.Pa /etc/rc.d/postgresql :
146.Pp
147.Dl daemon_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile
148.Pp
149To override this and increase the debug log level (keeping the existing
150flags), define the following in
151.Xr rc.conf.local 8 :
152.Pp
153.Dl postgresql_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile -d 5
154.Pp
155Each script may define its own defaults, as explained in
156.Xr rc.subr 8 .
157.Pp
158.Va daemon_class
159is a special read-only variable.
160It is set to
161.Dq daemon
162unless there is a login class configured in
163.Xr login.conf 5
164with the same name as the
165.Nm rc.d
166script itself,
167in which case it will be set to that login class.
168This allows setting many initial process properties, for example
169environment variables, scheduling priority, and process limits
170such as maximum memory use and number of files.
171.Sh FILES
172.Bl -tag -width Ds
173.It Pa /etc/rc.d/
174Directory containing daemon control scripts.
175.It Pa /etc/rc.d/rc.subr
176Functions and variables used by
177.Nm rc.d
178scripts.
179.It Pa /var/run/rc.d/
180Directory containing files recording the variables of currently running daemons.
181Some are informational and some are for matching daemons using
182.Xr pgrep 1
183and
184.Xr pkill 1 .
185.El
186.Sh SEE ALSO
187.Xr ksh 1 ,
188.Xr rc 8 ,
189.Xr rc.conf 8 ,
190.Xr rc.subr 8 ,
191.Xr rcctl 8
192.Sh HISTORY
193The
194.Pa /etc/rc.d
195directory
196first appeared in
197.Ox 4.9 .
198