diff options
author | Robert Nagy <robert@cvs.openbsd.org> | 2010-10-26 20:56:04 +0000 |
---|---|---|
committer | Robert Nagy <robert@cvs.openbsd.org> | 2010-10-26 20:56:04 +0000 |
commit | f3e98b5d75919954908260771ba2a987309c7fa0 (patch) | |
tree | 3c2f30ead3f23405e3a19d86eb5e425855db4890 /etc | |
parent | 8a549178ee06b6828240c981a6bdd4e3f523609d (diff) |
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@
Diffstat (limited to 'etc')
-rw-r--r-- | etc/Makefile | 5 | ||||
-rw-r--r-- | etc/mtree/4.4BSD.dist | 7 | ||||
-rw-r--r-- | etc/rc | 8 | ||||
-rw-r--r-- | etc/rc.d/rc.subr | 54 | ||||
-rw-r--r-- | etc/rc.local | 7 | ||||
-rw-r--r-- | etc/rc.shutdown | 16 |
6 files changed, 85 insertions, 12 deletions
diff --git a/etc/Makefile b/etc/Makefile index 7ef715adbba..750b6e649f4 100644 --- a/etc/Makefile +++ b/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/etc/mtree/4.4BSD.dist b/etc/mtree/4.4BSD.dist index 2de15e19e7e..107eeba0be7 100644 --- a/etc/mtree/4.4BSD.dist +++ b/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 @@ -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/etc/rc.d/rc.subr b/etc/rc.d/rc.subr new file mode 100644 index 00000000000..1b712fa0b86 --- /dev/null +++ b/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/etc/rc.local b/etc/rc.local index 83284ff292a..af88e0a06c7 100644 --- a/etc/rc.local +++ b/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/etc/rc.shutdown b/etc/rc.shutdown index 1c42393d2c0..ef85722199b 100644 --- a/etc/rc.shutdown +++ b/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 '.' |