#! /bin/sh
#
# $Id: swapd.init,v 0.4.0a-alt1 2004/07/12 15:19:09 gns Exp $
#
# swapd         Monitors swap usage and creates additional swap space.
#
# chkconfig: 345 98 02
# description: swapd is a simple daemon process to monitor swap usage. \
#	        It create additional swap files if necessary.
# processname: swapd
# pidfile: /var/run/swapd.pid
# config: /etc/swapd.conf
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

# Source networking configuration.                                                                                                           
#SourceIfNotEmpty /etc/sysconfig/network

# Source config.                                                                                                                             
#SourceIfNotEmpty /etc/sysconfig/monit

[ -r /etc/swapd.conf ] || exit

PIDFILE=/var/run/swapd.pid
LOCKFILE=/var/lock/subsys/swapd
RETVAL=0

start ()
{
	start_daemon --lockfile "$LOCKFILE" --expect-user root -- swapd --pidfile "$PIDFILE"  
	RETVAL=$?
	return $RETVAL

}

stop ()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- swapd
	RETVAL=$?
	return $RETVAL
}

restart ()
{
	stop
	start
}

reload ()
{
	msg_reloading swapd
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- swapd
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
###		status --expect-user root -- swapd
		status --pidfile "$PIDFILE" --expect-user root -- swapd
		# swapd status
		RETVAL=$?
	
		;;
	restart)
		restart
		;;
	reload)
		reload
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1

esac

exit $RETVAL
