Advertisement
Guest User

Arch Linux - /etc/rc.shutdown

a guest
Sep 24th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.42 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # /etc/rc.shutdown
  4. #
  5.  
  6. . /etc/rc.conf
  7. . /etc/rc.d/functions
  8.  
  9. # avoid staircase effect
  10. stty onlcr
  11.  
  12. echo " "
  13. printhl "Initiating Shutdown..."
  14. echo " "
  15.  
  16. run_hook shutdown_start
  17.  
  18. [[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
  19.  
  20. stop_all_daemons
  21.  
  22. run_hook shutdown_prekillall
  23.  
  24. kill_all
  25.  
  26. run_hook shutdown_postkillall
  27.  
  28. stat_busy "Saving Random Seed"
  29.     RANDOM_SEED=/var/lib/misc/random-seed
  30.     install -TDm 0600 <(:) $RANDOM_SEED
  31.     POOL_FILE=/proc/sys/kernel/random/poolsize
  32.     if [[ -r $POOL_FILE ]]; then
  33.         read POOL_SIZE < $POOL_FILE
  34.     else
  35.         POOL_SIZE=512
  36.     fi
  37.     dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &>/dev/null
  38. stat_done
  39.  
  40. [[ $TIMEZONE ]] &&
  41.     status "Saving Time Zone" \
  42.         cp --remove-destination "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  43.  
  44. # Write to wtmp file before unmounting
  45. halt -w
  46.  
  47. status "Deactivating Swap" swapoff -a
  48.  
  49. # stop monitoring of lvm2 groups before unmounting filesystems
  50. [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
  51.     status "Deactivating monitoring of LVM2 groups" \
  52.         vgchange --monitor n &>/dev/null
  53.  
  54. # if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it
  55. status "Unmounting Filesystems" \
  56.     umount -a -r -t nodevtmpfs,notmpfs,nosysfs,noproc,nodevpts -O no_netdev
  57.  
  58. run_hook shutdown_postumount
  59.  
  60. # Kill non-root encrypted partition mappings
  61. if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then
  62.     stat_busy "Deactivating encrypted volumes:"
  63.         # Maybe someone has LVM on an encrypted block device
  64.         # executing an extra vgchange is errorless
  65.         [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null
  66.         do_lock() {
  67.             stat_append "${1}.."
  68.             if $CS remove "$1" &>/dev/null; then
  69.                 stat_append "ok "
  70.             else
  71.                 stat_append "failed "
  72.             fi
  73.         }
  74.         read_crypttab do_lock
  75.     stat_done
  76. fi
  77.  
  78. [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
  79.     status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null
  80.  
  81. status "Remounting Root Filesystem Read-only" \
  82.     mount -n -o remount,ro /
  83.  
  84. run_hook shutdown_poweroff
  85.  
  86. # Power off or reboot
  87. printsep
  88. if [[ $RUNLEVEL = 0 ]]; then
  89.     printhl "${C_H2}POWER OFF"
  90.     poweroff -d -f -h -i
  91. else
  92.     printhl "${C_H2}REBOOTING"
  93.     # if kexec is installed and a kernel is loaded, use it
  94.     [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null
  95.     reboot -d -f -i
  96. fi
  97.  
  98. # End of file
  99. # vim: set ts=2 sw=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement