1.\" $OpenBSD: rc.d.8,v 1.40 2022/09/02 22:11:57 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: September 2 2022 $ 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 configtest -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.It Cm configtest 98Check that the daemon configuration is valid. 99.El 100.Sh ENVIRONMENT 101Daemon control scripts use a fixed number of 102.Xr ksh 1 103variables when starting a daemon. 104The following can be overridden by site-specific values provided in 105.Xr rc.conf.local 8 : 106.Bl -tag -width daemon_timeout -offset indent 107.It Ar daemon Ns _execdir 108Run daemon from the specified directory. 109.It Ar daemon Ns _flags 110Additional arguments to call the daemon with. 111These will be appended to any mandatory arguments already contained in the 112.Va daemon 113variable defined in the control script. 114If 115.Ar daemon Ns _flags 116is set to 117.Dq NO , 118it will prevent the daemon from starting even when listed in 119.Va pkg_scripts . 120.It Ar daemon Ns _logger 121Redirect standard output and error to 122.Xr logger 1 123using the configured priority (e.g. "daemon.info"). 124.It Ar daemon Ns _rtable 125Routing table to run the daemon under, using 126.Xr route 8 . 127.It Ar daemon Ns _timeout 128Maximum time in seconds to wait for the 129.Cm start , 130.Cm stop 131and 132.Cm reload 133actions to return. 134This is only guaranteed with the default 135.Ic rc_start , 136.Ic rc_stop 137and 138.Ic rc_reload 139functions. 140.It Ar daemon Ns _user 141User to run the daemon as, using 142.Xr su 1 . 143.El 144.Pp 145To obtain the actual variable names, replace 146.Ar daemon 147with the name of the script. 148For example, postgres is managed through 149.Pa /etc/rc.d/postgresql : 150.Pp 151.Dl daemon_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile 152.Pp 153To override this and increase the debug log level (keeping the existing 154flags), define the following in 155.Xr rc.conf.local 8 : 156.Pp 157.Dl postgresql_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile -d 5 158.Pp 159Each script may define its own defaults, as explained in 160.Xr rc.subr 8 . 161.Pp 162.Va daemon_class 163is a special read-only variable. 164It is set to 165.Dq daemon 166unless there is a login class configured in 167.Xr login.conf 5 168with the same name as the 169.Nm rc.d 170script itself, 171in which case it will be set to that login class. 172This allows setting many initial process properties, for example 173environment variables, scheduling priority, and process limits 174such as maximum memory use and number of files. 175.Sh FILES 176.Bl -tag -width Ds 177.It Pa /etc/rc.d/ 178Directory containing daemon control scripts. 179.It Pa /etc/rc.d/rc.subr 180Functions and variables used by 181.Nm rc.d 182scripts. 183.It Pa /var/run/rc.d/ 184Directory containing files recording the variables of currently running daemons. 185Some are informational and some are for matching daemons using 186.Xr pgrep 1 187and 188.Xr pkill 1 . 189.El 190.Sh SEE ALSO 191.Xr ksh 1 , 192.Xr rc 8 , 193.Xr rc.conf 8 , 194.Xr rc.subr 8 , 195.Xr rcctl 8 196.Sh HISTORY 197The 198.Pa /etc/rc.d 199directory 200first appeared in 201.Ox 4.9 . 202