Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created September 12, 2012 16:25
Show Gist options
  • Save mitchellh/3707876 to your computer and use it in GitHub Desktop.
Save mitchellh/3707876 to your computer and use it in GitHub Desktop.
init file for pg clusters on Ubuntu
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: postgresql-cluster-<%= @cluster_name %>
# Required-Start: $local_fs $remote_fs $network $time
# Required-Stop: $local_fs $remote_fs $network $time
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PostgreSQL Cluster: <%= @cluster_name %>
### END INIT INFO
CLUSTER=<%= @cluster_name %>
OWNER=<%= @owner %>
VERSION=<%= @version %>
case "$1" in
start|stop|restart|reload)
su -c "pg_ctlcluster ${VERSION} ${CLUSTER} $1" $OWNER
;;
status)
pg_lsclusters -h | awk "BEGIN {rc=0}; \$2 == \"${CLUSTER}\" && \$4 == \"down\" {rc=3}; END {exit rc}"
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment