#! /bin/sh
### BEGIN INIT INFO
# Provides:          swapspace
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Linux init script for swapspace
# Description: Starts and stops swapspace daemon, a dynamic swapspace manager
### END INIT INFO

# Swapspace is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# Swapspace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with swapspace; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

. /lib/lsb/init-functions

set -e
PREFIX="/usr/"
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
DESC="dynamic swap manager"
NAME=swapspace
DAEMON="$PREFIX/sbin/$NAME"
PIDFILE="/var/run/$NAME.pid"

PARANOID="no"

# Exit gracefully if the package has been removed
test -x "$DAEMON" || exit 0

PIDOPT="--pidfile $PIDFILE"
#DAEMON_ARGS="--daemon $PIDOPT"
DAEMON_ARGS="-d -p"
STDOPTS="--quiet $PIDOPT"

if test "$PARANOID" = "yes" ; then
	DAEMON_ARGS = "$DAEMON_ARGS -P"
fi

STARTCMD="start-stop-daemon --start --oknodo --exec $DAEMON $STDOPTS -- $DAEMON_ARGS"
STOPCMD="start-stop-daemon --stop --oknodo $STDOPTS"


case "$1" in
  start)
	log_daemon_msg "Starting $DESC" "$NAME"
	$STARTCMD >/dev/null
	log_end_msg $?
	;;
  stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	set +e
	$STOPCMD
	exit_code=$?
	set -e
	if test "$PARANOID" = "yes" ; then
		# Make an extra attempt to clean up any remaining swapfiles
		$DAEMON $DAEMON_ARGS -e
	fi
	log_end_msg $exit_code
	;;
  reload|restart|force-reload)
    $0 stop
	$0 start
	;;
  status)
    status_of_proc -p "$PIDFILE" "$DAEMON" swapspace && exit 0 || exit $?
	;;
  *)
	echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0

