ping
On 09/25/15 14:44, Martijn van Duren wrote:
On 09/25/15 14:03, Stuart Henderson wrote:
On 2015/09/25 13:17, Martijn van Duren wrote:
I don't always want all daemons running all the time on my desktop,
but when
I want to start multiple daemons (for instance when doing some webdev) I
have to call rcctl multiple times, which results in multiple password
questions and long commands (I know I could set up doas.conf with the
nopass
option, but I'd rather enter my password when starting a daemon):
I like this a lot, but there's one small issue: if a service fails to
stop/start (either due to a problem with the service, or due to not being
enabled if you don't use -f) then it doesn't go on to start the remaining
daemons.
Here's an updated version with two extra minor regressions found and fixed:
- `rcctl <action> <blank>` results in a usage again (regression)
- `rcctl get(def) <blank>` doesn't results in a usage again (regression)
- `rcctl <action> <daemon> <daemon> ...` continues to run if a daemon
fails and exits with the error code of the last failed daemon.
Index: rcctl.sh
===================================================================
RCS file: /cvs/src/usr.sbin/rcctl/rcctl.sh,v
retrieving revision 1.79
diff -u -p -r1.79 rcctl.sh
--- rcctl.sh 12 Aug 2015 06:28:18 -0000 1.79
+++ rcctl.sh 25 Sep 2015 12:34:44 -0000
@@ -424,52 +424,76 @@ shift $((OPTIND-1))
[ $# -gt 0 ] || usage
action=$1
-if [ "${action}" = "ls" ]; then
- lsarg=$2
- [[ ${lsarg} == @(all|faulty|off|on|started|stopped) ]] || usage
-elif [ "${action}" = "order" ]; then
- shift 1
- svcs="$*"
-else
- svc=$2
- var=$3
- [ $# -ge 3 ] && shift 3 || shift $#
- args="$*"
-fi
-
-if [ -n "${svc}" ]; then
- [[ ${action} == @(disable|enable|get|getdef|set|start|stop|restart|reload|check) ]] || \
- usage
- svc_is_avail ${svc} || \
- rcctl_err "service ${svc} does not exist" 2
-elif [[ ${action} != @(ls|order) ]] ; then
- usage
-fi
-
-if [ -n "${var}" ]; then
- [[ ${var} != @(class|flags|status|timeout|user) ]] && usage
- [[ ${action} == set && ${var} = flags && ${args} = NO ]] && \
- rcctl_err "\"flags NO\" contradicts \"${action}\""
- [[ ${action} == set && ${var} == class ]] && \
- rcctl_err "\"${svc}_class\" is a read-only variable set in login.conf(5)"
- if svc_is_special ${svc}; then
- if [[ ${action} == set && ${var} != status ]] || \
- [[ ${action} == @(get|getdef) && ${var} == @(class|timeout|user) ]]; then
- rcctl_err "\"${svc}\" is a special variable, cannot \"${action} ${svc} ${var}\""
+case ${action} in
+ ls)
+ lsarg=$2
+ [[ ${lsarg} == @(all|faulty|off|on|started|stopped) ]] || usage
+ ;;
+ order)
+ shift 1
+ svcs="$*"
+ ;;
+ disable|enable|start|stop|restart|reload|check)
+ shift 1
+ svcs="$*"
+ [ -z "${svcs}" ] && usage
+ for svc in ${svcs}; do
+ svc_is_avail ${svc} || \
+ rcctl_err "service ${svc} does not exist" 2
+ done
+ ;;
+ get|getdef)
+ svc=$2
+ var=$3
+ [ -z "${svc}" ] && usage
+ svc_is_avail ${svc} || \
+ rcctl_err "service ${svc} does not exist" 2
+ if [ -n "${var}" ]; then
+ [[ ${var} != @(class|flags|status|timeout|user) ]] && usage
+ if svc_is_special ${svc}; then
+ [[ ${var} == @(class|timeout|user) ]] && \
+ rcctl_err "\"${svc}\" is a special variable, cannot \"${action} ${svc} ${var}\""
+ fi
fi
- fi
-elif [ ${action} = "set" ]; then
- usage
-fi
+ ;;
+ set)
+ svc=$2
+ var=$3
+ [ $# -ge 3 ] && shift 3 || shift $#
+ args="$*"
+ [ -z "${svc}" ] && usage
+ svc_is_avail ${svc} || \
+ rcctl_err "service ${svc} does not exist" 2
+ [[ ${var} != @(class|flags|status|timeout|user) ]] && usage
+ [[ ${var} = flags && ${args} = NO ]] && \
+ rcctl_err "\"flags NO\" contradicts \"${action}\""
+ [[ ${var} == class ]] && \
+ rcctl_err "\"${svc}_class\" is a read-only variable set in login.conf(5)"
+ if svc_is_special ${svc}; then
+ [[ ${var} != status ]] && \
+ rcctl_err "\"${svc}\" is a special variable, cannot \"${action} ${svc} ${var}\""
+ fi
+ ;;
+ *)
+ usage
+ ;;
+esac
+status=0
case ${action} in
disable) # undocumented, deprecated
needs_root ${action}
- svc_set ${svc} status off
+ for svc in ${svcs}; do
+ svc_set ${svc} status off || status=$?;
+ done
+ exit $status
;;
enable) # undocumented, deprecated
needs_root ${action}
- svc_set ${svc} status on
+ for svc in ${svcs}; do
+ svc_set ${svc} status on || status=$?;
+ done
+ exit $status
;;
get)
svc_get ${svc} "${var}"
@@ -495,10 +519,13 @@ case ${action} in
svc_set ${svc} "${var}" "${args}"
;;
start|stop|restart|reload|check)
- if svc_is_special ${svc}; then
- rcctl_err "\"${svc}\" is a special variable, no rc.d(8) script"
- fi
- /etc/rc.d/${svc} ${_RC_DEBUG} ${_RC_FORCE} ${action}
+ for svc in ${svcs}; do
+ if svc_is_special ${svc}; then
+ rcctl_err "\"${svc}\" is a special variable, no rc.d(8) script"
+ fi
+ /etc/rc.d/${svc} ${_RC_DEBUG} ${_RC_FORCE} ${action} || status=$?;
+ done
+ exit $status
;;
*)
usage