萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> BSD關機重啟腳本/etc/rc.d/rc.0

BSD關機重啟腳本/etc/rc.d/rc.0

  BSD關機重啟腳本/etc/rc.d/rc.0

  #!/bin/sh

  # 關閉所有程序

  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

  # 保存隨想數種子

  echo "Saving random seed to a temporary file..."

  /bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2>/dev/null

  # 保存系統時鐘

  echo "Saving the system time to hardware clock..."

  /sbin/hwclock --systohc --utc

  # 卸載遠程系統

  echo "Unmounting remote filesystems..."

  /bin/umount -a -f -tnfs

  # -w參數並不會真的重開機,只是把記錄寫到 /var/log/wtmp 檔案裡

  # 0級和6級這裡是一個文件,通過腳本名來判斷是關機還是重啟,所以有了下面結構。

  case "$0" in

  *6)

  /sbin/reboot -w

  ;;

  *0)

  /sbin/halt -w

  ;;

  esac

  # 以只讀方式掛載系統

  echo "Remounting root filesystem read-only..."

  /bin/mount -n -o remount,ro /

  #將刷新緩存,保存數據

  echo "Flushing filesystem buffers..."

  /bin/sync

  #卸載本地文件系統

  echo "Unmounting local filesystems..."

  /bin/umount -a -tnonfs

  # 關機

  case "$0" in

  *6)

  echo "Please stand by while rebooting..."

  /sbin/reboot -d -f -i

  ;;

  *0)

  echo "Bye..."

  /sbin/halt -d -f -p

  ;;

  esac

copyright © 萬盛學電腦網 all rights reserved