Skip to content

Commit

Permalink
Separate shutdown services
Browse files Browse the repository at this point in the history
  • Loading branch information
konimex committed Mar 26, 2018
1 parent 65e0733 commit f8a8bc6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
35 changes: 3 additions & 32 deletions 3
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,11 @@ if [ -e /run/runit/reboot ]; then
chmod 100 /run/runit/reboot
fi

echo
msg "Waiting for services to stop..."
sv force-stop /run/runit/service/*
sv exit /run/runit/service/*

[ -x /etc/runit/rc.shutdown ] && /etc/runit/rc.shutdown

msg "Saving random seed..."
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )

if [ -z "$VIRTUALIZATION" -a -n "$HARDWARECLOCK" ]; then
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
fi

halt -w # for utmp

if [ -z "$VIRTUALIZATION" ]; then
msg "Stopping udev..."
udevadm control --exit
fi

msg "Sending TERM signal to processes..."
pkill --inverse -s0,1 -TERM
sleep 1
msg "Sending KILL signal to processes..."
pkill --inverse -s0,1 -KILL

if [ -z "$VIRTUALIZATION" ]; then
msg "Unmounting filesystems, disabling swap..."
swapoff -a
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
msg "Remounting rootfs read-only..."
mount -o remount,ro /
fi
for f in /etc/runit/shutdown-services/*.sh; do
[ -r $f ] && . $f
done

sync

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ install:
install -d ${DESTDIR}/etc/runit/sv
install -d ${DESTDIR}/etc/runit/runsvdir
install -d ${DESTDIR}/etc/runit/core-services
install -d ${DESTDIR}/etc/runit/shutdown-services
install -m644 core-services/*.sh ${DESTDIR}/etc/runit/core-services
install -m644 shutdown-services/*.sh ${DESTDIR}/etc/runit/shutdown-services
install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
install -m644 functions $(DESTDIR)/etc/runit
install -m644 crypt.awk ${DESTDIR}/etc/runit
Expand Down
3 changes: 3 additions & 0 deletions shutdown-services/00-stop-services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
msg "Waiting for services to stop..."
sv force-stop /run/runit/service/*
sv exit /run/runit/service/*
2 changes: 2 additions & 0 deletions shutdown-services/01-random-seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msg "Saving random seed..."
( umask 077; bytes=$(cat /proc/sys/kernel/random/poolsize) || bytes=512; dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=$bytes >/dev/null 2>&1 )
6 changes: 6 additions & 0 deletions shutdown-services/02-hwclock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if [ -z "$VIRTUALIZATION" ] && [ -n "$HARDWARECLOCK" ]; then
msg "Saving hardware clock..."
hwclock --systohc ${HARDWARECLOCK:+--$(echo $HARDWARECLOCK |tr A-Z a-z)}
fi

halt -w # for utmp
4 changes: 4 additions & 0 deletions shutdown-services/03-stop-udev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if [ -z "$VIRTUALIZATION" ]; then
msg "Stopping udev..."
udevadm control --exit
fi
5 changes: 5 additions & 0 deletions shutdown-services/04-killall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
msg "Sending TERM signal to processes..."
pkill --inverse -s0,1 -TERM
sleep 1
msg "Sending KILL signal to processes..."
pkill --inverse -s0,1 -KILL
7 changes: 7 additions & 0 deletions shutdown-services/97-mount-ro.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if [ -z "$VIRTUALIZATION" ]; then
msg "Unmounting filesystems, disabling swap..."
swapoff -a
umount -r -a -t nosysfs,noproc,nodevtmpfs,notmpfs
msg "Remounting rootfs read-only..."
mount -o remount,ro /
fi

0 comments on commit f8a8bc6

Please sign in to comment.