#!/bin/ksh93 . /lib/svc/share/smf_include.sh unset PGDATA PGLOG ; typeset PGDATA PGLOG PGCTL=@CLIENT_BASEDIR@/bin/pg_ctl if [[ -z ${SMF_FMRI} ]]; then SMF_FMRI='postgres-95:default' print -u2 "SMF_FMRI is not set! Assuming '${SMF_FMRI}'." fi # $1 .. Name of the property to lookup # $2 .. vName of the variable, where to append the unescaped values # return: 0 .. non-empty value found; 1 .. prop does not exist or is empty function getSvcProp { typeset -n VAL=$2 typeset V="${ svcprop -p $1 ${SMF_FMRI} 2>/dev/null ; }" [[ $V == '""' || -z $V ]] && return 1 VAL+="${V// /_}" return 0 } if ! getSvcProp 'config/dir' PGDATA ; then print -u2 "SMF property 'config/dir' not set - exiting." exit ${SMF_EXIT_ERR_CONFIG} fi function checkDB { if ! getSvcProp 'config/log' PGLOG ; then print -u2 "SMF property 'config/log' not set - exiting." exit ${SMF_EXIT_ERR_CONFIG} fi [[ -e ${PGDATA}/postgresql.conf ]] && return 0 print "Trying to initialize PostgreSQL database cluster in '${PGDATA}'..." if [[ ! -e "${PGDATA}" ]]; then mkdir -p "${PGDATA}" || return ${SMF_EXIT_ERR_PERM} chmod 0700 "${PGDATA}" fi if ! ${PGCTL} init -w -D "${PGDATA}" -m fast -l "${PGLOG}"; then print -u2 "'${PGCTL} init -w -D \"${PGDATA}\" -m fast " \ "-l \"${PGLOG}\" failed." return ${SMF_EXIT_ERR_FATAL} fi print 'done.' return 0 } case "$1" in start) print "Starting postgres using '${PGDATA}' ..." ulimit -n 10240 checkDB || exit $? ${PGCTL} -w -D "${PGDATA}" -l "${PGLOG}" start ;; refresh) print "Reloading postgres config using '${PGDATA}' ..." ${PGCTL} -w -D "${PGDATA}" reload ;; stop) print "Stopping postgres using '${PGDATA}' ..." ${PGCTL} -w -D "${PGDATA}" stop ;; *) print -u2 "Usage: $0 {start|refresh}" exit 1 ;; esac integer RES=$? (( RES )) && print -u2 "Faild with exit code ${RES}" && \ exit ${SMF_EXIT_ERR_FATAL} print 'Done.' exit ${SMF_EXIT_OK}