#!/sbin/sh # # Copyright 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # #ident "@(#)postgresql 1.3 08/02/08 SMI" . /lib/svc/share/smf_include.sh # SMF_FMRI is the name of the target service. This allows multiple instances # to use the same script. getproparg() { val=`svcprop -p $1 $SMF_FMRI` [ -n "$val" ] && echo $val } check_data_dir() { if [ ! -d $PGDATA ]; then echo "Error: postgresql/data directory $PGDATA does not exist" exit $SMF_EXIT_ERR_CONFIG fi if [ ! -w $PGDATA ]; then echo "Error: postgresql/data directory $PGDATA is not writable by postgres" exit $SMF_EXIT_ERR_CONFIG fi if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then # If the directory is empty we can create the database files # on behalf of the user using initdb if [ `ls -a $PGDATA | wc -w` -le 2 ]; then echo "Notice: postgresql/data directory $PGDATA is empty" echo "Calling '$PGBIN/initdb -D $PGDATA' to initialize" $PGBIN/initdb -D $PGDATA if [ $? -ne 0 ]; then echo "Error: initdb failed" exit $SMF_EXIT_ERR fi else echo "Error: postgresql/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory" exit $SMF_EXIT_ERR_CONFIG fi fi } PGBIN=`getproparg postgresql/bin` PGDATA=`getproparg postgresql/data` PGLOG=`getproparg postgresql/log` if [ -z $SMF_FMRI ]; then echo "Error: SMF framework variables are not initialized" exit $SMF_EXIT_ERR fi if [ -z $PGDATA ]; then echo "Error: postgresql/data property not set" exit $SMF_EXIT_ERR_CONFIG fi if [ -z $PGLOG ]; then echo "Error: postgresql/log property not set" exit $SMF_EXIT_ERR_CONFIG fi case "$1" in 'start') check_data_dir $PGBIN/pg_ctl -D $PGDATA -l $PGDATA/$PGLOG start ;; 'stop') $PGBIN/pg_ctl -D $PGDATA stop ;; 'refresh') $PGBIN/pg_ctl -D $PGDATA reload ;; *) echo "Usage: $0 {start|stop|refresh}" exit 1 ;; esac exit $SMF_EXIT_OK