BSD關(guān)機(jī)重啟腳本/etc/rc.d/rc.0
BSD關(guān)機(jī)重啟腳本/etc/rc.d/rc.0
#!/bin/sh
# 關(guān)閉所有程序
echo "Sending all processes the TERM signal..."
/sbin/killall5 -15
sleep 1
echo "Sending all processes the KILL signal..."
/sbin/killall5 -9
sleep 1
# 卸載swap
echo "Deactivating swap partitions..."
/sbin/swapoff -a
# 保存隨想數(shù)種子
echo "Saving random seed to a temporary file..."
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null
# 保存系統(tǒng)時(shí)鐘
echo "Saving the system time to hardware clock..."
/sbin/hwclock --systohc --utc
# 卸載遠(yuǎn)程系統(tǒng)
echo "Unmounting remote filesystems..."
/bin/umount -a -f -tnfs
# -w參數(shù)并不會(huì)真的重開機(jī),只是把記錄寫到 /var/log/wtmp 檔案里
# 0級(jí)和6級(jí)這里是一個(gè)文件,通過腳本名來判斷是關(guān)機(jī)還是重啟,所以有了下面結(jié)構(gòu)。
case "$0" in
*6)
/sbin/reboot -w
;;
*0)
/sbin/halt -w
;;
esac
# 以只讀方式掛載系統(tǒng)
echo "Remounting root filesystem read-only..."
/bin/mount -n -o remount,ro /
#將刷新緩存,保存數(shù)據(jù)
echo "Flushing filesystem buffers..."
/bin/sync
#卸載本地文件系統(tǒng)
echo "Unmounting local filesystems..."
/bin/umount -a -tnonfs
# 關(guān)機(jī)
case "$0" in
*6)
echo "Please stand by while rebooting..."
/sbin/reboot -d -f -i
;;
*0)
echo "Bye..."
/sbin/halt -d -f -p
;;
esac