5 # SPDX-License-Identifier: BSD-2-Clause
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
37 echo "${0##*/} [-j <jail name or id>] -e"
38 echo "${0##*/} [-j <jail name or id>] -R"
39 echo "${0##*/} [-j <jail name or id>] [-v] -l | -r"
40 echo "${0##*/} [-j <jail name or id>] [-v] <rc.d script> start|stop|etc."
43 echo "-j Perform actions within the named jail"
44 echo '-e Show services that are enabled'
45 echo "-R Stop and start enabled $local_startup services"
46 echo "-l List all scripts in /etc/rc.d and $local_startup"
47 echo '-r Show the results of boot time rcorder'
52 while getopts 'j:ehlrRv' COMMAND_LINE_ARGUMENT ; do
53 case "${COMMAND_LINE_ARGUMENT}" in
54 j) JAIL="${OPTARG}" ;;
64 shift $(( $OPTIND - 1 ))
66 if [ -n "${JAIL}" ]; then
67 # We need to rebuild the command line before passing it on.
68 # We do not send the -j argument into the jail.
70 [ -n "${ENABLED}" ] && args="${args} -e"
71 [ -n "${LIST}" ] && args="${args} -l"
72 [ -n "${RCORDER}" ] && args="${args} -r"
73 [ -n "${RESTART}" ] && args="${args} -R"
74 [ -n "${VERBOSE}" ] && args="${args} -v"
76 # Call jexec(8) with the rebuild args and any positional args that
78 /usr/sbin/jexec -l "${JAIL}" /usr/sbin/service $args "$@"
82 if [ -n "$RESTART" ]; then
84 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
85 skip="$skip -s nojail"
86 if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then
87 skip="$skip -s nojailvnet"
90 [ -n "$local_startup" ] && find_local_scripts_new
91 files=`rcorder ${skip} ${local_rc} 2>/dev/null`
93 for file in `reverse_list ${files}`; do
94 if grep -q ^rcvar $file; then
95 eval `grep ^name= $file`
96 eval `grep ^rcvar $file`
97 if [ -n "$rcvar" ]; then
98 load_rc_config_var ${name} ${rcvar}
100 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop
103 for file in $files; do
104 if grep -q ^rcvar $file; then
105 eval `grep ^name= $file`
106 eval `grep ^rcvar $file`
107 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start
114 if [ -n "$ENABLED" -o -n "$RCORDER" ]; then
115 # Copied from /etc/rc
117 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
118 skip="$skip -s nojail"
119 if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then
120 skip="$skip -s nojailvnet"
123 [ -n "$local_startup" ] && find_local_scripts_new
124 files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
127 if [ -n "$ENABLED" ]; then
128 for file in $files; do
129 if grep -q ^rcvar $file; then
130 eval `grep ^name= $file`
131 eval `grep ^rcvar $file`
132 if [ -n "$rcvar" ]; then
133 load_rc_config_var ${name} ${rcvar}
135 checkyesno $rcvar 2>/dev/null && echo $file
141 if [ -n "$LIST" ]; then
142 for dir in /etc/rc.d $local_startup; do
143 [ -n "$VERBOSE" ] && echo "From ${dir}:"
144 [ -d ${dir} ] && /bin/ls -1 ${dir}
149 if [ -n "$RCORDER" ]; then
150 for file in $files; do
152 if [ -n "$VERBOSE" ]; then
154 */${early_late_divider})
155 echo '========= Early/Late Divider =========' ;;
162 if [ $# -gt 1 ]; then
171 for dir in /etc/rc.d $local_startup; do
172 if [ -x "$dir/$script" ]; then
173 [ -n "$VERBOSE" ] && echo "$script is located in $dir"
174 exec env -i -L -/daemon HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin "$dir/$script" "$@"
178 # If the script was not found
179 echo "$script does not exist in /etc/rc.d or the local startup"
180 echo "directories (${local_startup}), or is not executable"