Add postgresql 9.6.1
[unleashed-userland.git] / components / database / postgresql-96 / files / postgres_96
blobff5abda8dd8d2ecc93a0f0301c03dc4104e398a0
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
25 #ident "@(#)postgres_96 1.1 09/10/13 SMI"
27 . /lib/svc/share/smf_include.sh
29 # SMF_FMRI is the name of the target service. This allows multiple instances
30 # to use the same script.
32 getproparg() {
33 val=`svcprop -p $1 $SMF_FMRI`
34 [ -n "$val" ] && echo $val
37 check_data_dir() {
38 if [ ! -d $PGDATA ]; then
39 echo "Error: postgresql_96/data directory $PGDATA does not exist"
40 exit $SMF_EXIT_ERR_CONFIG
43 if [ ! -w $PGDATA ]; then
44 echo "Error: postgresql_96/data directory $PGDATA is not writable by postgres"
45 exit $SMF_EXIT_ERR_CONFIG
48 if [ "$PGINIT" = "false" ]; then
49 echo "Notice: postgresql_96/data directory $PGDATA is not initialized"
50 echo " Calling '$PGBIN/initdb -D $PGDATA' to initialize"
51 $PGBIN/initdb -D $PGDATA
52 if [ $? -ne 0 ]; then
53 echo "Error: initdb failed"
54 echo "Hint : If database is already initialized set postgresql_96/initialized property to true."
55 echo " svccfg -s $SMF_FMRI \"setprop postgresql_96/initialized = boolean: true\""
56 echo " svccfg -s $SMF_FMRI refresh"
57 exit $SMF_EXIT_ERR
59 svccfg -s $SMF_FMRI "setprop postgresql_96/initialized = boolean: true"
60 svccfg -s $SMF_FMRI refresh
63 if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then
64 if [ `ls -a $PGDATA | wc -w` -le 2 ]; then
65 echo "Error: postgresql_96/data directory $PGDATA is empty, but it should be initialized"
66 echo "Hint : check your mountpoints"
67 else
68 echo "Error: postgresql_96/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory"
70 exit $SMF_EXIT_ERR_CONFIG
74 PGBIN=`getproparg postgresql_96/bin`
75 PGDATA=`getproparg postgresql_96/data`
76 PGLOG=`getproparg postgresql_96/log`
77 PGINIT=`getproparg postgresql_96/initialized`
79 if [ -z $SMF_FMRI ]; then
80 echo "Error: SMF framework variables are not initialized"
81 exit $SMF_EXIT_ERR
84 if [ -z $PGDATA ]; then
85 echo "Error: postgresql_96/data property not set"
86 exit $SMF_EXIT_ERR_CONFIG
89 if [ -z $PGLOG ]; then
90 echo "Error: postgresql_96/log property not set"
91 exit $SMF_EXIT_ERR_CONFIG
95 case "$1" in
96 'start')
97 check_data_dir
98 $PGBIN/pg_ctl -D $PGDATA -l $PGDATA/$PGLOG start
101 'stop')
102 $PGBIN/pg_ctl -D $PGDATA -m fast stop
105 'refresh')
106 $PGBIN/pg_ctl -D $PGDATA reload
110 echo "Usage: $0 {start|stop|refresh}"
111 exit 1
114 esac
115 exit $SMF_EXIT_OK