2 # $NetBSD: service,v 1.7 2015/04/05 11:33:15 apb Exp $
3 # service -- run or list system services
5 # Taken from FreeBSD: releng/10.1/usr.sbin/service/service.sh 268098
6 # Modified for NetBSD by Adrian Steinmann in March, 2015
8 # Copyright (c) 2009 Douglas Barton
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 export PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin
37 echo "usage: ${me} [-elv]"
38 echo " ${me} [-ev] rc_script_name [rc_script_name2 [...]]"
39 echo " ${me} [-v] rc_script_name action"
40 echo " -e: List enabled scripts; check if given scripts are enabled"
41 echo " -l: List all scripts in rcorder"
42 echo " -v: Verbose (mention in which directory script is found)"
43 echo "rc_directories is currently set to ${rc_directories}"
47 # list all files in rc_directories with absolute pathnames
48 # written to be compatible with ls(1) from pre netbsd-7
52 for _d
in ${rc_directories}; do
55 [ -f "$_f" -a -x "$_f" ] && echo "$_f"
58 done |
xargs rcorder
-s nostart
${rc_rcorder_flags} 2>/dev
/null
62 while getopts elv o
; do
70 shift $
( expr $OPTIND - 1 )
72 [ -n "${ENABLED}" -a -n "${LIST}" ] && usage
77 if [ -n "${ENABLED}" ]; then
78 [ -n "${VERBOSE}" ] && echo "rc_directories is ${rc_directories}" >&2
82 flt
=$
( echo $
* |
sed -e 's; ;|;g' -e 's;^;egrep /(;' -e 's;$;)$;' )
84 _rc_files |
$flt |
while read file
86 if grep -q ^rcvar
"$file"; then
87 eval $
( grep ^name
= "$file" )
88 eval $
( grep ^rcvar
"$file" )
89 if [ -n "${rcvar}" ]; then
90 load_rc_config
${rcvar}
91 checkyesno
${rcvar} 2>/dev
/null
&& echo ${file}
98 if [ -n "${LIST}" ]; then
99 [ -n "${VERBOSE}" ] && echo "rc_directories is ${rc_directories}" >&2
104 if [ $# -eq 2 ]; then
111 for dir
in ${rc_directories}; do
112 if [ -x "${dir}/${script}" ]; then
113 [ -n "${VERBOSE}" ] && echo "${script} is located in ${dir}" >&2
118 HOME
=/ PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin \
119 "${dir}/${script}" "${arg}"
120 echo "Failed to exec ${dir}/${script} ${arg}" >&2
125 echo "${script} does not exist in ${rc_directories}" >&2