From: ajacoutot Date: Wed, 24 Dec 2014 13:04:43 +0000 (+0000) Subject: Implement some kind ordering in the startup of package script daemons. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ab2f10b496660a90dc28cd22df4f06429d531f99;p=openbsd Implement some kind ordering in the startup of package script daemons. 'rcctl order ...' will prepend the daemon(s) given as argument to the pkg_scripts line (it can be all daemons, some, or just one). Without argument, it'll display the current order. While here, drop a couple of examples from the man page to only leave the most interesting one. ok schwarze@ rpe@ (with tweaks) jasper@ robert@ sthen@ --- diff --git a/usr.sbin/rcctl/rcctl.8 b/usr.sbin/rcctl/rcctl.8 index df07c83509e..a854553d3f4 100644 --- a/usr.sbin/rcctl/rcctl.8 +++ b/usr.sbin/rcctl/rcctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rcctl.8,v 1.10 2014/10/13 14:12:57 schwarze Exp $ +.\" $OpenBSD: rcctl.8,v 1.11 2014/12/24 13:04:43 ajacoutot Exp $ .\" .\" Copyright (c) 2014 Antoine Jacoutot .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 13 2014 $ +.Dd $Mdocdate: December 24 2014 $ .Dt RCCTL 8 .Os .Sh NAME @@ -24,9 +24,9 @@ .Nm rcctl .Op Fl df .Sm off -.Cm enable | disable | status | default | Ar action +.Cm enable | disable | status | default | order | Ar action .Sm on -.Op Ar service | daemon Op Cm flags Op Ar arguments +.Op Ar service | daemon Oo Cm flags Oo Ar arguments Oc Oc | Ar daemons .Sh DESCRIPTION The .Nm @@ -81,6 +81,16 @@ For a daemon, display the flags that will be used if is called without .Ar arguments . For a base system service, display whether it is enabled by default. +.It Cm order Op Ar daemons +Order +.Sy enabled +.Xr packages 7 +daemons startup by prepending +.Ar daemons +to the pkg_scripts line. +If +.Ar daemons +is empty, display the current order. .It Oo Fl df Oc Ar action daemon Run the .Xr rc.d 8 @@ -107,17 +117,6 @@ utility exits 0 on success, and >0 if an error occurs .Ar service .Pc . .Sh EXAMPLES -Disable -.Xr ntpd 8 -and check its status: -.Bd -literal -offset indent -# rcctl disable ntpd -# rcctl status ntpd -NO -# echo $? -1 -.Ed -.Pp Enable and set .Xr ntpd 8 flags: @@ -128,18 +127,6 @@ flags: # echo $? 0 .Ed -.Pp -Start -.Xr ntpd 8 -and check that it is running: -.Bd -literal -offset indent -# rcctl start ntpd -ntpd(ok) -# rcctl check ntpd -ntpd(ok) -# echo $? -0 -.Ed .Sh SEE ALSO .Xr rc.conf.local 8 , .Xr rc.d 8 diff --git a/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index b844fb6e40d..e4ae59818cc 100644 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: rcctl.sh,v 1.50 2014/12/23 10:07:44 ajacoutot Exp $ +# $OpenBSD: rcctl.sh,v 1.51 2014/12/24 13:04:43 ajacoutot Exp $ # # Copyright (c) 2014 Antoine Jacoutot # Copyright (c) 2014 Ingo Schwarze @@ -27,8 +27,8 @@ _rc_parse_conf usage() { - _rc_err "usage: ${0##*/} [-df] enable|disable|status|default|action - [service | daemon [flags [arguments]]]" + _rc_err "usage: ${0##*/} [-df] enable|disable|status|default|order|action + [service | daemon [flags [arguments]] | daemons]" } needs_root() @@ -202,6 +202,28 @@ append_to_pkg_scripts() rcconf_edit_end } +order_pkg_scripts() +{ + local _svcs="$*" + [ -n "${_svcs}" ] || return + + needs_root ${action} + local _pkg_scripts _svc + for _svc in ${_svcs}; do + if svc_is_base ${_svc} || svc_is_special ${_svc}; then + _rc_err "${0##*/}: ${_svc} is not a pkg script" + elif ! svc_is_enabled ${_svc}; then + _rc_err "${0##*/}: ${_svc} is not enabled" + fi + done + _pkg_scripts=$(echo "${_svcs} ${pkg_scripts}" | tr "[:blank:]" "\n" | \ + awk -v ORS=' ' '!x[$0]++') + rcconf_edit_begin + grep -v "^pkg_scripts.*=" /etc/rc.conf.local >${_TMP_RCCONF} + echo pkg_scripts=${_pkg_scripts} >>${_TMP_RCCONF} + rcconf_edit_end +} + rm_from_pkg_scripts() { local _svc=$1 @@ -292,16 +314,21 @@ shift $((OPTIND-1)) [ $# -gt 0 ] || usage action=$1 -svc=$2 -flag=$3 -[ $# -ge 3 ] && shift 3 || shift $# -flags="$*" +if [ "${action}" = "order" ]; then + shift 1 + svcs="$*" +else + svc=$2 + flag=$3 + [ $# -ge 3 ] && shift 3 || shift $# + flags="$*" +fi if [ -n "${svc}" ]; then if ! svc_is_avail ${svc}; then _rc_err "${0##*/}: service ${svc} does not exist" 2 fi -elif [ "${action}" != "default" -a "${action}" != "status" ] ; then +elif [[ ${action} != @(default|order|status) ]] ; then usage fi @@ -339,6 +366,14 @@ case ${action} in append_to_pkg_scripts ${svc} fi ;; + order) + if [ -n "${svcs}" ]; then + needs_root ${action} + order_pkg_scripts ${svcs} + else + echo ${pkg_scripts} + fi + ;; status) svc_get_status ${svc} ;;