#!/bin/sh
# Start script for FreeBSD, contributed by user Fabian Abplanalp
# Put this script in /usr/local/etc/rc.d then adjust NTFY_BIN and
# NTFY_CFG values in /etc/defaults/ntfy

NTFY_BIN="/usr/local/bin/ntfy"
NTFY_PID="/var/run/ntfy.pid"

# Read configuration variable file if it is present
[ -r /etc/defaults/ntfy ] && . /etc/defaults/ntfy

case "$1" in
	"start")
		echo "Starting ntfy..."
		${NTFY_BIN} serve --listen-http 0.0.0.0:8003 &
		echo $! >${NTFY_PID}
		echo "done"
		;;

	"stop")
		echo "Stopping ntfy..."
		if [ -f ${NTFY_PID} ]; then
			kill $(cat ${NTFY_PID})
			rm ${NTFY_PID}
			echo "done"
		else
			echo "not running?"
		fi
		;;

	"restart")
		echo "Restarting ntfy..."
		$0 stop
		sleep 2
		$0 start
		;;

	*)
		echo "$0 [start|stop|restart]"
		;;

esac
