From cfe71d64421c5473145ef0d3df859e5a5a23502f Mon Sep 17 00:00:00 2001 From: robert <> Date: Tue, 26 Oct 2010 20:56:03 +0000 Subject: [PATCH] Add a simple 'rc' system to base in order to start/stop/restart/reload services installed by the ports system (for now). It only uses pgrep/pkill to handle these processes. A manual page will come later. 'put it in' deraadt@ --- src/etc/Makefile | 5 +++- src/etc/mtree/4.4BSD.dist | 7 ++++- src/etc/rc | 8 +++--- src/etc/rc.d/rc.subr | 54 +++++++++++++++++++++++++++++++++++++++ src/etc/rc.local | 7 +++-- src/etc/rc.shutdown | 16 +++++++++--- 6 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 src/etc/rc.d/rc.subr diff --git a/src/etc/Makefile b/src/etc/Makefile index 7ef715ad..750b6e64 100644 --- a/src/etc/Makefile +++ b/src/etc/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.293 2010/10/18 14:54:47 deraadt Exp $ +# $OpenBSD: Makefile,v 1.294 2010/10/26 20:56:03 robert Exp $ TZDIR= /usr/share/zoneinfo LOCALTIME= Canada/Mountain @@ -255,6 +255,9 @@ distribution-etc-root-var: distrib-dirs ${DESTDIR}/var/mail/root ${INSTALL} -c -o root -g wheel -m 440 ../usr.bin/sudo/sudoers \ ${DESTDIR}/etc/sudoers + cd rc.d; \ + ${INSTALL} -c -o root -g wheel -m 644 rc.subr \ + ${DESTDIR}/etc/rc.d distribution: exec ${SUDO} ${MAKE} distribution-etc-root-var diff --git a/src/etc/mtree/4.4BSD.dist b/src/etc/mtree/4.4BSD.dist index 2de15e19..107eeba0 100644 --- a/src/etc/mtree/4.4BSD.dist +++ b/src/etc/mtree/4.4BSD.dist @@ -1,4 +1,4 @@ -# $OpenBSD: 4.4BSD.dist,v 1.211 2010/10/18 20:52:43 deraadt Exp $ +# $OpenBSD: 4.4BSD.dist,v 1.212 2010/10/26 20:56:03 robert Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -193,6 +193,11 @@ ppp # ./etc/ppp .. +# ./etc/rc.d +rc.d +# ./etc/rc.d +.. + # ./etc/skel skel diff --git a/src/etc/rc b/src/etc/rc index 487663a2..05e2a9fe 100644 --- a/src/etc/rc +++ b/src/etc/rc @@ -1,4 +1,4 @@ -# $OpenBSD: rc,v 1.342 2010/10/01 20:51:32 jakob Exp $ +# $OpenBSD: rc,v 1.343 2010/10/26 20:56:03 robert Exp $ # System startup script run by init on autoboot # or after single-user. @@ -157,6 +157,9 @@ HOME=/; export HOME PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH +# pick up option configuration +. /etc/rc.conf + if [ X"$1" = X"shutdown" ]; then dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >/dev/null 2>&1 chmod 600 /var/db/host.random >/dev/null 2>&1 @@ -244,9 +247,6 @@ rm -f /fastboot # XXX (root now writeable) random_seed -# pick up option configuration -. /etc/rc.conf - # set flags on ttys. (do early, in case they use tty for SLIP in netstart) echo 'setting tty flags' ttyflags -a diff --git a/src/etc/rc.d/rc.subr b/src/etc/rc.d/rc.subr new file mode 100644 index 00000000..1b712fa0 --- /dev/null +++ b/src/etc/rc.d/rc.subr @@ -0,0 +1,54 @@ +[ -z $local_rcconf ] && . /etc/rc.conf + +rc_err() { + echo $1 + exit 1 +} + +rc_start() { + type rc_pre >/dev/null && rc_pre + eval $daemon $daemon_flags +} + +rc_check() { + pgrep -f "^$pexp" >/dev/null +} + +rc_reload() { + pkill -HUP -f "^$pexp" +} + +rc_stop() { + pkill -f "^$pexp" + type rc_post >/dev/null && rc_post || return 0 +} + +rc_cmd() { + [ `id -u` -eq 0 ] || rc_err "$0: need root privileges" + [ -n "$daemon" ] || rc_err "$0: daemon is not set" + [ -n "$pexp" ] || pexp="$daemon${daemon_flags:+ $daemon_flags}" + + case "$1" in + check|status) + rc_check + ;; + start) + rc_check || rc_start + ;; + stop) + rc_stop + ;; + reload) + rc_check && rc_reload + ;; + restart) + rc_stop + while rc_check; do + sleep 1 + done + rc_start + ;; + *) + rc_err "usage: $0 {start|check|reload|restart|stop}" + esac +} diff --git a/src/etc/rc.local b/src/etc/rc.local index 83284ff2..af88e0a0 100644 --- a/src/etc/rc.local +++ b/src/etc/rc.local @@ -1,4 +1,4 @@ -# $OpenBSD: rc.local,v 1.39 2006/07/28 20:19:46 sturm Exp $ +# $OpenBSD: rc.local,v 1.40 2010/10/26 20:56:03 robert Exp $ # Site-specific startup actions, daemons, and other things which # can be done AFTER your system goes into securemode. For actions @@ -7,7 +7,10 @@ echo -n 'starting local daemons:' +for _r in $rc_scripts; do + [ -x /etc/rc.d/${_r} ] && /etc/rc.d/${_r} start && echo -n " ${_r}" +done + # Add your local startup actions here. echo '.' - diff --git a/src/etc/rc.shutdown b/src/etc/rc.shutdown index 1c42393d..ef857221 100644 --- a/src/etc/rc.shutdown +++ b/src/etc/rc.shutdown @@ -1,4 +1,4 @@ -# $OpenBSD: rc.shutdown,v 1.7 2006/06/22 00:41:59 deraadt Exp $ +# $OpenBSD: rc.shutdown,v 1.8 2010/10/26 20:56:03 robert Exp $ # # If it exists, this script is run at system-shutdown by reboot(8), # halt(8). If the architecture supports keyboard requested halting, @@ -7,6 +7,14 @@ powerdown=NO # set to YES for powerdown -# -# Your shell code goes here -# +echo -n 'stopping local daemons:' + +while [ -n "$rc_scripts" ]; do + _r=${rc_scripts##* } + rc_scripts=${rc_scripts%%*( )${_r}} + [ -x /etc/rc.d/${_r} ] && /etc/rc.d/${_r} stop && echo -n " ${_r}" +done + +# Add your local shutdown actions here. + +echo '.'