aboutsummaryrefslogtreecommitdiff
path: root/rc.shutdown
blob: 848f11403d1a08a0bd0c373286bd92f522da63d2 (plain)
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
#!/bin/sh

. /etc/init/rc.conf
. INITDIR/rc.lib

PATH=/sbin:/bin:/usr/sbin:/usr/bin

out "Waiting for services to stop..."; {
    sv -w196 force-stop /var/service/*
    sv exit /var/service/*
}

out "Running pre shutdown hooks..."
for file in /etc/init/*.pre.shutdown ; do
	[ -f "$file" ] && \
		out "Running $file" && . "$file"
done

out "Saving random seed..."; {
    dd count=1 bs=512 if=/dev/random of=/var/random.seed
}

out "Sending TERM signal to all processes..."; {
    killall5 -TERM
    sleep 1
}

out "Sending KILL signal to all processes..."; {
    killall5 -KILL
}

out "Unmounting filesystems and disabling swap..."
out "Remounting rootfs as readonly"; {
    swapoff -a
    umount -rat nosysfs,noproc,nodevtmpfs,notmpfs
    mount -o remount,ro /

    sync
}

out "Deactivating dmcrypt devices (if any exist)."; {
    [ -x /bin/cryptsetup ] && [ -x /bin/dmsetup ] && {
        dmsetup ls --target crypt \
                   --exec "dmsetup info -c --noheadings -o open,name" |
        while read -r drive; do
            [ "${drive%%:*}" = "0" ] && cryptsetup close "${drive##*:}"
        done
    }
}

out "Running post shutdown hooks...";
for file in /etc/init/*.post.shutdown ; do
	[ -f "$file" ] && \
		out "Running $file" && . "$file"
done

case "$1" in reboot) shalt r ;; poweroff) shalt p ;; esac