-.\" $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 <ajacoutot@openbsd.org>
.\"
.\" 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
.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
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
.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:
# 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
#!/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 <ajacoutot@openbsd.org>
# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
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()
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
[ $# -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
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}
;;