#!/bin/sh
#
# git-daemon	git-daemon tcp daemon for git
#
# chkconfig:	345 90 25
#
# description:	git-daemon is a simple tcp daemon that serves git repositories
#
# $Id: git-core.init,v 1.4 2008/11/16 11:41:16 megabajt Exp $

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

# Get network config
. /etc/sysconfig/network

DAEMON_OPTS="--syslog"

# Get service config - may override defaults
[ -f /etc/sysconfig/git-daemon ] && . /etc/sysconfig/git-daemon

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down git-daemon
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/git-daemon ]; then
		msg_starting git-daemon
		daemon --fork /usr/lib/git-core/git-daemon $DAEMON_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/git-daemon
	else
		msg_already_running git-daemon
	fi
}

stop() {
	if [ -f /var/lock/subsys/git-daemon ]; then
		# Stop daemons.
		msg_stopping git-daemon
		killproc git-daemon
		rm -f /var/lock/subsys/git-daemon
	else
		msg_not_running git-daemon
	fi
}

reload() {
	if [ -f /var/lock/subsys/git-daemon ]; then
		msg_reloading git-daemon
		killproc git-daemon -HUP
		RETVAL=$?
	else
		msg_not_running git-daemon
		RETVAL=7
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/git-daemon ]; then
		stop
		start
	else
		msg_not_running git-daemon
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
  	reload
	;;
  status)
	status git-daemon
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
