#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.postgresql -- Run-Command for PostgreSQL Database
##

%config
    postgresql_enable="yes"
    postgresql_flags=""
    postgresql_datadir="@l_prefix@/var/postgresql/db"
    postgresql_socket_inet="localhost"
    postgresql_socket_unix="@l_prefix@/var/postgresql/run/"
    postgresql_log_file="@l_prefix@/var/postgresql/run/postmaster.log"
    postgresql_log_prolog="true"
    postgresql_log_epilog="true"
    postgresql_log_numfiles="10"
    postgresql_log_minsize="1M"
    postgresql_log_complevel="9"

%common
    postgresql_opts="-i -h $postgresql_socket_inet -k $postgresql_socket_unix"
    postgresql_opts="$postgresql_opts $postgresql_flags"

%start -p 200 -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    @l_prefix@/bin/pg_ctl start -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts"

%stop -p 200 -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    @l_prefix@/bin/pg_ctl stop -l $postgresql_log_file -D $postgresql_datadir -m smart

%restart -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    @l_prefix@/bin/pg_ctl restart -l $postgresql_log_file -D $postgresql_datadir -o "$postgresql_opts" -m smart

%reload -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    @l_prefix@/bin/pg_ctl reload -D $postgresql_datadir

%status -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    @l_prefix@/bin/pg_ctl status -D $postgresql_datadir

%daily -u @l_rusr@
    opServiceEnabled postgresql || exit 0
    shtool rotate -f \
        -n${postgresql_log_numfiles} -s${postgresql_log_minsize} -d \
        -z${postgresql_log_complevel} -m644 \
        -P "$postgresql_log_prolog" \
        -E "@l_prefix@/bin/pg_ctl reload -D $postgresql_datadir; $postgresql_log_epilog" \
        $postgresql_log_file

