5 # Copyright (c) 2009 Douglas Barton
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
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.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 echo "${0##*/} [-v] -l | -r"
38 echo "${0##*/} [-v] <rc.d script> start|stop|etc."
41 echo '-e Show services that are enabled'
42 echo "-R Stop and start enabled $local_startup services"
43 echo "-l List all scripts in /etc/rc.d and $local_startup"
44 echo '-r Show the results of boot time rcorder'
49 while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do
50 case "${COMMAND_LINE_ARGUMENT}" in
60 shift $(( $OPTIND - 1 ))
62 if [ -n "$RESTART" ]; then
64 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
65 skip="$skip -s nojail"
67 [ -n "$local_startup" ] && find_local_scripts_new
68 files=`rcorder ${skip} ${local_rc} 2>/dev/null`
70 for file in `reverse_list ${files}`; do
71 if grep -q ^rcvar $file; then
72 eval `grep ^name= $file`
73 eval `grep ^rcvar $file`
74 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop
77 for file in $files; do
78 if grep -q ^rcvar $file; then
79 eval `grep ^name= $file`
80 eval `grep ^rcvar $file`
81 checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start
88 if [ -n "$ENABLED" -o -n "$RCORDER" ]; then
91 if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
92 skip="$skip -s nojail"
94 [ -n "$local_startup" ] && find_local_scripts_new
95 files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
98 if [ -n "$ENABLED" ]; then
99 for file in $files; do
100 if grep -q ^rcvar $file; then
101 eval `grep ^name= $file`
102 eval `grep ^rcvar $file`
103 checkyesno $rcvar 2>/dev/null && echo $file
109 if [ -n "$LIST" ]; then
110 for dir in /etc/rc.d $local_startup; do
111 [ -n "$VERBOSE" ] && echo "From ${dir}:"
112 [ -d ${dir} ] && /bin/ls -1 ${dir}
117 if [ -n "$RCORDER" ]; then
118 for file in $files; do
120 if [ -n "$VERBOSE" ]; then
122 */${early_late_divider})
123 echo '========= Early/Late Divider =========' ;;
130 if [ $# -gt 1 ]; then
139 for dir in /etc/rc.d $local_startup; do
140 if [ -x "$dir/$script" ]; then
141 [ -n "$VERBOSE" ] && echo "$script is located in $dir"
142 exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $*
146 # If the script was not found
147 echo "$script does not exist in /etc/rc.d or the local startup"
148 echo "directories (${local_startup})"