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

export PGADMIN_CONFIG_DEFAULT_SERVER=0.0.0.0
PGADMIN_BIN="/usr/local/bin/pgadmin4"
PGADMIN_PID="/var/run/pgadmin4.pid"

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

case "$1" in
"start")
	echo "Starting pgadmin4..."
	${PGADMIN_BIN} &
	echo $! >${PGADMIN_PID}
	echo "done"
	;;

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

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

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

esac
