#!/bin/bash . /etc/rc.conf . /etc/rc.d/functions . /etc/conf.d/postgresql # Default PGROOT if it wasn't defined in the conf.d file PGROOT=${PGROOT:-/var/lib/postgres} PG_CTL="/usr/bin/pg_ctl -D $PGROOT/data -l /var/log/postgresql.log -s -w" postgres_init() { # initialization if [ ! -d $PGROOT/data ]; then mkdir -p $PGROOT/data && chown -R postgres:postgres $PGROOT su - postgres -c "/usr/bin/initdb $INITOPTS -D $PGROOT/data" fi if [ ! -e /var/log/postgresql.log ]; then touch /var/log/postgresql.log chown postgres /var/log/postgresql.log fi } case "$1" in start) postgres_init stat_busy "Starting PostgreSQL" su - postgres -c \ "$PG_CTL start" if [ $? -gt 0 ]; then stat_fail exit 1 else add_daemon postgresql stat_done fi ;; stop) stat_busy "Stopping PostgreSQL" su - postgres -c \ "$PG_CTL stop -m fast" if [ $? -gt 0 ]; then stat_fail else rm_daemon postgresql stat_done fi ;; reload) stat_busy "Reloading PostgreSQL" su - postgres -c \ "$PG_CTL reload" if [ $? -gt 0 ]; then stat_fail exit 1 else stat_done fi ;; restart) postgres_init stat_busy "Restarting PostgreSQL" su - postgres -c \ "$PG_CTL restart -m fast" if [ $? -gt 0 ]; then stat_fail exit 1 else add_daemon postgresql stat_done fi ;; status) stat_busy "Checking PostgreSQL status"; ck_status postgresql ;; *) echo "usage: $0 {start|stop|reload|restart|status}" esac exit 0