Re: rcctl action multiple daemons
On Wed, Sep 30, 2015 at 01:40:44PM +0200, Antoine Jacoutot wrote: > On Wed, Sep 30, 2015 at 12:30:52PM +0200, Martijn van Duren wrote: > > ping > > I am still pondering the pros and cons... I'll probably commit your diff tomorrow, thanks. -- Antoine
Re: rcctl action multiple daemons
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 ` results in a usage again (regression) - `rcctl get(def) ` doesn't results in a usage again (regression) - `rcctl...` 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 - 1.79 +++ rcctl.sh 25 Sep 2015 12:34:44 - @@ -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
rcctl action multiple daemons
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 - 1.79 +++ rcctl.sh 25 Sep 2015 11:10:04 - @@ -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
Re: rcctl action multiple daemons
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.
Re: rcctl action multiple daemons
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 ` results in a usage again (regression) - `rcctl get(def) ` doesn't results in a usage again (regression) - `rcctl...` 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 - 1.79 +++ rcctl.sh 25 Sep 2015 12:34:44 - @@ -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