#!/bin/bash
#
# intersync   This shell script takes care of starting and stopping InterSync
#
# chkconfig: 2345 99 1
# description: InterSync is the InterMezzo file system synchronization daemon.
# processname: intersync
# config: /etc/intermezzo/intersync.conf
# pidfile: /var/run/intersync.pid

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

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

# Source InterSync configureation.
if [ -f /etc/sysconfig/intersync ] ; then
	. /etc/sysconfig/intersync
else
	CLIENT_OPTS=
        CACHE=/var/intermezzo/cache
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/bin/intersync ] || exit 0

start() {
        # Start daemons.
        echo -n $"Starting intersync: "
        # FIXME: Have intersync actually daemonize and leave a pid file.
        echo -n intersync
        /usr/bin/intersync $CLIENT_OPTS $CACHE &
        RETVAL=$?
        echo "$!" > /var/run/intersync.pid
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/intersync
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down intersync: "
        kill `cat /var/run/intersync.pid`
	RETVAL=$?
        [ $RETVAL = 0 ] && echo -n intersync
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/intersync
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
	;;
  status)
	status intersync
	;;
  *)
	echo $"Usage: intersync {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL

