description "PostgreSQL - RDBMS server"

start on runlevel [2345]
stop on runlevel [!2345]

pre-start script
    [ -r /usr/share/postgresql-common/init.d-functions ] || exit 0
    . /usr/share/postgresql-common/init.d-functions

    get_versions

    # create socket directory
    if [ -d /var/run/postgresql ]; then
	chmod 2775 /var/run/postgresql
    else
	install -d -m 2775 -o postgres -g postgres /var/run/postgresql
	[ -x /sbin/restorecon ] && restorecon -R /var/run/postgresql || true
    fi

    # Start version instances
    ret=0
    for v in $versions; do
        initctl start postgresql-version VERSION=$v || ret=$?
    done
    exit $ret
end script

post-stop exec initctl emit stop-postgresql-versions
