#!/bin/bash
### BEGIN INIT INFO
# Provides:          svnwcsub
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SvnWcSub
# Description:       start SvnWcSub daemon
#### END INIT INFO

. /lib/init/vars.sh
. /lib/lsb/init-functions

svnwcsub_user=${svnwcsub_user-"svnwc"}
svnwcsub_group=${svnwcsub_group-"svnwc"}
svnwcsub_pidfile=${svnwcsub_pidfile-"/var/run/svnwcsub.pid"}
svnwcsub_config=${svnwcsub_config-"/etc/svnwcsub.conf"}
svnwcsub_logfile=${svnwcsub_logfile-"/var/log/svnwcsub/svnwcsub.log"}
pidfile="${svnwcsub_pidfile}"

SVNWCSUB_CMD="/opt/svnpubsub/svnwcsub.py \
              --daemon \
              --logfile=${svnwcsub_logfile} \
              --pidfile=${pidfile} \
              --uid=${svnwcsub_user} --gid=${svnwcsub_group} \
              --umask=002 \
              ${svnwcsub_config} "

RETVAL=0
 
start() {
    echo "Starting SvnWcSub Server: "
    $SVNWCSUB_CMD
    RETVAL=$?
    [ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
    return $RETVAL
}
 
stop() {
    echo "Stopping SvnWcSub Server: "
    THE_PID=`cat ${pidfile}`
    kill $THE_PID
    RETVAL=$?
    [ $RETVAL -eq 0 ] && echo "ok" || echo "failed"
    return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $RETVAL
