From f292f6dd5e6fee271b9f61bd057abbe138603f14 Mon Sep 17 00:00:00 2001 From: Xin LI Date: Wed, 12 Dec 2012 01:50:58 +0000 Subject: [PATCH] Add -R, an option to restart all enabled "local" services. Discussed on: -rc@ (in September) MFC after: 2 months --- usr.sbin/service/service.8 | 6 +++++- usr.sbin/service/service.sh | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/usr.sbin/service/service.8 b/usr.sbin/service/service.8 index 10f2e8f608bc..0c2b2d30c912 100644 --- a/usr.sbin/service/service.8 +++ b/usr.sbin/service/service.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 26, 2009 +.Dd December 11, 2012 .Dt SERVICE 8 .Os .Sh NAME @@ -34,6 +34,8 @@ .Nm .Fl e .Nm +.Fl R +.Nm .Op Fl v .Fl l | r .Nm @@ -62,6 +64,8 @@ then that list of scripts is checked for an .Qq rcvar assignment. If present the script is checked to see if it is enabled. +.It Fl R +Restart all enabled local services. .It Fl l List all files in .Pa /etc/rc.d diff --git a/usr.sbin/service/service.sh b/usr.sbin/service/service.sh index 1794315fb73c..cf181fa57a16 100755 --- a/usr.sbin/service/service.sh +++ b/usr.sbin/service/service.sh @@ -33,29 +33,58 @@ usage () { echo '' echo 'Usage:' echo "${0##*/} -e" + echo "${0##*/} -R" echo "${0##*/} [-v] -l | -r" echo "${0##*/} [-v] start|stop|etc." echo "${0##*/} -h" echo '' 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 '-r Show the results of boot time rcorder' echo '-v Verbose' echo '' } -while getopts 'ehlrv' COMMAND_LINE_ARGUMENT ; do +while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do case "${COMMAND_LINE_ARGUMENT}" in e) ENABLED=eopt ;; h) usage ; exit 0 ;; l) LIST=lopt ;; r) RCORDER=ropt ;; + R) RESTART=Ropt ;; v) VERBOSE=vopt ;; *) usage ; exit 1 ;; esac done shift $(( $OPTIND - 1 )) +if [ -n "$RESTART" ]; then + skip="-s nostart" + if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then + skip="$skip -s nojail" + fi + [ -n "$local_startup" ] && find_local_scripts_new + files=`rcorder ${skip} ${local_rc} 2>/dev/null` + + for file in `reverse_list ${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} 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 + fi + done + + exit 0 +fi + if [ -n "$ENABLED" -o -n "$RCORDER" ]; then # Copied from /etc/rc skip="-s nostart"