1548a3528SFranco Fichtner#!/bin/sh 2548a3528SFranco Fichtner 3*63cca36dSRobin Hahling# $FreeBSD: head/usr.sbin/service/service.sh 268773 2014-07-16 19:02:30Z dteske $ 4548a3528SFranco Fichtner 5548a3528SFranco Fichtner# Copyright (c) 2009 Douglas Barton 6548a3528SFranco Fichtner# All rights reserved. 7548a3528SFranco Fichtner# 8548a3528SFranco Fichtner# Redistribution and use in source and binary forms, with or without 9548a3528SFranco Fichtner# modification, are permitted provided that the following conditions 10548a3528SFranco Fichtner# are met: 11548a3528SFranco Fichtner# 1. Redistributions of source code must retain the above copyright 12548a3528SFranco Fichtner# notice, this list of conditions and the following disclaimer. 13548a3528SFranco Fichtner# 2. Redistributions in binary form must reproduce the above copyright 14548a3528SFranco Fichtner# notice, this list of conditions and the following disclaimer in the 15548a3528SFranco Fichtner# documentation and/or other materials provided with the distribution. 16548a3528SFranco Fichtner# 17548a3528SFranco Fichtner# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18548a3528SFranco Fichtner# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19548a3528SFranco Fichtner# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20548a3528SFranco Fichtner# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21548a3528SFranco Fichtner# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22548a3528SFranco Fichtner# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23548a3528SFranco Fichtner# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24548a3528SFranco Fichtner# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25548a3528SFranco Fichtner# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26548a3528SFranco Fichtner# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27548a3528SFranco Fichtner# SUCH DAMAGE. 28548a3528SFranco Fichtner 29548a3528SFranco Fichtner. /etc/rc.subr 30548a3528SFranco Fichtnerload_rc_config 'XXX' 31548a3528SFranco Fichtner 32548a3528SFranco Fichtnerusage () { 33548a3528SFranco Fichtner echo '' 34548a3528SFranco Fichtner echo 'Usage:' 35548a3528SFranco Fichtner echo "${0##*/} -e" 36548a3528SFranco Fichtner echo "${0##*/} -R" 37548a3528SFranco Fichtner echo "${0##*/} [-v] -l | -r" 38548a3528SFranco Fichtner echo "${0##*/} [-v] <rc.d script> start|stop|etc." 39548a3528SFranco Fichtner echo "${0##*/} -h" 40548a3528SFranco Fichtner echo '' 41548a3528SFranco Fichtner echo '-e Show services that are enabled' 42548a3528SFranco Fichtner echo "-R Stop and start enabled $local_startup services" 43548a3528SFranco Fichtner echo "-l List all scripts in /etc/rc.d and $local_startup" 44548a3528SFranco Fichtner echo '-r Show the results of boot time rcorder' 45548a3528SFranco Fichtner echo '-v Verbose' 46548a3528SFranco Fichtner echo '' 47548a3528SFranco Fichtner} 48548a3528SFranco Fichtner 49548a3528SFranco Fichtnerwhile getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do 50548a3528SFranco Fichtner case "${COMMAND_LINE_ARGUMENT}" in 51548a3528SFranco Fichtner e) ENABLED=eopt ;; 52548a3528SFranco Fichtner h) usage ; exit 0 ;; 53548a3528SFranco Fichtner l) LIST=lopt ;; 54548a3528SFranco Fichtner r) RCORDER=ropt ;; 55548a3528SFranco Fichtner R) RESTART=Ropt ;; 56548a3528SFranco Fichtner v) VERBOSE=vopt ;; 57548a3528SFranco Fichtner *) usage ; exit 1 ;; 58548a3528SFranco Fichtner esac 59548a3528SFranco Fichtnerdone 60548a3528SFranco Fichtnershift $(( $OPTIND - 1 )) 61548a3528SFranco Fichtner 62548a3528SFranco Fichtnerif [ -n "$RESTART" ]; then 63548a3528SFranco Fichtner skip="-s nostart" 6488b499edSRobin Hahling# if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then 6588b499edSRobin Hahling# skip="$skip -s nojail" 6688b499edSRobin Hahling# fi 67684cb317SRobin Hahling [ -n "$local_startup" ] && find_local_scripts 68548a3528SFranco Fichtner files=`rcorder ${skip} ${local_rc} 2>/dev/null` 69548a3528SFranco Fichtner 70548a3528SFranco Fichtner for file in `reverse_list ${files}`; do 71548a3528SFranco Fichtner if grep -q ^rcvar $file; then 72548a3528SFranco Fichtner eval `grep ^name= $file` 73548a3528SFranco Fichtner eval `grep ^rcvar $file` 74548a3528SFranco Fichtner checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop 75548a3528SFranco Fichtner fi 76548a3528SFranco Fichtner done 77548a3528SFranco Fichtner for file in $files; do 78548a3528SFranco Fichtner if grep -q ^rcvar $file; then 79548a3528SFranco Fichtner eval `grep ^name= $file` 80548a3528SFranco Fichtner eval `grep ^rcvar $file` 81548a3528SFranco Fichtner checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start 82548a3528SFranco Fichtner fi 83548a3528SFranco Fichtner done 84548a3528SFranco Fichtner 85548a3528SFranco Fichtner exit 0 86548a3528SFranco Fichtnerfi 87548a3528SFranco Fichtner 88548a3528SFranco Fichtnerif [ -n "$ENABLED" -o -n "$RCORDER" ]; then 89548a3528SFranco Fichtner # Copied from /etc/rc 90548a3528SFranco Fichtner skip="-s nostart" 9188b499edSRobin Hahling# if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then 9288b499edSRobin Hahling# skip="$skip -s nojail" 9388b499edSRobin Hahling# fi 94684cb317SRobin Hahling [ -n "$local_startup" ] && find_local_scripts 95548a3528SFranco Fichtner files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null` 96548a3528SFranco Fichtnerfi 97548a3528SFranco Fichtner 98548a3528SFranco Fichtnerif [ -n "$ENABLED" ]; then 99548a3528SFranco Fichtner for file in $files; do 100548a3528SFranco Fichtner if grep -q ^rcvar $file; then 101548a3528SFranco Fichtner eval `grep ^name= $file` 102548a3528SFranco Fichtner eval `grep ^rcvar $file` 103548a3528SFranco Fichtner checkyesno $rcvar 2>/dev/null && echo $file 104548a3528SFranco Fichtner fi 105548a3528SFranco Fichtner done 106548a3528SFranco Fichtner exit 0 107548a3528SFranco Fichtnerfi 108548a3528SFranco Fichtner 109548a3528SFranco Fichtnerif [ -n "$LIST" ]; then 110548a3528SFranco Fichtner for dir in /etc/rc.d $local_startup; do 111548a3528SFranco Fichtner [ -n "$VERBOSE" ] && echo "From ${dir}:" 112*63cca36dSRobin Hahling [ -d ${dir} ] && /bin/ls -1 ${dir} 113548a3528SFranco Fichtner done 114548a3528SFranco Fichtner exit 0 115548a3528SFranco Fichtnerfi 116548a3528SFranco Fichtner 117548a3528SFranco Fichtnerif [ -n "$RCORDER" ]; then 118548a3528SFranco Fichtner for file in $files; do 119548a3528SFranco Fichtner echo $file 120548a3528SFranco Fichtner if [ -n "$VERBOSE" ]; then 121548a3528SFranco Fichtner case "$file" in 122548a3528SFranco Fichtner */${early_late_divider}) 123548a3528SFranco Fichtner echo '========= Early/Late Divider =========' ;; 124548a3528SFranco Fichtner esac 125548a3528SFranco Fichtner fi 126548a3528SFranco Fichtner done 127548a3528SFranco Fichtner exit 0 128548a3528SFranco Fichtnerfi 129548a3528SFranco Fichtner 130548a3528SFranco Fichtnerif [ $# -gt 1 ]; then 131548a3528SFranco Fichtner script=$1 132548a3528SFranco Fichtner shift 133548a3528SFranco Fichtnerelse 134548a3528SFranco Fichtner usage 135548a3528SFranco Fichtner exit 1 136548a3528SFranco Fichtnerfi 137548a3528SFranco Fichtner 138548a3528SFranco Fichtnercd / 139548a3528SFranco Fichtnerfor dir in /etc/rc.d $local_startup; do 140548a3528SFranco Fichtner if [ -x "$dir/$script" ]; then 141548a3528SFranco Fichtner [ -n "$VERBOSE" ] && echo "$script is located in $dir" 142548a3528SFranco Fichtner exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $* 143548a3528SFranco Fichtner fi 144548a3528SFranco Fichtnerdone 145548a3528SFranco Fichtner 146548a3528SFranco Fichtner# If the script was not found 147548a3528SFranco Fichtnerecho "$script does not exist in /etc/rc.d or the local startup" 148548a3528SFranco Fichtnerecho "directories (${local_startup}), or is not executable" 149548a3528SFranco Fichtnerexit 1 150