]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man8/rc.subr.8
Merge llvm-project release/15.x llvmorg-15.0.2-10-gf3c5289e7846
[FreeBSD/FreeBSD.git] / share / man / man8 / rc.subr.8
1 .\"     $NetBSD: rc.subr.8,v 1.12 2004/01/06 00:52:24 lukem Exp $
2 .\"
3 .\" Copyright (c) 2002-2004 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Luke Mewburn.
8 .\"
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\"
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
29 .\"
30 .\" $FreeBSD$
31 .\"
32 .Dd August 16, 2022
33 .Dt RC.SUBR 8
34 .Os
35 .Sh NAME
36 .Nm rc.subr
37 .Nd functions used by system shell scripts
38 .Sh SYNOPSIS
39 .Bl -item -compact
40 .It
41 .Ic .\& Pa /etc/rc.subr
42 .Pp
43 .It
44 .Ic backup_file Ar action Ar file Ar current Ar backup
45 .It
46 .Ic checkyesno Ar var
47 .It
48 .Ic check_pidfile Ar pidfile Ar procname Op Ar interpreter
49 .It
50 .Ic check_process Ar procname Op Ar interpreter
51 .It
52 .Ic debug Ar message
53 .It
54 .Ic err Ar exitval Ar message
55 .It
56 .Ic force_depend Ar name
57 .It
58 .Ic info Ar message
59 .It
60 .Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file
61 .It
62 .Ic load_rc_config Op Ar service
63 .It
64 .Ic load_rc_config_var Ar name Ar var
65 .It
66 .Ic mount_critical_filesystems Ar type
67 .It
68 .Ic rc_usage Ar command ...
69 .It
70 .Ic reverse_list Ar item ...
71 .It
72 .Ic run_rc_command Ar argument
73 .It
74 .Ic run_rc_script Ar file Ar argument
75 .It
76 .Ic startmsg Oo Fl n Oc Ar message
77 .It
78 .Ic wait_for_pids Op Ar pid ...
79 .It
80 .Ic warn Ar message
81 .El
82 .Sh DESCRIPTION
83 The
84 .Nm
85 script
86 contains commonly used shell script functions and variable
87 definitions which are used by various scripts such as
88 .Xr rc 8 .
89 Scripts required by ports in
90 .Pa /usr/local/etc/rc.d
91 will also eventually
92 be rewritten to make use of it.
93 .Pp
94 The
95 .Nm
96 functions were mostly imported from
97 .Nx .
98 .Pp
99 They are accessed by sourcing
100 .Pa /etc/rc.subr
101 into the current shell.
102 .Pp
103 The following shell functions are available:
104 .Bl -tag -width 4n
105 .It Ic backup_file Ar action file current backup
106 Make a backup copy of
107 .Ar file
108 into
109 .Ar current .
110 Save the previous version of
111 .Ar current
112 as
113 .Ar backup .
114 .Pp
115 The
116 .Ar action
117 argument
118 may be one of the following:
119 .Bl -tag -width ".Cm remove"
120 .It Cm add
121 .Ar file
122 is now being backed up by or possibly re-entered into this backup mechanism.
123 .Ar current
124 is created.
125 .It Cm update
126 .Ar file
127 has changed and needs to be backed up.
128 If
129 .Ar current
130 exists, it is copied to
131 .Ar backup
132 and then
133 .Ar file
134 is copied to
135 .Ar current .
136 .It Cm remove
137 .Ar file
138 is no longer being tracked by this backup mechanism.
139 .Ar current
140 is moved to
141 .Ar backup .
142 .El
143 .It Ic checkyesno Ar var
144 Return 0 if
145 .Ar var
146 is defined to
147 .Dq Li YES ,
148 .Dq Li TRUE ,
149 .Dq Li ON ,
150 or
151 .Ql 1 .
152 Return 1 if
153 .Ar var
154 is defined to
155 .Dq Li NO ,
156 .Dq Li FALSE ,
157 .Dq Li OFF ,
158 or
159 .Ql 0 .
160 Otherwise, warn that
161 .Ar var
162 is not set correctly.
163 The values are case insensitive.
164 .Em Note :
165 .Ar var
166 should be a variable name, not its value;
167 .Ic checkyesno
168 will expand the variable by itself.
169 .It Ic check_pidfile Ar pidfile procname Op Ar interpreter
170 Parses the first word of the first line of
171 .Ar pidfile
172 for a PID, and ensures that the process with that PID
173 is running and its first argument matches
174 .Ar procname .
175 Prints the matching PID if successful, otherwise nothing.
176 If
177 .Ar interpreter
178 is provided, parse the first line of
179 .Ar procname ,
180 ensure that the line is of the form:
181 .Pp
182 .Dl "#! interpreter [...]"
183 .Pp
184 and use
185 .Ar interpreter
186 with its optional arguments and
187 .Ar procname
188 appended as the process string to search for.
189 .It Ic check_process Ar procname Op Ar interpreter
190 Prints the PIDs of any processes that are running with a first
191 argument that matches
192 .Ar procname .
193 .Ar interpreter
194 is handled as per
195 .Ic check_pidfile .
196 .It Ic debug Ar message
197 Display a debugging message to
198 .Va stderr ,
199 log it to the system log using
200 .Xr logger 1 ,
201 and
202 return to the caller.
203 The error message consists of the script name
204 (from
205 .Va $0 ) ,
206 followed by
207 .Dq Li ": DEBUG: " ,
208 and then
209 .Ar message .
210 This function is intended to be used by developers
211 as an aid to debugging scripts.
212 It can be turned on or off
213 by the
214 .Xr rc.conf 5
215 variable
216 .Va rc_debug .
217 .It Ic err Ar exitval message
218 Display an error message to
219 .Va stderr ,
220 log it to the system log
221 using
222 .Xr logger 1 ,
223 and
224 .Ic exit
225 with an exit value of
226 .Ar exitval .
227 The error message consists of the script name
228 (from
229 .Va $0 ) ,
230 followed by
231 .Dq Li ": ERROR: " ,
232 and then
233 .Ar message .
234 .It Ic force_depend Ar name
235 Output an advisory message and force the
236 .Ar name
237 service to start.
238 The
239 .Ar name
240 argument is the
241 .Xr basename 1
242 component of the path to the script located at
243 .Pa /etc/rc.d
244 (scripts stored in other locations such as
245 .Pa /usr/local/etc/rc.d
246 cannot be controlled with
247 .Ic force_depend
248 currently).
249 If the script fails for any reason it will output a warning
250 and return with a return value of 1.
251 If it was successful
252 it will return 0.
253 .It Ic info Ar message
254 Display an informational message to
255 .Va stdout ,
256 and log it to the system log using
257 .Xr logger 1 .
258 The message consists of the script name
259 (from
260 .Va $0 ) ,
261 followed by
262 .Dq Li ": INFO: " ,
263 and then
264 .Ar message .
265 The display of this informational output can be
266 turned on or off by the
267 .Xr rc.conf 5
268 variable
269 .Va rc_info .
270 .It Ic load_kld Oo Fl e Ar regex Oc Oo Fl m Ar module Oc Ar file
271 Load
272 .Ar file
273 as a kernel module unless it is already loaded.
274 For the purpose of checking the module status,
275 either the exact module name can be specified using
276 .Fl m ,
277 or an
278 .Xr egrep 1
279 regular expression matching the module name can be supplied via
280 .Fl e .
281 By default, the module is assumed to have the same name as
282 .Ar file ,
283 which is not always the case.
284 .It Ic load_rc_config Op Ar service
285 Source in the configuration file(s) for
286 .Ar service .
287 If no
288 .Ar service
289 is specified,
290 only the global configuration file(s) will be loaded.
291 First,
292 .Pa /etc/rc.conf
293 is sourced if it has not yet been read in.
294 Then,
295 .Pa /etc/rc.conf.d/ Ns Ar service
296 is sourced if it is an existing file.
297 The latter may also contain other variable assignments to override
298 .Ic run_rc_command
299 arguments defined by the calling script, to provide an easy
300 mechanism for an administrator to override the behaviour of a given
301 .Xr rc.d 8
302 script without requiring the editing of that script.
303 .It Ic load_rc_config_var Ar name Ar var
304 Read the
305 .Xr rc.conf 5
306 variable
307 .Ar var
308 for
309 .Ar name
310 and set in the current shell, using
311 .Ic load_rc_config
312 in a sub-shell to prevent unwanted side effects from other variable
313 assignments.
314 .It Ic mount_critical_filesystems Ar type
315 Go through a list of critical file systems,
316 as found in the
317 .Xr rc.conf 5
318 variable
319 .Va critical_filesystems_ Ns Ar type ,
320 mounting each one that
321 is not currently mounted.
322 .It Ic rc_usage Ar command ...
323 Print a usage message for
324 .Va $0 ,
325 with
326 .Ar commands
327 being the list of valid arguments
328 prefixed by
329 .Sm off
330 .Dq Bq Li fast | force | one | quiet .
331 .Sm on
332 .It Ic reverse_list Ar item ...
333 Print the list of
334 .Ar items
335 in reverse order.
336 .It Ic run_rc_command Ar argument
337 Run the
338 .Ar argument
339 method for the current
340 .Xr rc.d 8
341 script, based on the settings of various shell variables.
342 .Ic run_rc_command
343 is extremely flexible, and allows fully functional
344 .Xr rc.d 8
345 scripts to be implemented in a small amount of shell code.
346 .Pp
347 .Ar argument
348 is searched for in the list of supported commands, which may be one
349 of:
350 .Bl -tag -width ".Cm restart" -offset indent
351 .It Cm start
352 Start the service.
353 This should check that the service is to be started as specified by
354 .Xr rc.conf 5 .
355 Also checks if the service is already running and refuses to start if
356 it is.
357 This latter check is not performed by standard
358 .Fx
359 scripts if the system is starting directly to multi-user mode, to
360 speed up the boot process.
361 .It Cm stop
362 If the service is to be started as specified by
363 .Xr rc.conf 5 ,
364 stop the service.
365 This should check that the service is running and complain if it is not.
366 .It Cm restart
367 Perform a
368 .Cm stop
369 then a
370 .Cm start .
371 Defaults to displaying the process ID of the program (if running).
372 .It Cm enabled
373 Return 0 if the service is enabled and 1 if it is not.
374 This command does not print anything.
375 .It Cm rcvar
376 Display which
377 .Xr rc.conf 5
378 variables are used to control the startup of the service (if any).
379 .El
380 .Pp
381 If
382 .Va pidfile
383 or
384 .Va procname
385 is set, also support:
386 .Bl -tag -width ".Cm restart" -offset indent
387 .It Cm poll
388 Wait for the command to exit.
389 .It Cm status
390 Show the status of the process.
391 .El
392 .Pp
393 Other supported commands are listed in the optional variable
394 .Va extra_commands .
395 .Pp
396 .Ar argument
397 may have one of the following prefixes which alters its operation:
398 .Bl -tag -width ".Li force" -offset indent
399 .It Li fast
400 Skip the check for an existing running process,
401 and sets
402 .Va rc_fast Ns = Ns Li YES .
403 .It Li force
404 Skip the checks for
405 .Va rcvar
406 being set to
407 .Dq Li YES ,
408 and sets
409 .Va rc_force Ns = Ns Li YES .
410 This ignores
411 .Ar argument Ns Va _precmd
412 returning non-zero, and ignores any of the
413 .Va required_*
414 tests failing, and always returns a zero exit status.
415 .It Li one
416 Skip the checks for
417 .Va rcvar
418 being set to
419 .Dq Li YES ,
420 but performs all the other prerequisite tests.
421 .It Li quiet
422 Inhibits some verbose diagnostics.
423 Currently, this includes messages
424 .Qq Starting ${name}
425 (as checked by
426 .Ic check_startmsgs
427 inside
428 .Nm )
429 and errors about usage of services that are not enabled in
430 .Xr rc.conf 5 .
431 This prefix also sets
432 .Va rc_quiet Ns = Ns Li YES .
433 .Em Note :
434 .Va rc_quiet
435 is not intended to completely mask all debug and warning messages,
436 but only certain small classes of them.
437 .El
438 .Pp
439 .Ic run_rc_command
440 uses the following shell variables to control its behaviour.
441 Unless otherwise stated, these are optional.
442 .Bl -tag -width ".Va procname" -offset indent
443 .It Va name
444 The name of this script.
445 This is not optional.
446 .It Va rcvar
447 The value of
448 .Va rcvar
449 is checked with
450 .Ic checkyesno
451 to determine if this method should be run.
452 .It Va command
453 Full path to the command.
454 Not required if
455 .Ar argument Ns Va _cmd
456 is defined for each supported keyword.
457 Can be overridden by
458 .Va ${name}_program .
459 .It Va command_args
460 Optional arguments and/or shell directives for
461 .Va command .
462 .It Va command_interpreter
463 .Va command
464 is started with:
465 .Pp
466 .Dl "#! command_interpreter [...]"
467 .Pp
468 which results in its
469 .Xr ps 1
470 command being:
471 .Pp
472 .Dl "command_interpreter [...] command"
473 .Pp
474 so use that string to find the PID(s) of the running command
475 rather than
476 .Va command .
477 .It Va extra_commands
478 Extra commands/keywords/arguments supported.
479 .It Va pidfile
480 Path to PID file.
481 Used to determine the PID(s) of the running command.
482 If
483 .Va pidfile
484 is set, use:
485 .Pp
486 .Dl "check_pidfile $pidfile $procname"
487 .Pp
488 to find the PID.
489 Otherwise, if
490 .Va command
491 is set, use:
492 .Pp
493 .Dl "check_process $procname"
494 .Pp
495 to find the PID.
496 .It Va procname
497 Process name to check for.
498 Defaults to the value of
499 .Va command .
500 .It Va required_dirs
501 Check for the existence of the listed directories
502 before running the
503 .Cm start
504 method.
505 The list is checked before running
506 .Va start_precmd .
507 .It Va required_files
508 Check for the readability of the listed files
509 before running the
510 .Cm start
511 method.
512 The list is checked before running
513 .Va start_precmd .
514 .It Va required_modules
515 Ensure that the listed kernel modules are loaded
516 before running the
517 .Cm start
518 method.
519 The list is checked after running
520 .Va start_precmd .
521 This is done after invoking the commands from
522 .Va start_precmd
523 so that the missing modules are not loaded in vain
524 if the preliminary commands indicate a error condition.
525 A word in the list can have an optional
526 .Dq Li \&: Ns Ar modname
527 or
528 .Dq Li ~ Ns Ar pattern
529 suffix.
530 The
531 .Ar modname
532 or
533 .Ar pattern
534 parameter is passed to
535 .Ic load_kld
536 through a
537 .Fl m
538 or
539 .Fl e
540 option, respectively.
541 See the description of
542 .Ic load_kld
543 in this document for details.
544 .It Va required_vars
545 Perform
546 .Ic checkyesno
547 on each of the list variables
548 before running the
549 .Cm start
550 method.
551 The list is checked after running
552 .Va start_precmd .
553 .It Va ${name}_chdir
554 Directory to
555 .Ic cd
556 to before running
557 .Va command ,
558 if
559 .Va ${name}_chroot
560 is not provided.
561 .It Va ${name}_chroot
562 Directory to
563 .Xr chroot 8
564 to before running
565 .Va command .
566 Only supported after
567 .Pa /usr
568 is mounted.
569 .It Va ${name}_env
570 A list of environment variables to run
571 .Va command
572 with.
573 Those variables will be passed as arguments to the
574 .Xr env 1
575 utility unless
576 .Ar argument Ns Va _cmd
577 is defined.
578 In that case the contents of
579 .Va ${name}_env
580 will be exported via the
581 .Xr export 1
582 builtin of
583 .Xr sh 1 ,
584 which puts some limitations on the names of variables
585 (e.g., a variable name may not start with a digit).
586 .It Va ${name}_env_file
587 A file to source for environmental variables to run
588 .Va command
589 with.
590 .Em Note :
591 all the variables which are being assigned in this file are going
592 to be exported into the environment of
593 .Va command .
594 .It Va ${name}_fib
595 FIB
596 .Pa Routing Table
597 number to run
598 .Va command
599 with.
600 See
601 .Xr setfib 1
602 for more details.
603 .It Va ${name}_flags
604 Arguments to call
605 .Va command
606 with.
607 This is usually set in
608 .Xr rc.conf 5 ,
609 and not in the
610 .Xr rc.d 8
611 script.
612 The environment variable
613 .Sq Ev flags
614 can be used to override this.
615 .It Va ${name}_nice
616 .Xr nice 1
617 level to run
618 .Va command
619 as.
620 Only supported after
621 .Pa /usr
622 is mounted.
623 .It Va ${name}_limits
624 Resource limits to apply to
625 .Va command .
626 This will be passed as arguments to the
627 .Xr limits 1
628 utility.
629 By default, the resource limits are based on the login class defined in
630 .Va ${name}_login_class .
631 .It Va ${name}_login_class
632 Login class to use with
633 .Va ${name}_limits .
634 Defaults to
635 .Dq Li daemon .
636 .It Va ${name}_oomprotect
637 .Xr protect 1
638 .Va command
639 from being killed when swap space is exhausted.
640 If
641 .Dq Li YES
642 is used, no child processes are protected.
643 If
644 .Dq Li ALL ,
645 protect all child processes.
646 .It Va ${name}_program
647 Full path to the command.
648 Overrides
649 .Va command
650 if both are set, but has no effect if
651 .Va command
652 is unset.
653 As a rule,
654 .Va command
655 should be set in the script while
656 .Va ${name}_program
657 should be set in
658 .Xr rc.conf 5 .
659 .It Va ${name}_user
660 User to run
661 .Va command
662 as, using
663 .Xr chroot 8
664 if
665 .Va ${name}_chroot
666 is set, otherwise
667 uses
668 .Xr su 1 .
669 Only supported after
670 .Pa /usr
671 is mounted.
672 .It Va ${name}_group
673 Group to run the chrooted
674 .Va command
675 as.
676 .It Va ${name}_groups
677 Comma separated list of supplementary groups to run the chrooted
678 .Va command
679 with.
680 .It Va ${name}_prepend
681 Commands to be prepended to
682 .Va command .
683 This is a generic version of
684 .Va ${name}_env ,
685 .Va ${name}_fib ,
686 or
687 .Va ${name}_nice .
688 .It Va ${name}_setup
689 Command to be run prior to
690 .Va command .
691 .It Ar argument Ns Va _cmd
692 Shell commands which override the default method for
693 .Ar argument .
694 .It Ar argument Ns Va _precmd
695 Shell commands to run just before running
696 .Ar argument Ns Va _cmd
697 or the default method for
698 .Ar argument .
699 If this returns a non-zero exit code, the main method is not performed.
700 If the default method is being executed, this check is performed after
701 the
702 .Va required_*
703 checks and process (non-)existence checks.
704 .It Ar argument Ns Va _postcmd
705 Shell commands to run if running
706 .Ar argument Ns Va _cmd
707 or the default method for
708 .Ar argument
709 returned a zero exit code.
710 .It Va sig_stop
711 Signal to send the processes to stop in the default
712 .Cm stop
713 method.
714 Defaults to
715 .Dv SIGTERM .
716 .It Va sig_reload
717 Signal to send the processes to reload in the default
718 .Cm reload
719 method.
720 Defaults to
721 .Dv SIGHUP .
722 .El
723 .Pp
724 For a given method
725 .Ar argument ,
726 if
727 .Ar argument Ns Va _cmd
728 is not defined, then a default method is provided by
729 .Ic run_rc_command :
730 .Bl -tag -width ".Sy Argument" -offset indent
731 .It Sy Argument
732 .Sy Default method
733 .It Cm start
734 If
735 .Va command
736 is not running and
737 .Ic checkyesno Va rcvar
738 succeeds, start
739 .Va command .
740 .It Cm stop
741 Determine the PIDs of
742 .Va command
743 with
744 .Ic check_pidfile
745 or
746 .Ic check_process
747 (as appropriate),
748 .Ic kill Va sig_stop
749 those PIDs, and run
750 .Ic wait_for_pids
751 on those PIDs.
752 .It Cm reload
753 Similar to
754 .Cm stop ,
755 except that it uses
756 .Va sig_reload
757 instead, and does not run
758 .Ic wait_for_pids .
759 Another difference from
760 .Cm stop
761 is that
762 .Cm reload
763 is not provided by default.
764 It can be enabled via
765 .Va extra_commands
766 if appropriate:
767 .Pp
768 .Dl "extra_commands=reload"
769 .It Cm restart
770 Runs the
771 .Cm stop
772 method, then the
773 .Cm start
774 method.
775 .It Cm status
776 Show the PID of
777 .Va command ,
778 or some other script specific status operation.
779 .It Cm poll
780 Wait for
781 .Va command
782 to exit.
783 .It Cm rcvar
784 Display which
785 .Xr rc.conf 5
786 variable is used (if any).
787 This method always works, even if the appropriate
788 .Xr rc.conf 5
789 variable is set to
790 .Dq Li NO .
791 .El
792 .Pp
793 The following variables are available to the methods
794 (such as
795 .Ar argument Ns Va _cmd )
796 as well as after
797 .Ic run_rc_command
798 has completed:
799 .Bl -tag -width ".Va rc_service" -offset indent
800 .It Va rc_arg
801 Argument provided to
802 .Ic run_rc_command ,
803 after fast and force processing has been performed.
804 .It Va rc_flags
805 Flags to start the default command with.
806 Defaults to
807 .Va ${name}_flags ,
808 unless overridden by the environment variable
809 .Sq Ev flags .
810 This variable may be changed by the
811 .Ar argument Ns Va _precmd
812 method.
813 .It Va rc_service
814 Path to the service script being executed, in case it needs to re-invoke itself.
815 .It Va rc_pid
816 PID of
817 .Va command
818 (if appropriate).
819 .It Va rc_fast
820 Not empty if
821 .Dq Li fast
822 prefix was used.
823 .It Va rc_force
824 Not empty if
825 .Dq Li force
826 prefix was used.
827 .El
828 .It Ic run_rc_script Ar file argument
829 Start the script
830 .Ar file
831 with an argument of
832 .Ar argument ,
833 and handle the return value from the script.
834 .Pp
835 Various shell variables are unset before
836 .Ar file
837 is started:
838 .Bd -ragged -offset indent
839 .Va name ,
840 .Va command ,
841 .Va command_args ,
842 .Va command_interpreter ,
843 .Va extra_commands ,
844 .Va pidfile ,
845 .Va rcvar ,
846 .Va required_dirs ,
847 .Va required_files ,
848 .Va required_vars ,
849 .Ar argument Ns Va _cmd ,
850 .Ar argument Ns Va _precmd .
851 .Ar argument Ns Va _postcmd .
852 .Ed
853 .Pp
854 The startup behaviour of
855 .Ar file
856 depends upon the following checks:
857 .Bl -enum
858 .It
859 If
860 .Ar file
861 ends in
862 .Pa .sh ,
863 it is sourced into the current shell.
864 .It
865 If
866 .Ar file
867 appears to be a backup or scratch file
868 (e.g., with a suffix of
869 .Pa ~ , # , .OLD ,
870 or
871 .Pa .orig ) ,
872 ignore it.
873 .It
874 If
875 .Ar file
876 is not executable, ignore it.
877 .It
878 If the
879 .Xr rc.conf 5
880 variable
881 .Va rc_fast_and_loose
882 is empty,
883 source
884 .Ar file
885 in a sub shell,
886 otherwise source
887 .Ar file
888 into the current shell.
889 .El
890 .It Ic startmsg Oo Fl n Oc Ar message
891 Display a start message to
892 .Va stdout .
893 It should be used instead of
894 .Xr echo 1 .
895 The display of this output can be turned off if the
896 .Xr rc.conf 5
897 variable
898 .Va rc_startmsgs
899 is set to
900 .Dq Li NO .
901 .It Ic stop_boot Op Ar always
902 Prevent booting to multiuser mode.
903 If the
904 .Va autoboot
905 variable is set to
906 .Ql yes
907 (see
908 .Xr rc 8
909 to learn more about
910 .Va autoboot ) ,
911 or
912 .Ic checkyesno Ar always
913 indicates a truth value, then a
914 .Dv SIGTERM
915 signal is sent to the parent
916 process, which is assumed to be
917 .Xr rc 8 .
918 Otherwise, the shell exits with a non-zero status.
919 .It Ic wait_for_pids Op Ar pid ...
920 Wait until all of the provided
921 .Ar pids
922 do not exist any more, printing the list of outstanding
923 .Ar pids
924 every two seconds.
925 .It Ic warn Ar message
926 Display a warning message to
927 .Va stderr
928 and log it to the system log
929 using
930 .Xr logger 1 .
931 The warning message consists of the script name
932 (from
933 .Va $0 ) ,
934 followed by
935 .Dq Li ": WARNING: " ,
936 and then
937 .Ar message .
938 .El
939 .Sh FILES
940 .Bl -tag -width ".Pa /etc/rc.subr" -compact
941 .It Pa /etc/rc.subr
942 The
943 .Nm
944 file resides in
945 .Pa /etc .
946 .El
947 .Sh SEE ALSO
948 .Xr rc.conf 5 ,
949 .Xr rc 8
950 .Sh HISTORY
951 The
952 .Nm
953 script
954 appeared in
955 .Nx 1.3 .
956 The
957 .Xr rc.d 8
958 support functions appeared in
959 .Nx 1.5 .
960 The
961 .Nm
962 script
963 first appeared in
964 .Fx 5.0 .