#!/bin/sh
#
# Startup script for GoFish
#
# chkconfig:	345 86 14
# description:	GoFish is a simple gopher / web server.
# processname:	gopherd
# pidfile:	/var/run/gopherd.pid
# config:	/etc/gofish.conf

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

# Get network config
. /etc/sysconfig/network

if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down gopherd
		exit 1
	fi
else
	exit 0
fi

# See how we were called.
case "$1" in
  start)
	if [ ! -f /var/lock/subsys/gopherd ]; then
		msg_starting gopherd
		# daemon gopherd -d	# gopherd writes to terminal ...
		busy
		termput hpa 45
		gopherd -d		# no error code returned even if fails
		sleep 1
		ok
		touch /var/lock/subsys/gopherd
	else
		msg_already_running gopherd
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/gopherd ]; then
		msg_stopping gopherd
		killproc gopherd
		rm -f /var/lock/subsys/gopherd /var/run/gopherd.pid >/dev/null 2>&1
	else
		msg_not_running gopherd
	fi
	;;
  status)
	status gopherd
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit 0
