学习啦 > 学习电脑 > 操作系统 > Linux教程 >

BSD关机重启脚本/etc/rc.d/rc.0

时间: 若木635 分享

  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

75556