#!/bin/sh

### BEGIN INIT INFO
# Provides: landscape-client
# Required-Start: $local_fs $remote_fs hal dbus
# Required-Stop: $local_fs $remote_fs hal dbus
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Landscape client daemons
# Description: The Landscape client daemons are needed so the
#              Landscape server can manage a computer.
### END INIT INFO

LANDSCAPE_DEFAULTS=/etc/default/landscape-client
NAME=landscape-client
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
RUN=0 # overridden in /etc/default/landscape-client

[ -f $DAEMON ] || exit 0

. /lib/lsb/init-functions
[ -f $LANDSCAPE_DEFAULTS ] && . $LANDSCAPE_DEFAULTS

if [ $RUN -eq 0 ]; then
	echo "$NAME is not configured, please run landscape-config."
	exit 0
fi

case "$1" in
	start)
		log_daemon_msg "Starting the $NAME daemon"
		start-stop-daemon --start --quiet --oknodo --startas $DAEMON --pidfile $PIDFILE -- --daemon --pid-file $PIDFILE
		log_end_msg $?
		;;

	stop)
		log_daemon_msg "Stopping $NAME daemon"
		start-stop-daemon --retry 30 --stop --quiet --pidfile $PIDFILE
		log_end_msg $?
		;;

	status)
		# We want to maintain backward compatibility with Dapper,
		# so we're not going to use status_of_proc()
		pidofproc -p $PIDFILE $DAEMON >/dev/null
		status=$?
		if [ $status -eq 0 ]; then
			log_success_msg "$NAME is running"
		else
			log_failure_msg "$NAME is not running"
		fi
		exit $status
		;;

	restart|force-reload)
		$0 stop && $0 start
		;;

	*)
		echo "Usage: $0 {start|stop|status|restart|force-reload}"
		exit 1
		;;
esac

exit 0
