#!/bin/bash
### BEGIN INIT INFO
# Provides:          lvectl
# Required-Start:    mountkernfs lve udev $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: lvectl init
# Description:       Load/unload lve modules
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

prog="lvectl"

RETVAL=0

destroy_all_ve(){
    # lvectl flush all
    echo "not supported in this version"
    RETVAL=$?
    return $RETVAL
}

start() {
    # Do not start if there is no config file.
    [ ! -f /proc/lve/list ] && return 6
    log_action_msg "Starting lvectl"
    lvectl start
    lvectl --apply all
    RETVAL=$?
    sleep 3
    log_end_msg $RETVAL
    return $RETVAL
}

stop() {
    log_action_msg "Stopping lvectl"
    return 0
}

reload() {
    log_action_msg "Reloading lvectl"
    lvectl apply
    RETVAL=$?
    sleep 3
    log_end_msg $RETVAL
    return $RETVAL
}

# See how we were called.
case "$1" in
  start)
      start
  ;;
  stop)
      stop
  ;;
  restart)
      stop
      start
  ;;
  reload|force-reload)
      reload
  ;;
  *)
            echo $"Usage: $prog {start|stop|restart|reload|force-reload}"
            exit 3
esac

RETVAL=$?

exit $RETVAL
