#!/bin/sh

set -e

# Common helper script to start/stop gdomap; it is used both by the
# init script and the systemd unit file.

DAEMON=/usr/bin/gdomap
NAME=gdomap
PIDFILE=/var/run/$NAME.pid

GDOMAP_ARGS=
if [ -f /etc/default/$NAME ]; then
    . /etc/default/$NAME
fi

[ -x "$DAEMON" ] || exit 0

case "$1" in
  start)
	# Create an empty directory where the process would chroot to.
	if [ ! -d /var/run/gdomap ]; then
	    mkdir /var/run/gdomap
	    chmod 0755 /var/run/gdomap
	fi
	start-stop-daemon --start --oknodo --quiet --exec $DAEMON \
		-- -I $PIDFILE $GDOMAP_ARGS
	;;
  stop)
	start-stop-daemon --stop --oknodo --quiet --exec $DAEMON \
		-- -I $PIDFILE $GDOMAP_ARGS
	rm -f $PIDFILE
	;;
  *)
	printf "Usage: $0 {start|stop}\n"
	exit 1
	;;
esac

exit 0
