#!/bin/bash
### BEGIN INIT INFO
# Provides:		ccgfs-super
# Required-Start:
# Should-Start:		$remote_fs $network
# Required-Stop:
# Default-Start:	3 5
# Default-Stop:		0 1 6
# Short-Description:	ccgfs storage and mount daemon
# Description:		ccgfs storage and mount daemon
### END INIT INFO

if [ -e /etc/rc.status ]; then
	. /etc/rc.status;
	rc_reset;
else
	function rc_failed()
	{
		_saved=$?;
		return 1;
	}
	function rc_status()
	{
		_saved=$?;
		case "$_saved" in
			0) echo -e "\e[150C\e[10D\e[1;32m""done""\e[0m";;
			*) echo -e "\e[150C\e[10D\e[1;31m""failed""\e[0m";;
		esac;
		return $?;
	}
	function rc_exit()
	{
		return $?;
	}
	function rc_reset()
	{
		return 0;
	}
fi;

verbose="-v";
prefix="/usr";
exec_prefix="/usr";
daemon_bin="/usr/sbin/ccgfs-super";
config_file="/etc/ccgfs-super.xml";
pid_file="/var/run/ccgfs-super.pid";

rc_reset;

case "$1" in
    (start)
	[ -n "$verbose" ] && echo -n "Starting ccgfs-super";
	checkproc "$daemon_bin" && echo " (already running)";
	startproc -sp "$pid_file" -- \
		"$daemon_bin" -f "$config_file" -p "$pid_file";
	rc_status -v;
	;;
    (stop)
	echo -n "Stopping ccgfs-super";
	checkproc "$daemon_bin" || echo -n " (not running)";
	killproc -p "$pid_file" "$daemon_bin";
	rc_status -v;
	;;
    (status)
	echo -n "Checking for ccgfs-super";
	checkproc -p "$pid_file" "$daemon_bin";
	rc_status -v;
	;;
    (reload)
	echo -n "Reloading ccgfs-super";
	killproc -p "$pid_file" -HUP "$daemon_bin";
	rc_status -v;
	;;
    (restart)
	"$0" stop;
	"$0" start;
	rc_status;
	;;
    (try-restart)
	"$0" status >/dev/null && "$0" restart;
	rc_status;
	;;
    (*)
	echo "Usage: $0 {start|stop|status|reload|restart|try-restart}";
	exit 1;
	;;
esac;

rc_exit;
