#! /bin/sh
#
# atop init script
#

### BEGIN INIT INFO
# Provides:          atop
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Monitor for system resources and process activity
# Description:       Atop is an ASCII full-screen performance monitor,
#                    similar to the top command, but atop only shows
#                    the active system-resources and processes, and
#                    only shows the deviations since the previous
#                    interval.
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
ATOP_OPTS="-a"
ATOP_PERIOD=600

if test -f /etc/default/atop; then
    . /etc/default/atop
fi

DAEMON=/usr/bin/atop
PIDFILE=/var/run/atop.pid
LOGFILE=/var/log/atop/atop_$(date +%Y%m%d)
DARGS="$ATOP_OPTS -w $LOGFILE $ATOP_PERIOD"
NAME=atop
DESC="atop system monitor"

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --pidfile $PIDFILE --make-pidfile --start --background --quiet --exec $DAEMON -- $DARGS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --pidfile $PIDFILE --stop --quiet --retry 5 --oknodo --exec $DAEMON -- $DARGS
	echo "$NAME."
	;;
  #reload)
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: "
	start-stop-daemon --pidfile $PIDFILE --stop --quiet --retry 5 --oknodo --exec $DAEMON -- $DARGS
	start-stop-daemon --pidfile $PIDFILE --make-pidfile --start --background --quiet --exec $DAEMON -- $DARGS
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
