#!/bin/sh

### BEGIN INIT INFO
# Provides:		bucardo
# Required-Start:	$local_fs $remote_fs $network $time
# Required-Stop:	$local_fs $remote_fs $network $time
# Should-Start:		$syslog postgresql
# Should-Stop:		$syslog postgresql
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	PostgreSQL replication system
### END INIT INFO

NAME=bucardo
DESC="PostgreSQL replication system"
DAEMON=/usr/bin/bucardo
PIDFILE=/var/run/bucardo/bucardo.mcp.pid

test -x $DAEMON || exit 0

if [ -f /etc/default/bucardo ] ; then
	. /etc/default/bucardo
fi

test "$ENABLED" != "0" || exit 0

. /lib/lsb/init-functions

case "$1" in
start)
	if [ ! -d /var/run/bucardo ]; then
		mkdir /var/run/bucardo
		chown bucardo:bucardo /var/run/bucardo
	fi
	log_daemon_msg "Starting $DESC" $NAME
	su bucardo --command "$DAEMON start"
	log_end_msg $?
	;;
force-reload|reload)
	log_daemon_msg "Reloading $DESC configuration files" $NAME
	su bucardo --command "$DAEMON reload_config"
	log_end_msg $?
	;;
restart)
	$0 stop
	$0 start
	;;
stop)
	log_daemon_msg "Stopping $DESC" $NAME
	su bucardo --command "$DAEMON stop"
	log_end_msg $?
	;;
status)
	status_of_proc -p "$PIDFILE" bucardo
	;;
*)
	log_action_msg "Usage: $0 {start|force-reload|reload|restart|stop}" >&2
	exit 1
	;;
esac

exit 0
