Advertisement
Guest User

rc.shutdown

a guest
Jun 25th, 2010
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.06 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. run_hook shutdown_start
  10.  
  11. # avoid staircase effect
  12. /bin/stty onlcr
  13.  
  14. echo " "
  15. printhl "Initiating Shutdown..."
  16. echo " "
  17.  
  18. # avoid NIS hanging syslog-ng on shutdown by unsetting the domainname
  19. if [ -x /bin/domainname ]; then
  20.     /bin/domainname ""
  21. fi
  22.  
  23. if [ -x /etc/rc.local.shutdown ]; then
  24.     /etc/rc.local.shutdown
  25. fi
  26.  
  27. # Find daemons NOT in the DAEMONS array. Shut these down first
  28. if [ -d /var/run/daemons ]; then
  29.     for daemon in $(/bin/ls -1t /var/run/daemons); do
  30.         if ! in_array $daemon ${DAEMONS[@]}; then
  31.             stop_daemon $daemon
  32.         fi
  33.     done
  34. fi
  35. # Shutdown daemons in reverse order
  36. let i=${#DAEMONS[@]}-1
  37. while [ $i -ge 0 ]; do
  38.     if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
  39.         ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@}
  40.     fi
  41.     let i=i-1
  42. done
  43.  
  44. # Terminate all processes
  45. stat_busy "Sending SIGTERM To Processes"
  46. run_hook shutdown_prekillall
  47. /sbin/killall5 -15 &> /dev/null
  48. /bin/sleep 5
  49. stat_done
  50.  
  51. stat_busy "Sending SIGKILL To Processes"
  52. /sbin/killall5 -9 &> /dev/null
  53. /bin/sleep 1
  54. stat_done
  55.  
  56. run_hook shutdown_postkillall
  57.  
  58. stat_busy "Saving Random Seed"
  59. RANDOM_SEED=/var/lib/misc/random-seed
  60. [ -d $(dirname $RANDOM_SEED) ] || mkdir -p $(dirname $RANDOM_SEED)
  61. : > $RANDOM_SEED
  62. /bin/chmod 0600 $RANDOM_SEED
  63. POOL_FILE=/proc/sys/kernel/random/poolsize
  64. if [ -r $POOL_FILE ]; then
  65.     POOL_SIZE=$(/bin/cat $POOL_FILE)
  66. else
  67.     POOL_SIZE=512
  68. fi
  69. /bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null
  70. stat_done
  71.  
  72. stat_busy "Saving System Clock"
  73. if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then
  74.     /bin/rm -f /etc/localtime
  75.     /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
  76. fi
  77.  
  78. HWCLOCK_PARAMS="--systohc"
  79. if [ "$HARDWARECLOCK" = "UTC" ]; then
  80.     HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc"
  81. elif [ "$HARDWARECLOCK" = "localtime" ]; then
  82.     HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime"
  83. else
  84.     HWCLOCK_PARAMS=""
  85. fi
  86. if [ -n "$HWCLOCK_PARAMS" ]; then
  87.     /sbin/hwclock $HWCLOCK_PARAMS
  88. fi
  89. stat_done
  90.  
  91. # removing psmouse module to fix some reboot issues on newer laptops
  92. /sbin/modprobe -r psmouse >/dev/null 2>&1
  93.  
  94. # Write to wtmp file before unmounting
  95. /sbin/halt -w
  96.  
  97. stat_busy "Deactivating Swap"
  98. /sbin/swapoff -a
  99. stat_done
  100.  
  101. stat_busy "Unmounting Filesystems"
  102. /bin/umount -a -r -t noramfs,notmpfs,nosysfs,noproc,nodevtmpfs -O no_netdev
  103. stat_done
  104.  
  105. # Kill non-root encrypted partition mappings
  106. if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then
  107.     stat_busy "Deactivating encrypted volumes:"
  108.     # Arch cryptsetup packages traditionally contained the binaries
  109.     #  /usr/sbin/cryptsetup
  110.     #  /sbin/cryptsetup.static
  111.     # By default, initscripts used the /sbin/cryptsetup.static.
  112.     # Newer packages will only have /sbin/cryptsetup and no static binary
  113.     # This ensures maximal compatibility with the old and new layout
  114.     if [ -x /sbin/cryptsetup ]; then
  115.         CS=/sbin/cryptsetup
  116.     elif [ -x /usr/sbin/cryptsetup ]; then
  117.         CS=/usr/sbin/cryptsetup
  118.     else
  119.         CS=/sbin/cryptsetup.static
  120.     fi
  121.     do_uncrypt() {
  122.         if [ $# -ge 3 ]; then
  123.             if [ -b /dev/mapper/$1 ] ;then
  124.                 stat_append "${1}.."
  125.                 $CS remove $1 >/dev/null 2>&1
  126.                 if [ $? -ne 0 ]; then
  127.                     stat_append "failed "
  128.                 else
  129.                     stat_append "ok "
  130.                 fi
  131.             fi
  132.         fi
  133.     }
  134.     while read line; do
  135.         eval do_uncrypt "$line"
  136.     done </etc/crypttab
  137.     stat_done
  138. fi
  139.  
  140. if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
  141.     if [ -x /sbin/lvm -a -d /sys/block ]; then
  142.         stat_busy "Deactivating LVM2 groups"
  143.         /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1
  144.         stat_done
  145.     fi
  146. fi
  147.  
  148. stat_busy "Remounting Root Filesystem Read-only"
  149. /bin/mount -n -o remount,ro /
  150. stat_done
  151.  
  152. run_hook shutdown_poweroff
  153.  
  154. # Power off or reboot
  155. if [ "$RUNLEVEL" = "0" ]; then
  156.     printsep
  157.     printhl "${C_H2}POWER OFF"
  158.     /sbin/poweroff -d -f -h -i
  159. else
  160.     printsep
  161.     printhl "${C_H2}REBOOTING"
  162.     # if kexec is installed and a kernel is loaded, use it
  163.     [ -x /sbin/kexec ] && /sbin/kexec -e > /dev/null 2>&1
  164.     /sbin/reboot -d -f -i
  165. fi
  166.  
  167. # End of file
  168. # vim: set ts=2 sw=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement