Hello tech@,
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):
$ doas rcctl -f start mysqld && doas rcctl -f start php_fpm && doas
rcctl -f start nginx
Password:
mysqld(ok)
Password:
php_fpm(ok)
Password:
nginx(ok)
Which I find somewhat annoying. The following patch allows to combine
multiple daemons on a single action, which is possible since var and and
args aren't used:
$ doas rcctl -f start mysqld php_fpm nginx
Password:
mysqld(ok)
php_fpm(ok)
nginx(ok)
Which I find far more convenient.
I have lightly tested this patch and there seem to be no regressions.
I gave disable and enable the same treatment as action, because it was
slightly easier that way.
Any interest in (or comments on) this patch?
Sincerely,
Martijn van Duren
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 11:10:04 -0000
@@ -424,52 +424,68 @@ 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="$*"
+ for svc in ${svcs}; do
+ svc_is_avail ${svc} || \
+ rcctl_err "service ${svc} does not exist" 2
+ done
+ ;;
+ get|getdef)
+ svc=$2
+ var=$3
+ svc_is_avail ${svc} || \
+ rcctl_err "service ${svc} does not exist" 2
+ [[ ${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
-elif [ ${action} = "set" ]; then
- usage
-fi
+ ;;
+ set)
+ svc=$2
+ var=$3
+ [ $# -ge 3 ] && shift 3 || shift $#
+ args="$*"
+ 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
case ${action} in
disable) # undocumented, deprecated
needs_root ${action}
- svc_set ${svc} status off
+ for svc in ${svcs}; do
+ svc_set ${svc} status off || break;
+ done
;;
enable) # undocumented, deprecated
needs_root ${action}
- svc_set ${svc} status on
+ for svc in ${svcs}; do
+ svc_set ${svc} status on || break;
+ done
;;
get)
svc_get ${svc} "${var}"
@@ -495,10 +511,12 @@ 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} || break;
+ done
;;
*)
usage