6930152 6192139 (no reboot audit -- PSARC/2009/354) points out less than optimal...
[unleashed.git] / usr / src / cmd / mms / mmsdb
blobb198b11daf0aa0686f2c51843bb7f2585ad753a3
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.
26 . /lib/svc/share/smf_include.sh
28 getproparg() {
29 val=`svcprop -c -p $1 $SMF_FMRI`
30 [ -n "$val" ] && echo $val
33 check_data_dir() {
34 if [ ! -d $PGDATA ]; then
35 echo "Error: postgresql/data directory $PGDATA does not exist"
36 exit $SMF_EXIT_ERR_CONFIG
39 if [ ! -w $PGDATA ]; then
40 echo "Error: postgresql/data directory $PGDATA is not writable by postgres"
41 exit $SMF_EXIT_ERR_CONFIG
44 if [ ! -d $PGDATA/base -o ! -d $PGDATA/global -o ! -f $PGDATA/PG_VERSION ]; then
45 echo "Error: postgresql/data directory $PGDATA is not empty, nor is it a valid PostgreSQL data directory"
46 exit $SMF_EXIT_ERR_CONFIG
50 if [ -z "$SMF_FMRI" ]; then
51 echo "Error: SMF framework variables are not initialized."
52 exit $SMF_EXIT_ERR
55 PGBIN=`getproparg postgresql/bin`
56 PGDATA=`getproparg postgresql/data`
57 PGUSER=`getproparg method_context/user`
59 if [ -z "$PGDATA" ]; then
60 echo "Error: postgresql/data property not set"
61 exit $SMF_EXIT_ERR_CONFIG
64 if [ -z "$PGBIN" ]; then
65 echo "Error: postgresql/bin property not set"
66 exit $SMF_EXIT_ERR_CONFIG
69 if [ -z "$PGUSER" ]; then
70 echo "Error: method_context/user property not set"
71 exit $SMF_EXIT_ERR_CONFIG
74 case "$1" in
75 'start')
76 check_data_dir
77 $PGBIN/pg_ctl -D $PGDATA start
80 'stop')
81 status=`$PGBIN/pg_ctl -D $PGDATA status | /bin/grep PID`
82 $PGBIN/pg_ctl -D $PGDATA stop -m fast
83 if [ -z "$status" ]; then
84 pattern="$PGBIN/postgres -D $PGDATA"
85 /bin/pgrep -u $PGUSER -f "$pattern" > /dev/null 2>&1
86 if [ $? -eq 0 ]; then
87 echo "Sending immediate shutdown signal."
88 /bin/pkill -QUIT -u $PGUSER -f "$pattern"
93 'refresh')
94 $PGBIN/pg_ctl -D $PGDATA reload
98 echo "Usage: $0 {start|stop|refresh}"
99 exit 1
102 esac
103 exit $SMF_EXIT_OK