#!/bin/bash
#
# autoswap-dervice	Summary of the service.
#
# chkconfig: 345 05 97
# description:	autoswap on and swapoff service
#
# processname: autoswap-service


start()
{
    echo -en "Start swaping system\n "
    swapon -a $parts

#   modprobe overlay ?


    swapon --show
    RETVAL=0
    return $RETVAL
}
stop()
{

    swapoff -a $parts


    RETVAL=0
    return $RETVAL
}
status()
{
   swapon --show
   RETVAL=$?
   return $RETVAL
}

parts=$(blkid -t TYPE=swap -o device)

if [ -z "$1" ];then
    int=start
else
    int="$1"
fi


case "$int" in
  start)
    start
    ;;

  stop)
    echo -n "Stop $0 "
    stop
    ;;

  on)
    echo -n "Start $0 "
    start
    ;;

  off)
    echo -n "Stop $0 "
    stop
    ;;
 status)
   echo -n "Status $0 "
   status
   ;;
  restart)
    echo -n "Restart $0 "
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    RETVAL=1
    ;;
esac
exit $RETVAL
