#!/bin/sh

PATH=/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
logger -t "[nginx]" "$1"
if  [ "$1" = "start" ] || [ "$1" = "restart" ] ; then
lnmp_enable=`nvram get lnmp_enable`
lnmp_enable=${lnmp_enable:-"0"}
if [ "$lnmp_enable" = "0" ] ; then
/opt/etc/init.d/S80nginx stop
exit 1
fi
fi

case $1 in
	start)
	nginx && echo 'Nginx started.'
	;;
	stop)
	nginx -s quit && echo 'Nginx gracefully stopped.'
	;;
	restart)
	nginx -s stop && nginx && echo 'Nginx restarted.'
	;;
	reload)
	nginx -s reload && echo 'Nginx configuration reload.'
	;;
	reopen)
	nginx -s reopen && echo 'Nginx log files reopened.'
	;;
	test)
	nginx -t
	;;
	*)
	echo "Usage: $0 {start|stop|restart|reload|reopen|test}"
	;;
esac
