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
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"
87 [ -n "$local_startup" ] && find_local_scripts_new
88 files=`rcorder ${skip} ${local_rc} 2>/dev/null`
90 for file in `reverse_list ${files}`; do
91 if grep -q ^rcvar $file; then
92 eval `grep ^name= $file`
93 eval `grep ^rcvar $file`
94 if [ -n "$rcvar" ]; then
95 load_rc_config_var ${name} ${rcvar}
97 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop
100 for file in $files; do
101 if grep -q ^rcvar $file; then
102 eval `grep ^name= $file`
103 eval `grep ^rcvar $file`
104 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start
111 if [ -n "$ENABLED" -o -n "$RCORDER" ]; then
112 # Copied from /etc/rc
114 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
115 skip="$skip -s nojail"
117 [ -n "$local_startup" ] && find_local_scripts_new
118 files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
121 if [ -n "$ENABLED" ]; then
122 for file in $files; do
123 if grep -q ^rcvar $file; then
124 eval `grep ^name= $file`
125 eval `grep ^rcvar $file`
126 if [ -n "$rcvar" ]; then
127 load_rc_config_var ${name} ${rcvar}
129 checkyesno $rcvar 2>/dev/null && echo $file
135 if [ -n "$LIST" ]; then
136 for dir in /etc/rc.d $local_startup; do
137 [ -n "$VERBOSE" ] && echo "From ${dir}:"
138 [ -d ${dir} ] && /bin/ls -1 ${dir}
143 if [ -n "$RCORDER" ]; then
144 for file in $files; do
146 if [ -n "$VERBOSE" ]; then
148 */${early_late_divider})
149 echo '========= Early/Late Divider =========' ;;
156 if [ $# -gt 1 ]; then
165 for dir in /etc/rc.d $local_startup; do
166 if [ -x "$dir/$script" ]; then
167 [ -n "$VERBOSE" ] && echo "$script is located in $dir"
168 exec env -i -L 0/daemon HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin "$dir/$script" "$@"
172 # If the script was not found
173 echo "$script does not exist in /etc/rc.d or the local startup"
174 echo "directories (${local_startup}), or is not executable"