Advertisement
Guest User

Untitled

a guest
Jun 30th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.21 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. status 'Saving Random Seed' /usr/lib/systemd/systemd-random-seed save
  23.  
  24. [[ $TIMEZONE ]] && status "Configuring Time Zone" set_timezone "$TIMEZONE"
  25.  
  26. # Write to wtmp file before unmounting
  27. halt -w
  28.  
  29. # stop monitoring of lvm2 groups before unmounting filesystems
  30. [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) ]] &&
  31.     status "Deactivating monitoring of LVM2 groups" vgchange --monitor n
  32.  
  33. # any future uevents can and should be ignored
  34. status "Shutting down UDev" udevadm control --exit
  35.  
  36. run_hook shutdown_prekillall
  37.  
  38. kill_all
  39.  
  40. run_hook shutdown_postkillall
  41.  
  42. run_hook shutdown_preumount
  43.  
  44. # unmount any non-api partitions that are backed by swap, we don't want to
  45. # move their contents into memory (waste of time and might caues OOM).
  46. status "Unmounting Swap-backed Filesystems" umount_all "tmpfs"
  47.  
  48. # almost everything is dead now, so the swap should hopefully be relatively
  49. # empty, and quick to switch off
  50. status "Deactivating Swap" swapoff -a
  51.  
  52. status "Unmounting Non-API Filesystems" umount_all
  53.  
  54. run_hook shutdown_postumount
  55.  
  56. # Kill non-root encrypted partition mappings
  57. if [[ -f /etc/crypttab ]] && type -p cryptsetup >/dev/null; then
  58.     stat_busy "Deactivating encrypted volumes:"
  59.         # Maybe someone has LVM on an encrypted block device
  60.         # executing an extra vgchange is errorless
  61.         [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null
  62.         do_lock() {
  63.             stat_append "${1}.."
  64.             if cryptsetup remove "$1" &>/dev/null; then
  65.                 stat_append "ok "
  66.             else
  67.                 stat_append "failed "
  68.             fi
  69.         }
  70.         read_crypttab do_lock
  71.     stat_done
  72. fi
  73.  
  74. [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
  75.     status "Deactivating LVM2 groups" vgchange --sysinit -a n &>/dev/null
  76.  
  77. run_hook shutdown_poweroff
  78.  
  79. if [[ -x /run/initramfs/shutdown ]]; then
  80.  
  81.     # decide what we want to do
  82.     if [[ $RUNLEVEL = 0 ]]; then
  83.         action="poweroff"
  84.     else
  85.         action="reboot"
  86.     fi
  87.  
  88.     # make /run/initrafs a mount
  89.     mount --bind /run/initramfs /run/initramfs
  90.  
  91.     # in case someone has shared our mountpoints, unshare them
  92.     mount --make-private /run/initramfs
  93.     mount --make-private /
  94.  
  95.     # bind all api mounts
  96.     mkdir -p /run/initramfs/{sys,proc,dev,run,oldroot}
  97.     mount --bind /sys /run/initramfs/sys
  98.     mount --bind /proc /run/initramfs/proc
  99.     mount --bind /dev /run/initramfs/dev
  100.     mount --bind /run /run/initramfs/run
  101.  
  102.     # enter shutdownramfs
  103.     cd /run/initramfs
  104.     pivot_root . oldroot
  105.  
  106.     #reexec init
  107.     /oldroot/sbin/init u
  108.  
  109.     # run /shutdown in the new root
  110.     exec chroot . /shutdown $action </dev/console >/dev/console 2>&1
  111.  
  112. else
  113.  
  114.     status "Remounting Root Filesystem Read-only" \
  115.         mount -o remount,ro /
  116.  
  117.     # Power off or reboot
  118.     printsep
  119.     if [[ $RUNLEVEL = 0 ]]; then
  120.         printhl "${C_H2}POWER OFF"
  121.         poweroff -d -f -h -i
  122.     else
  123.         printhl "${C_H2}REBOOTING"
  124.         # if kexec is installed and a kernel is loaded, use it
  125.         [[ -x $(type -P kexec) ]] && kexec -e &>/dev/null
  126.         reboot -d -f -i
  127.     fi
  128.  
  129. fi
  130.  
  131. # End of file
  132. # vim: set ts=2 sw=2 noet:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement