#!/bin/sh
#
# /etc/rc.d/patroni: start/stop patroni
#

USER="postgres"
GROUP="postgres"

SSD=/sbin/start-stop-daemon
PROG=/usr/bin/patroni
CONF=/etc/patroni/patroni.yml
LOGFILE=/var/log/patroni/patroni.log
PID=/run/patroni.pid
OPTS="$CONF"

case $1 in
start)
        $SSD --start -c $USER:$GROUP --chdir `eval echo ~$USER` \
             -b -m --pidfile $PID --exec $PROG -O $LOGFILE -- $OPTS
        ;;
stop)
        $SSD --stop --retry 10 --pidfile $PID --remove-pidfile
        ;;
restart)
        $0 stop
        $0 start
        ;;
status)
        $SSD --status --pidfile $PID
        case $? in
        0) echo "$PROG is running with pid $(cat $PID)" ;;
        1) echo "$PROG is not running but the pid file $PID exists" ;;
        3) echo "$PROG is not running" ;;
        4) echo "Unable to determine the program status" ;;
        esac
        ;;
*)
        echo "usage: $0 [start|stop|restart|status]"
        ;;
esac

# End of file
