Browse Source

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@
OPENBSD_4_9
robert 14 years ago
parent
commit
cfe71d6442
6 changed files with 85 additions and 12 deletions
  1. +4
    -1
      src/etc/Makefile
  2. +6
    -1
      src/etc/mtree/4.4BSD.dist
  3. +4
    -4
      src/etc/rc
  4. +54
    -0
      src/etc/rc.d/rc.subr
  5. +5
    -2
      src/etc/rc.local
  6. +12
    -4
      src/etc/rc.shutdown

+ 4
- 1
src/etc/Makefile View File

@ -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 TZDIR= /usr/share/zoneinfo
LOCALTIME= Canada/Mountain LOCALTIME= Canada/Mountain
@ -255,6 +255,9 @@ distribution-etc-root-var: distrib-dirs
${DESTDIR}/var/mail/root ${DESTDIR}/var/mail/root
${INSTALL} -c -o root -g wheel -m 440 ../usr.bin/sudo/sudoers \ ${INSTALL} -c -o root -g wheel -m 440 ../usr.bin/sudo/sudoers \
${DESTDIR}/etc/sudoers ${DESTDIR}/etc/sudoers
cd rc.d; \
${INSTALL} -c -o root -g wheel -m 644 rc.subr \
${DESTDIR}/etc/rc.d
distribution: distribution:
exec ${SUDO} ${MAKE} distribution-etc-root-var exec ${SUDO} ${MAKE} distribution-etc-root-var


+ 6
- 1
src/etc/mtree/4.4BSD.dist View File

@ -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 /set type=dir uname=root gname=wheel mode=0755
# . # .
@ -193,6 +193,11 @@ ppp
# ./etc/ppp # ./etc/ppp
.. ..
# ./etc/rc.d
rc.d
# ./etc/rc.d
..
# ./etc/skel # ./etc/skel
skel skel


+ 4
- 4
src/etc/rc View File

@ -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 # System startup script run by init on autoboot
# or after single-user. # or after single-user.
@ -157,6 +157,9 @@ HOME=/; export HOME
PATH=/sbin:/bin:/usr/sbin:/usr/bin PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH export PATH
# pick up option configuration
. /etc/rc.conf
if [ X"$1" = X"shutdown" ]; then if [ X"$1" = X"shutdown" ]; then
dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >/dev/null 2>&1 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 chmod 600 /var/db/host.random >/dev/null 2>&1
@ -244,9 +247,6 @@ rm -f /fastboot # XXX (root now writeable)
random_seed random_seed
# pick up option configuration
. /etc/rc.conf
# set flags on ttys. (do early, in case they use tty for SLIP in netstart) # set flags on ttys. (do early, in case they use tty for SLIP in netstart)
echo 'setting tty flags' echo 'setting tty flags'
ttyflags -a ttyflags -a


+ 54
- 0
src/etc/rc.d/rc.subr View File

@ -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
}

+ 5
- 2
src/etc/rc.local View File

@ -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 # Site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions # can be done AFTER your system goes into securemode. For actions
@ -7,7 +7,10 @@
echo -n 'starting local daemons:' 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. # Add your local startup actions here.
echo '.' echo '.'

+ 12
- 4
src/etc/rc.shutdown View File

@ -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), # If it exists, this script is run at system-shutdown by reboot(8),
# halt(8). If the architecture supports keyboard requested halting, # halt(8). If the architecture supports keyboard requested halting,
@ -7,6 +7,14 @@
powerdown=NO # set to YES for powerdown 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 '.'

Loading…
Cancel
Save