description "PostgreSQL - RDBMS server (cluster)"
author "Cameron Norman <camerontnorman@gmail.com>"

usage "VERSION - version of postgres, \
       CLUSTER - cluster within the version."
instance $VERSION-$CLUSTER

export VERSION
export CLUSTER

stop on (stop-postgresql-clusters VERSION=$VERSION
         or deconfiguring-networking
         or unmounting-filesystem
         or runlevel [016])

pre-start exec rm -f /var/run/postgresql/$VERSION-$CLUSTER.pid

normal exit 0 TERM INT
respawn
exec /usr/bin/pg_ctlcluster --foreground --stdlog $VERSION $CLUSTER start

post-start script
	for t in $(seq 1 60); do
		sleep 0.25
		test -e /var/run/postgresql/$VERSION-$CLUSTER.pid && exit 0
	done
	# None of the status calls succeeded
	echo "Postgres cluster failed to start."
	stop; exit 1
end script

kill timeout 15
pre-stop exec /usr/bin/pg_ctlcluster -m fast $VERSION $CLUSTER stop
