core/rc/rc.shutdown
2024-07-19 21:01:30 +02:00

68 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
#
# /etc/rc.shutdown: system shutdown script
#
# Load configuration
. /etc/rc.conf
# Load functions
. /etc/rc.functions
# Set linefeed mode to avoid staircase effect
/bin/stty onlcr
printf "\n%s\n" "The system is coming down. Please wait."
if [ "$PREVLEVEL" = "2" ]; then
# Shutdown services
printf "$(BOLD "Stopping services:")"
if [ "${SERVICES[*]}" ]; then
for service in "${SERVICES[@]}"; do
R_SERVICES=("$service" "${R_SERVICES[@]}")
done
for service in "${R_SERVICES[@]}"; do
printf " %s" "$service"
/etc/rc.d/$service stop &> /tmp/rc.$$ || printf "$(BOLD "$(RED "[ERROR]")")"
/usr/bin/logger -t $service -f /tmp/rc.$$
/bin/rm -f /tmp/rc.$$
done
fi
printf '\n'
fi
# Terminate all processes
/sbin/killall5 -15
/bin/sleep 5
/sbin/killall5 -9
# Save random seed
/bin/dd if=/dev/urandom of=/var/lib/urandom/seed count=1 2> /dev/null
# Save system clock
/sbin/hwclock --systohc
# Write to wtmp file before unmounting
/sbin/halt -w
# Turn off swap
/sbin/swapoff -a
# Unmount file systems
/bin/umount -a -d -r -t nosysfs,noproc,nodevtmpfs
if [ -x /sbin/lvm ]; then
/sbin/vgchange --ignorelockingfailure -a n
fi
/bin/umount -a -r
# Remount root filesystem read-only
/bin/mount -o remount,ro /
# Power off or reboot
if [ "$RUNLEVEL" = "0" ]; then
/sbin/poweroff -d -f -i
else
/sbin/reboot -d -f -i
fi
# End of file