5 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7 # Copyright (c) 2009 Douglas Barton
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 echo "${0##*/} [-v] -l | -r"
40 echo "${0##*/} [-v] <rc.d script> start|stop|etc."
43 echo '-e Show services that are enabled'
44 echo "-R Stop and start enabled $local_startup services"
45 echo "-l List all scripts in /etc/rc.d and $local_startup"
46 echo '-r Show the results of boot time rcorder'
51 while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do
52 case "${COMMAND_LINE_ARGUMENT}" in
62 shift $(( $OPTIND - 1 ))
64 if [ -n "$RESTART" ]; then
66 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
67 skip="$skip -s nojail"
69 [ -n "$local_startup" ] && find_local_scripts_new
70 files=`rcorder ${skip} ${local_rc} 2>/dev/null`
72 for file in `reverse_list ${files}`; do
73 if grep -q ^rcvar $file; then
74 eval `grep ^name= $file`
75 eval `grep ^rcvar $file`
76 if [ -n "$rcvar" ]; then
77 load_rc_config_var ${name} ${rcvar}
79 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop
82 for file in $files; do
83 if grep -q ^rcvar $file; then
84 eval `grep ^name= $file`
85 eval `grep ^rcvar $file`
86 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start
93 if [ -n "$ENABLED" -o -n "$RCORDER" ]; then
96 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
97 skip="$skip -s nojail"
99 [ -n "$local_startup" ] && find_local_scripts_new
100 files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
103 if [ -n "$ENABLED" ]; then
104 for file in $files; do
105 if grep -q ^rcvar $file; then
106 eval `grep ^name= $file`
107 eval `grep ^rcvar $file`
108 if [ -n "$rcvar" ]; then
109 load_rc_config_var ${name} ${rcvar}
111 checkyesno $rcvar 2>/dev/null && echo $file
117 if [ -n "$LIST" ]; then
118 for dir in /etc/rc.d $local_startup; do
119 [ -n "$VERBOSE" ] && echo "From ${dir}:"
120 [ -d ${dir} ] && /bin/ls -1 ${dir}
125 if [ -n "$RCORDER" ]; then
126 for file in $files; do
128 if [ -n "$VERBOSE" ]; then
130 */${early_late_divider})
131 echo '========= Early/Late Divider =========' ;;
138 if [ $# -gt 1 ]; then
147 for dir in /etc/rc.d $local_startup; do
148 if [ -x "$dir/$script" ]; then
149 [ -n "$VERBOSE" ] && echo "$script is located in $dir"
150 exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $*
154 # If the script was not found
155 echo "$script does not exist in /etc/rc.d or the local startup"
156 echo "directories (${local_startup}), or is not executable"