Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144640464
D451.1775969152.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
8 KB
Referenced Files
None
Subscribers
None
D451.1775969152.diff
View Options
Index: usr.sbin/service/service.8
===================================================================
--- usr.sbin/service/service.8
+++ usr.sbin/service/service.8
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 11, 2012
+.Dd April 24, 2016
.Dt SERVICE 8
.Os
.Sh NAME
@@ -32,15 +32,22 @@
.Nd "control (start/stop/etc.) or list system services"
.Sh SYNOPSIS
.Nm
-.Fl e
+.Op Fl c Ar /path/to/rc.conf
+.Ar name
+.Cm enable|disable|delete|opts
.Nm
-.Fl R
+.Fl e Op Fl n
.Nm
.Op Fl v
.Fl l | r
.Nm
+.Fl R
+.Nm
+.Fl s
+.Nm
.Op Fl v
-.Ar <rc.d script> start|stop|etc.
+.Ar name
+.Cm start|stop|...
.Sh DESCRIPTION
The
.Nm
@@ -54,8 +61,15 @@
.Pp
The options are as follows:
.Bl -tag -width F1
+.It Fl c
+The enable, disable, delete, and opts sub-commands operate on a specific config
+file, rather than defaulting to
+.Pa /etc/rc.conf.d/<name> .
.It Fl e
-List services that are enabled.
+List services that are enabled by their rc.d script.
+The
+.Fl n
+flag causes services to be listed by their name instead.
The list of scripts to check is compiled using
.Xr rcorder 8
the same way that it is done in
@@ -82,9 +96,38 @@
as in
.Fl e
above, but list all of the files, not just what is enabled.
+.It Fl s
+Output the status of each enabled service.
.It Fl v
Be slightly more verbose
.El
+.Sh SUBCOMMANDS
+Any subcommand provided is passed to the rc.d script of the service, with the
+exception of the following:
+.Bl -tag -width disable
+.It Cm enable
+Enables the service by setting the <name>_enable rcvar to
+.Qq YES .
+Unless the
+.Fl c
+flag is specified, the change is written to
+.Pa /etc/rc.conf.d/<name> .
+.It Cm disable
+Disables the service by setting the <name>_enable rcvar to
+.Qq NO .
+Unless the
+.Fl c
+flag is specified, the change is written to
+.Pa /etc/rc.conf.d/<name> .
+.It Cm delete
+Deletes any <name>_enable rcvar entries from the config files
+If the
+.Fl c
+flag is specified, only the indicated config file is changed.
+.It Cm opts
+Attempts to list the possible config options that can be specified for the
+service.
+.El
.Sh ENVIRONMENT
When used to run rc.d scripts the
.Nm
@@ -106,7 +149,10 @@
.Nm
command:
.Pp
+.Dl "service named enable"
+.Dl "service named start"
.Dl "service named status"
+.Dl "service named disable"
.Dl "service -rv"
.Pp
The following programmable completion entry can be use in
@@ -123,7 +169,8 @@
.Xr bash 1 Pq Pa ports/shells/bash ,
.Xr rc.conf 5 ,
.Xr rc 8 ,
-.Xr rcorder 8
+.Xr rcorder 8 ,
+.Xr sysrc 8
.Sh HISTORY
The
.Nm
Index: usr.sbin/service/service.sh
===================================================================
--- usr.sbin/service/service.sh
+++ usr.sbin/service/service.sh
@@ -3,6 +3,8 @@
# $FreeBSD$
# Copyright (c) 2009 Douglas Barton
+# Copyright (c) 2014 Lars Engels
+# Copyright (c) 2016 Allan Jude <allanjude@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -32,27 +34,117 @@
usage () {
echo ''
echo 'Usage:'
- echo "${0##*/} -e"
- echo "${0##*/} -R"
+ echo "${0##*/} [-c /path/to/rc.conf] <name> enable|disable|delete|opts"
+ echo "${0##*/} -e [-n]"
echo "${0##*/} [-v] -l | -r"
- echo "${0##*/} [-v] <rc.d script> start|stop|etc."
+ echo "${0##*/} -R"
+ echo "${0##*/} -s"
+ echo "${0##*/} [-v] <name> start|stop|..."
echo "${0##*/} -h"
echo ''
+ echo '-c Operate on a specific config file'
echo '-e Show services that are enabled'
- echo "-R Stop and start enabled $local_startup services"
echo "-l List all scripts in /etc/rc.d and $local_startup"
+ echo '-n Display service name, rather than path to rc.d script'
echo '-r Show the results of boot time rcorder'
+ echo "-R Stop and start enabled $local_startup services"
+ echo '-s Show status of all services that are enabled'
echo '-v Verbose'
echo ''
}
-while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do
+do_rc_action () {
+ script=$1
+ action=$2
+
+ cd /
+ _rcd=
+ for dir in /etc/rc.d $local_startup; do
+ if [ -x "$dir/$script" ]; then
+ if grep -q ^rcvar "$dir/$script"; then
+ _rcd="$dir/$script"
+ eval `grep ^name= "$_rcd"`
+ eval `grep ^rcvar "$_rcd"`
+ if [ -n "$rcvar" ]; then
+ load_rc_config_var "${name}" "${rcvar}"
+ fi
+ fi
+ fi
+ done
+ if [ -z "$rcvar" ]; then
+ if [ -n "$VERBOSE" ]; then
+ echo "Unable to determine rcvar for $script"
+ fi
+ exit 1
+ fi
+
+ _sysrc_flags="-s $name -e"
+ if [ -d "/etc/rc.conf.d" ]; then
+ _conf="${CONFFILE:-/etc/rc.conf.d/$name}"
+ _sysrc_conf="-f $_conf"
+ else
+ _conf="${CONFFILE:-/etc/rc.conf}"
+ fi
+ CONFDIR="$( dirname "$_conf" )"
+ if [ ! -e "$CONFDIR" ]; then
+ mkdir -p "$CONFDIR"
+ fi
+ case "$action" in
+ "enable")
+ /usr/sbin/sysrc $_sysrc_conf $_sysrc_flags $rcvar=YES
+ exitflag=$?
+ ;;
+ "disable")
+ /usr/sbin/sysrc $_sysrc_conf $_sysrc_flags $rcvar=NO
+ exitflag=$?
+ ;;
+ "delete")
+ /usr/sbin/sysrc $_sysrc_conf $_sysrc_flags -x $rcvar
+ exitflag=$?
+ ;;
+ "opts")
+ _rcopts=
+ _oifs=$IFS
+ IFS='
+ '
+ for _l in $(grep '^: ${' $_rcd); do
+ _v=${_l##: \$\{} #strip leading bits
+ _v=${_v%%:*} #strip conditional sets
+ _v=${_v%%=*} #strip unconditional sets
+ if [ -z "$_v" ]; then
+ continue
+ fi
+ _rcopts="$_rcopts $_v"
+ done
+ IFS=$_oifs
+
+ echo "$rcvar"
+ for _v in $_rcopts; do
+ if [ "$_v" = "$rcvar" ]; then
+ continue
+ fi
+ echo $_v
+ done
+ ;;
+ *)
+ echo "Error: unexpected action $action"
+ exit 1
+ ;;
+ esac
+
+ return $exitflag
+}
+
+while getopts 'c:ehlnrRsv' COMMAND_LINE_ARGUMENT ; do
case "${COMMAND_LINE_ARGUMENT}" in
+ c) CONFFILE=$OPTARG ;;
e) ENABLED=eopt ;;
h) usage ; exit 0 ;;
l) LIST=lopt ;;
+ n) NAME=nopt ;;
r) RCORDER=ropt ;;
R) RESTART=Ropt ;;
+ s) ENABLED=sopt ;;
v) VERBOSE=vopt ;;
*) usage ; exit 1 ;;
esac
@@ -69,19 +161,21 @@
for file in `reverse_list ${files}`; do
if grep -q ^rcvar $file; then
- eval `grep ^name= $file`
- eval `grep ^rcvar $file`
+ eval `grep ^name= "$file"`
+ eval `grep ^rcvar "$file"`
if [ -n "$rcvar" ]; then
- load_rc_config_var ${name} ${rcvar}
+ load_rc_config_var "${name}" "${rcvar}"
fi
- checkyesno $rcvar 2>/dev/null && run_rc_script ${file} stop
+ checkyesno $rcvar 2>/dev/null &&
+ run_rc_script "${file}" stop
fi
done
for file in $files; do
- if grep -q ^rcvar $file; then
- eval `grep ^name= $file`
- eval `grep ^rcvar $file`
- checkyesno $rcvar 2>/dev/null && run_rc_script ${file} start
+ if grep -q ^rcvar "$file"; then
+ eval `grep ^name= "$file"`
+ eval `grep ^rcvar "$file"`
+ checkyesno $rcvar 2>/dev/null &&
+ run_rc_script "${file}" start
fi
done
@@ -100,13 +194,30 @@
if [ -n "$ENABLED" ]; then
for file in $files; do
- if grep -q ^rcvar $file; then
- eval `grep ^name= $file`
- eval `grep ^rcvar $file`
+ if grep -q ^rcvar "$file"; then
+ eval `grep ^name= "$file"`
+ eval `grep ^rcvar "$file"`
if [ -n "$rcvar" ]; then
- load_rc_config_var ${name} ${rcvar}
+ load_rc_config_var "${name}" "${rcvar}"
+ fi
+ if [ "$ENABLED" = "eopt" ]; then
+ if [ -n "$NAME" -a -n "$name" ]; then
+ checkyesno $rcvar 2>/dev/null &&
+ echo $name
+ else
+ checkyesno $rcvar 2>/dev/null &&
+ echo $file
+ fi
+ elif [ "$ENABLED" = "sopt" ]; then
+ # Not all services have 'status', only those
+ # with a command defined
+ command=
+ eval `grep ^command= "$file"`
+ if [ -n "$command" ]; then
+ checkyesno $rcvar 2>/dev/null &&
+ run_rc_script "${file}" quietstatus
+ fi
fi
- checkyesno $rcvar 2>/dev/null && echo $file
fi
done
exit 0
@@ -115,7 +226,7 @@
if [ -n "$LIST" ]; then
for dir in /etc/rc.d $local_startup; do
[ -n "$VERBOSE" ] && echo "From ${dir}:"
- [ -d ${dir} ] && /bin/ls -1 ${dir}
+ [ -d "${dir}" ] && /bin/ls -1 "${dir}"
done
exit 0
fi
@@ -141,11 +252,22 @@
exit 1
fi
+case "$1" in
+ enable | disable | delete | opts)
+ # Special command, further processing required
+ do_rc_action "$script" "$1"
+ exit $?
+ ;;
+ *)
+ # Regular command, fall through to normal processing
+ ;;
+esac
+
cd /
for dir in /etc/rc.d $local_startup; do
if [ -x "$dir/$script" ]; then
[ -n "$VERBOSE" ] && echo "$script is located in $dir"
- exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin $dir/$script $*
+ exec env -i HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin "$dir/$script" "$@"
fi
done
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 12, 4:45 AM (1 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28324163
Default Alt Text
D451.1775969152.diff (8 KB)
Attached To
Mode
D451: Add new switches to service(8): enable, disable, rcopts and rcdelete
Attached
Detach File
Event Timeline
Log In to Comment