-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3
executable file
·72 lines (61 loc) · 2.06 KB
/
3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
#
# Runit stage 3: halt or restart system
# based on VOID Linux (https://www.voidlinux.org)
exec 2>&1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
printf '=> Entering Runit stage 3 (%s)\n' "$0"
[ -r /etc/rc.conf ] && . /etc/rc.conf
if [ -e /run/runit.kexecreboot ]; then
if command -v kexec >/dev/null; then
printf '=> Rebooting using kexec\n'
else
printf 'ERROR: kexec reboot failed, rebooting normally\n'
fi
elif [ -e /run/runit.reboot ]; then
printf '=> Rebooting system\n'
else
printf '=> Shutdown and halt the system\n'
fi
printf '=> Waiting for services to stop...\n'
printf '=> Further messages will not be logged to disk\n'
pkill -f 'runsvdir.*/etc/service'
sv -w 5 force-stop /etc/service/*
sv exit /etc/service/*
# rotate boot.log file
mv -f /var/log/boot.log /var/log/boot.log.1
[ -x /etc/rc.shutdown ] && /etc/rc.shutdown
printf '=> Saving random seed...\n'
( 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 )
# Detect LXC virtualization containers
grep -q lxc /proc/self/environ >/dev/null && VIRTUALIZATION=1
if [ -z "$VIRTUALIZATION" ]; then
printf '=> Stopping udev...\n'
udevadm control --exit
fi
printf '=> Sending ALRM signal to processes...\n'
kill -14 -1
printf '=> Sending TERM signal to processes...\n'
pkill --inverse --session 0,1 -TERM
sleep 1
printf '=> Sending KILL signal to processes...\n'
pkill --inverse --session 0,1 -KILL
if [ -z "$VIRTUALIZATION" ]; then
printf '=> Unmounting filesystems, disabling swap...\n'
swapoff -a
umount -r -a -t noproc,nosysfs,nodevfs,nodevpts,nodevtmpfs,notmpfs &
sleep 0.5
# deactivate vgs
VGCHANGE="$(command -v vgchange)"
if [ "$VGCHANGE" ] && [ "$(vgs | wc -l)" -gt 0 ]; then
printf '=> Deactivating all LVM Volume Groups...\n'
$VGCHANGE -an
fi
# trigger kexec reboot
if [ -e /run/runit.kexecreboot ] && command -v kexec >/dev/null; then
printf '=> Triggering kexec reboot of the current kernel...\n'
kexec -e 2>/dev/null
# not reached when kexec was successful.
fi
fi