home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20101108.etc.tar.gz / bradford.20101108.etc.tar / etc / init.d / boot.swap < prev    next >
Text File  |  2005-11-23  |  2KB  |  110 lines

  1. #! /bin/bash
  2. #
  3. # Copyright (c) 2001-2005 SuSE Linux AG, Nuernberg, Germany.
  4. # All rights reserved.
  5. #
  6. # /etc/init.d/boot.swap
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides:          boot.swap
  10. # Required-Start:    boot.localfs
  11. # Should-Start: boot.lvm boot.crypto boot.lkcd
  12. # Required-Stop:
  13. # Default-Start:     B
  14. # Default-Stop:
  15. # Description:       start rest of swap devices
  16. ### END INIT INFO
  17.  
  18. . /etc/rc.status
  19. . /etc/sysconfig/kernel
  20.  
  21. get_swap_id() {
  22.     local line dev min type;
  23.     type -p fdisk >/dev/null || return
  24.     fdisk -l 2>&1 | while read line; do
  25.     case "$line" in
  26.     /*Linux\ [sS]wap*)
  27.         echo "${line%% *}"
  28.         ;;
  29.     Disk\ /dev/*\ doesn*)
  30.         dev="${line##*/}"
  31.         dev="${dev%% *}"
  32.         type -p parted >/dev/null || continue
  33.         while read min type; do
  34.         case "$type" in
  35.         *type=82|*type=82,*) echo /dev/${dev}${min}
  36.         esac
  37.         done < <(parted -s /dev/$dev print quit 2>/dev/null)
  38.         ;;
  39.     esac
  40.     done
  41. }
  42.  
  43. check_swap_sig () {
  44.     local part="$(get_swap_id)"
  45.     local where what type rest p c
  46.     while read  where what type rest ; do
  47.     test "$type" = "swap" || continue
  48.     c=continue
  49.     for p in $part ; do
  50.         test "$p" = "$where" && c=true
  51.     done
  52.     $c
  53.     case "$(dd if=$where bs=1 count=6 skip=4086 2>/dev/null)" in
  54.     S1SUSP|S2SUSP) mkswap $where
  55.     esac
  56.     done < /etc/fstab
  57. }
  58.  
  59. rc_reset
  60.  
  61. case "$1" in
  62.     start)
  63.     #
  64.     # After mounting we may activate swap files in /etc/fstab
  65.     # .. this should work know with the new swapon behavio(u)r
  66.     #
  67.     # Check for swap signature only if sysfs is not mounted
  68.     # (then we have no way of knowing if swsuspend is enabled)
  69.     # or if /sys/power exists (then we are sure it is enabled).
  70.     if [ ! -d "/sys/devices" ] || [ -d "/sys/power" ]; then
  71.         check_swap_sig
  72.     fi
  73.     echo "Activating remaining swap-devices in /etc/fstab..."
  74.     swapon -a &> /dev/null
  75.     rc_status -v1 -r
  76.     ;;
  77.     stop)
  78.     echo "Turning off swap"
  79.     sync ; sync
  80.     rc_reset
  81.     swapoff -a &> /dev/null
  82.     rc_status -v1 -r
  83.     # Something forgotten?
  84.     if test -r /proc/swaps ; then
  85.         # Use cat and a pipe because swapoff changes
  86.         # /proc/swaps during direct read call
  87.         cat /proc/swaps | \
  88.         while read des rest ; do
  89.         test "$des" = "Filename" && continue
  90.         swapoff $des &> /dev/null
  91.         done
  92.     fi
  93.     ;;
  94.     restart)
  95.     $0 stop
  96.     $0 start
  97.     ;;
  98.     status)
  99.     rc_failed 4
  100.     rc_status -v
  101.     ;;
  102.     *)
  103.     echo "Usage: $0 {start|stop|status|restart}"
  104.     exit 1
  105.     ;;
  106. esac
  107.  
  108. rc_exit
  109.  
  110.