#!/bin/sh
#
# chkconfig: - 80 80
# processname: esehttpd
# description: a http server
# config: /etc/esehttpd/esehttpd.conf
#

source /etc/rc.d/init.d/functions

kernelrel=`uname -r`
kernelver=${kernelrel:0:4}
kernelarch=`uname -m`
lddruby=`ldd /usr/sbin/esehttpd | grep ruby`
eseopt=''
if [ "$kernelver" = "2.2" -o "$kernelarch" = "x86_64" -o -n "$lddruby" ]; then
  # force to use poll
  eseopt="-p"
fi


case "$1" in
start)
	echo -n "Starting esehttpd: "
	if ( /usr/sbin/esehttpd $eseopt ); then
		echo_success
	else
		echo_failure
	fi
	echo
	touch /var/lock/subsys/esehttpd
	;;
graceful)
	echo -n "Shutting down esehttpd (SIGHUP): "
	killproc esehttpd -HUP 2> /dev/null
	echo
	rm -f /var/lock/subsys/esehttpd
	;;
stop)
	echo -n "Shutting down esehttpd: "
	killproc esehttpd 2> /dev/null
	echo
	rm -f /var/lock/subsys/esehttpd
	;;
status)
	status esehttpd
	;;
configtest)
	if ( /usr/sbin/esehttpd -t ); then
		exit 0
	fi
	exit 1
	;;
restart)
	if ! $0 configtest ; then
		exit 1
	fi
	$0 graceful
	$0 start
	;;
*)
	echo "Usage: $0 {start|stop|restart|status|configtest}"
	exit 1
esac

exit 0

