#!/bin/sh
#
# MacPorts generated daemondo support script
#

#
# Init
#
prefix=/opt/local
pidfile="${prefix}/var/run/nginx/nginx-adblock2privoxy.pid"

#
# Start
#
Start()
{
	"${prefix}/sbin/nginx" \
		-c \
		"${prefix}/etc/adblock2privoxy/nginx.conf" \
		-g "daemon off;"
}

#
# Stop
#
Stop()
{
	if [ -f "${pidfile}" ]; then
		/usr/bin/kill "$(cat "${pidfile}")" \
			&& /bin/rm -f "${pidfile}" ;
	else
		/usr/bin/kill -SIGUSR1 "$(/usr/bin/pgrep -u root nginx)" 2>/dev/null ;
	fi
}

#
# Restart
#
Restart()
{
	Stop
	Start
}

#
# Run
#
Run()
{
case $1 in
  start  ) Start   ;;
  stop   ) Stop    ;;
  restart) Restart ;;
  *      ) echo "$0: unknown argument: $1";;
esac
}

#
# Run a phase based on the selector
#
Run $1

