#! /bin/sh
#
# preload init.d script
### BEGIN INIT INFO
# Provides:          preload.sourceforge.net
# Required-Start:    $local_fs $remote_fs $time
# Required-Stop:     $local_fs $remote_fs $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Adaptive readahead daemon
# Description:       Analyzes what applications users run and tries to predict
#                    what they would like to run and loads them into memory
#                    beforehand.
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/preload
NAME=preload
DESC=preload
DAEMON_OPTS="-s /var/lib/preload/preload.state $DAEMON_OPTS"

# Include preload defaults if available
if [ -f /etc/default/preload ] ; then
	. /etc/default/preload
fi

DAEMON_OPTS="$DAEMON_OPTS $OPTIONS"

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	if start-stop-daemon --start --quiet -u 0 $PRELOAD_IOSCHED --exec $DAEMON -- $DAEMON_OPTS; then
	    echo "$NAME."
	else
	    echo "already running."
	fi
	;;
  stop)
	echo -n "Stopping $DESC: "
	if start-stop-daemon --stop --retry 1 --quiet -u 0 --exec $DAEMON ; then
	    echo "$NAME."
	else
	    echo "not running."
	fi
	;;
  reload|force-reload)
	echo "Reloading $DESC configuration files."
	start-stop-daemon --stop $PRELOAD_IOSCHED --signal 1 --quiet -u 0 --exec $DAEMON
  	;;
  restart)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --oknodo --retry 1 --quiet -u 0 --exec $DAEMON
	start-stop-daemon --start --quiet -u 0 $PRELOAD_IOSCHED --exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
