3 # Prepare to halt or reboot the system
5 # Copyright (c) 2017-2020 Matias Fonzo, <selk@dragora.org>.
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
22 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/sbin
:/usr
/sbin
:/bin
:/usr
/bin
24 # Set linefeed mode to avoid staircase effect
27 # Be immune to the following signals
28 trap "" HUP INT QUIT ABRT TERM
32 if grep -q '^RC_HWCLOCK=local' /etc
/rc.conf
34 echo "(Shutdown) Saving hardware clock in local time"
35 hwclock --systohc --localtime
37 echo "(Shutdown) Saving hardware clock in UTC"
38 hwclock --systohc --utc
41 # Stop any quota system (if needed)
43 if egrep -q -m 1 '(usr|grp)quota' /etc
/fstab
45 if type quotaoff
> /dev
/null
47 echo "(Shutdown) Set any quota file system to OFF"
52 # Save the random number generator, see random(4)
54 echo "(Shutdown) Saving random number generator"
55 echo " /dev/urandom <-> /etc/random-seed ..."
57 # Read pool size from /proc or assign a default value
58 read -r < /proc
/sys
/kernel
/random
/poolsize size || size
=512
60 # Save seed file containing the whole entropy pool
61 dd if=/dev
/urandom of
=/etc
/random-seed count
=1 bs
=${size} 2> /dev
/null
62 unset size
; chmod 600 -- /etc
/random-seed
64 # Try to write a login record (at /var/log/wtmp)
67 # Flush file system buffers, update super block
70 # Stop FUSE filesystem
71 if test -x /etc
/rc.d
/rc.fuse
73 /etc
/rc.d
/rc.fuse stop
> /dev
/null
76 # Kill all processes, except the one that is currently running
80 echo "(Shutdown) Deactivating swap devices"
83 echo "(Shutdown) Unmounting local and remote file systems"
88 echo "(Shutdown) Remounting root filesystem in read-only mode"
89 mount
-n -o remount
,ro
/
91 # Wait for completion of all the processes
94 # Reboot, or halt the system