#!/bin/sh
#
# GNUnet         Start/Stop GNUnet server
#
# chkconfig: 	345 89 14
# description:	GNUnet is an anonymous distributed secure network \
#               this server is required to connect to the network, \
#               it will open a TCP port to communicate with the \
#               GUI and an UDP port to communicate with the world. \
#               The configuration file /etc/gnunet.conf will be used.
#
#
# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

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

# Sanity check
[ -e /etc/gnunet.conf ] || exit 0

RETVAL=0

start() {
  	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/gnunet ]; then
		msg_starting "GNUnet"
		daemon gnunetd -u gnunet
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/gnunet
	else
		msg_already_running "GNUnet"
	fi
}

stop() {
	if [ -f /var/lock/subsys/gnunet ]; then
		msg_stopping "GNUnet"
		killproc gnunetd
		rm -f /var/lock/subsys/gnunet >/dev/null 2>&1
	else
		msg_not_running "GNUnet"
	fi
}

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

exit $RETVAL
