Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 Sep 2012 13:18:16 -0700
From:      Xin Li <delphij@delphij.net>
To:        freebsd-rc@FreeBSD.ORG
Subject:   [PATCH] Add -R (restart all local services) to service(8)
Message-ID:  <504A5688.3090905@delphij.net>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------060608070106060403000200
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Here is a patch that adds a new option, -R, to service(8), that
restarts all "local" services.  Useful for after portmaster -a.

Cheers,
- -- 
Xin LI <delphij@delphij.net>    https://www.delphij.net/
FreeBSD - The Power to Serve!           Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBCAAGBQJQSlaIAAoJEG80Jeu8UPuzlrgIAJy7h5M80B2LI0rW/2urMOom
F9Jf9YIHSOeiMEHiFKhCEUKVtPYj9s6sSD2uJcerokcpV6jBvVBl1+FKIxpVE0mp
ZPUeatfPAK+4sOL6HKVm6r7T9J3x2TVCPl2iRmrmceIyjh81G+NmSI4RYamwe+/z
MY1iT9cjFxrQwVqnhEv5buOQsbS+pjL9i2qW0d5FzU3HGJXub6XoCJqvNJxq1uXk
cEhSETyJJDZRv9dJcz+8uu/tOe0YSjZaTvg/qQ26NJAU4u632S+9MCBbd86N2dau
1TNRtLaqO/4RrZBwzZTgr2KEPDWBiPC8/ZFS6QLCHeG1ckFGL4HrTnI3u13iweo=
=BGh/
-----END PGP SIGNATURE-----

--------------060608070106060403000200
Content-Type: text/plain;
 name="service.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="service.diff"

Index: service.8
===================================================================
--- service.8	(revision 240211)
+++ service.8	(working copy)
@@ -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
Index: service.sh
===================================================================
--- service.sh	(revision 240211)
+++ service.sh	(working copy)
@@ -33,29 +33,58 @@ usage () {
 	echo ''
 	echo 'Usage:'
 	echo "${0##*/} -e"
+	echo "${0##*/} -R"
 	echo "${0##*/} [-v] -l | -r"
 	echo "${0##*/} [-v] <rc.d script> 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"

--------------060608070106060403000200--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?504A5688.3090905>