New control_rolechg.ksh
1 #!/usr/bin/ksh
2 #
3 # CDDL HEADER START
4 #
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.
8 #
9 # You can obtain a copy of the license at usr/src/CDDL.txt
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/CDDL.txt.
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]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26
27 # ident "%Z%%M% %I% %E% SMI"
28 #
29 # Method for the PostrgresSQL rolchanger agent.
30 #
31 # This method is called by the GDS.
32 #
33 # It is started with options and one parameter:
34 #
35 #
36 # $1 start, stop or validate.
37 #
38
39 MYNAME=`basename ${0}`
40 MYDIR=`dirname ${0}`
41
42 . ${MYDIR}/../etc/config
43 . ${MYDIR}/../../lib/functions_static
44 . ${MYDIR}/functions
45
46 debug_message "Method: ${MYNAME} ${*} - Begin"
47 ${SET_DEBUG}
48
49 # get the options for gds
50
51 while getopts 'R:G:H:P:T:W:' opt
52 do
53 case "${opt}" in
54 R) RESOURCE=${OPTARG};;
55 G) RESOURCEGROUP=${OPTARG};;
56 H) STB_HOST=${OPTARG};;
57 P) STB_PARFILE=${OPTARG};;
58 T) TRIGGER=${OPTARG};;
59 W) WAIT=${OPTARG};;
60 *) exit 1;;
61 esac
62 done
63
64 # if no option is set ($OPTIND is 1 in this case) the following validation will fail.
65
66 if [ ${OPTIND} -gt 1 ]
67 then
68 shift $((${OPTIND} - 1))
69 fi
70
71 # set some generic variables
72
73 LOGFILE=/var/tmp/${RESOURCE}_logfile
74
75 case ${1} in
76 start)
77
78 # start the rolechanger for PostgreSQL
79
80 # touch a "lockfile" to prevent a a remote PostgreSQL to start in primary mode
81 # after the rolchanger starts his work.
82
83 /usr/bin/touch /tmp/${RESOURCE}_rolechg.lck
84 # exit from start, if the options are wrong
85
86 validate_options
87 rc_val=${?}
88 if [ ${rc_val} -ne 0 ]
89 then
90 terminate ${1} ${rc_val}
91 fi
92
93 ${RM} ${LOGFILE} 2>/dev/null
94
95 # check the content of the options
96
97 if validate
98 then
99
100 start_rolechg
101 rc_val=${?}
102
103 if [ ${rc_val} -eq 0 ]
104 then
105
106 # remove the rolechangers "lockfile"
107
108 ${RM} /tmp/${RESOURCE}_rolechg.lck
109
110 log_message notice "start_command rc<${rc_val}>"
111 debug_message "Method: ${MYNAME} - End (Exit 0)"
112 else
113 log_message err "start_command rc<${rc_val}>"
114 fi
115 else
116 debug_message "Method: ${MYNAME} - End (Exit 1)"
117 rc_val=1
118 fi;;
119
120 probe)
121
122 # Probe the rolechanger for PostgreSQL
123
124 # This is a placeholder for future extentionto avoid reregistration.
125 # It will always return 0 at the current point in time.
126
127 rc_val=0;;
128
129 stop)
130
131 # stop the rolechanger for PostgreSQL
132
133 # exit from stop, if the options are wrong
134
135
136 validate_options
137 rc_val=${?}
138 if [ ${rc_val} -ne 0 ]
139 then
140 terminate ${1} ${rc_val}
141 fi
142
143 ${RM} ${LOGFILE} 2>/dev/null
144
145 stop_rolechg
146 rc_val=${?}
147
148 if [ "${rc_val}" -eq 0 ]
149 then
150 log_message notice "stop_command rc<${rc_val}>"
151 else
152 log_message err "stop_command rc<${rc_val}>"
153 fi
154 rc_val=0;;
155
156 validate)
157
158 # validate the parameters for application PostgreSQL
159
160 validate_options
161 rc_val=${?}
162 if [ ${rc_val} -ne 0 ]
163 then
164 terminate ${1} ${rc_val}
165 fi
166
167 ${RM} ${LOGFILE} 2>/dev/null
168
169 if validate
170 then
171 rc_val=0
172 else
173 rc_val=1
174 fi;;
175
176 esac
177
178 # terminate with the right return code, either with an smf specific or the gds/zsh based
179 # return code
180
181 debug_message "Method: ${MYNAME} ${*} - End terminating"
182 terminate ${1} ${rc_val}