~ubuntu-branches/debian/sid/resource-agents/sid

« back to all changes in this revision

Viewing changes to rgmanager/src/resources/utils/config-utils.sh.in

  • Committer: Package Import Robot
  • Author(s): Martin Loschwitz
  • Date: 2012-10-09 11:16:59 UTC
  • mfrom: (3.1.1)
  • Revision ID: package-import@ubuntu.com-20121009111659-jrcwfqskcbh0iuio
Tags: 1:3.9.3+git20121009-1
* New upstream version
* debian/patches/01_docbook_patch.patch: Refactored for new release
* debian/patches/02_spelling_fixes.patch.new: Refatored for new release
* debian/control: Bumped Standards-Version to 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
# Copyright (C) 1997-2003 Sistina Software, Inc.  All rights reserved.
4
 
# Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
5
 
#
6
 
# This program is free software; you can redistribute it and/or
7
 
# modify it under the terms of the GNU General Public License
8
 
# as published by the Free Software Foundation; either version 2
9
 
# of the License, or (at your option) any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
#
20
 
 
21
 
declare RA_COMMON_pid_dir=/var/run/cluster
22
 
declare RA_COMMON_conf_dir=@CONFDIR@
23
 
 
24
 
declare -i FAIL=255
25
 
declare -a ip_keys
26
 
 
27
 
generate_configTemplate()
28
 
{
29
 
        cat > "$1" << EOT
30
 
#
31
 
# "$1" was created from the "$2"
32
 
#
33
 
# This template configuration was automatically generated, and will be
34
 
# automatically regenerated if removed. Once this file has been altered,
35
 
# automatic re-generation will stop. Remember to copy this file to all 
36
 
# other cluster members after making changes, or your service will not 
37
 
# operate correctly.
38
 
#
39
 
EOT
40
 
}
41
 
 
42
 
generate_configTemplateXML()
43
 
{
44
 
        cat > "$1" << EOT
45
 
<!--
46
 
  "$1" was created from the "$2"
47
 
 
48
 
  This template configuration was automatically generated, and will be
49
 
  automatically regenerated if removed. Once this file has been altered,
50
 
  automatic re-generation will stop. Remember to copy this file to all 
51
 
  other cluster members after making changes, or your service will not 
52
 
  operate correctly.
53
 
-->
54
 
EOT
55
 
}
56
 
 
57
 
sha1_addToFile()
58
 
{
59
 
        declare sha1line="# rgmanager-sha1 $(sha1sum "$1")"
60
 
        echo $sha1line >> "$1"
61
 
}
62
 
 
63
 
sha1_addToFileXML()
64
 
{
65
 
        declare sha1line="<!--# rgmanager-sha1 $(sha1sum "$1")-->"
66
 
        echo $sha1line >> "$1"
67
 
}
68
 
 
69
 
sha1_verify()
70
 
{
71
 
        declare sha1_new sha1_old
72
 
        declare oldFile=$1
73
 
 
74
 
        ocf_log debug "Checking: SHA1 checksum of config file $oldFile"
75
 
 
76
 
        sha1_new=`cat "$oldFile" | grep -v "# rgmanager-sha1" | sha1sum | sed 's/^\([a-z0-9]\+\) .*$/\1/'`
77
 
        sha1_old=`tail -n 1 "$oldFile" | sed 's/^\(<!--\)\?# rgmanager-sha1 \(.*\)$/\2/' | sed 's/^\([a-z0-9]\+\) .*$/\1/'`
78
 
 
79
 
        if [ "$sha1_new" = "$sha1_old" ]; then
80
 
                ocf_log debug "Checking: SHA1 checksum > succeed"
81
 
                return 0;
82
 
        else
83
 
                ocf_log debug "Checking: SHA1 checksum > failed - file changed"
84
 
                return 1;
85
 
        fi
86
 
}
87
 
 
88
 
#
89
 
# Usage: ccs_get key
90
 
#
91
 
ccs_get()
92
 
{
93
 
        declare outp
94
 
        declare key
95
 
 
96
 
        [ -n "$1" ] || return $FAIL
97
 
 
98
 
        key="$*"
99
 
 
100
 
        outp=$(ccs_tool query "$key" 2>&1)
101
 
        if [ $? -ne 0 ]; then
102
 
                if [[ "$outp" =~ "Query failed: Invalid argument" ]]; then
103
 
                        # This usually means that element does not exist
104
 
                        # e.g. when checking for IP address 
105
 
                        return 0;
106
 
                fi
107
 
 
108
 
                if [ "$outp" = "${outp/No data available/}" ] || [ "$outp" = "${outp/Operation not permitted/}" ]; then
109
 
                        ocf_log err "$outp ($key)"
110
 
                        return $FAIL
111
 
                fi
112
 
 
113
 
                # no real error, just no data available
114
 
                return 0
115
 
        fi
116
 
 
117
 
        echo $outp
118
 
 
119
 
        return 0
120
 
}
121
 
 
122
 
#
123
 
# Build a list of service IP keys; traverse refs if necessary
124
 
# Usage: get_service_ip_keys desc serviceName
125
 
#
126
 
get_service_ip_keys()
127
 
{
128
 
        declare svc=$1
129
 
        declare -i x y=0
130
 
        declare outp
131
 
        declare key
132
 
 
133
 
        #
134
 
        # Find service-local IP keys
135
 
        #
136
 
        x=1
137
 
        while : ; do
138
 
                key="/cluster/rm/service[@name=\"$svc\"]/ip[$x]"
139
 
 
140
 
                #
141
 
                # Try direct method
142
 
                #
143
 
                outp=$(ccs_get "$key/@address")
144
 
                if [ $? -ne 0 ]; then
145
 
                        return 1
146
 
                fi
147
 
 
148
 
                #
149
 
                # Try by reference
150
 
                #
151
 
                if [ -z "$outp" ]; then
152
 
                        outp=$(ccs_get "$key/@ref")
153
 
                        if [ $? -ne 0 ]; then
154
 
                                return 1
155
 
                        fi
156
 
                        key="/cluster/rm/resources/ip[@address=\"$outp\"]"
157
 
                fi
158
 
 
159
 
                if [ -z "$outp" ]; then
160
 
                        break
161
 
                fi
162
 
 
163
 
                #ocf_log debug "IP $outp found @ $key"
164
 
 
165
 
                ip_keys[$y]="$key"
166
 
 
167
 
                ((y++))
168
 
                ((x++))
169
 
        done
170
 
 
171
 
        ocf_log debug "$y IP addresses found for $svc/$OCF_RESKEY_name"
172
 
 
173
 
        return 0
174
 
}
175
 
 
176
 
build_ip_list()
177
 
{
178
 
        declare ipaddrs ipaddr
179
 
        declare -i x=0
180
 
                        
181
 
        while [ -n "${ip_keys[$x]}" ]; do
182
 
              ipaddr=$(ccs_get "${ip_keys[$x]}/@address")
183
 
              if [ -z "$ipaddr" ]; then
184
 
                                   break
185
 
              fi
186
 
 
187
 
              # remove netmask
188
 
              iponly=`echo $ipaddr | sed 's/\/.*//'`
189
 
              ipaddrs="$ipaddrs $iponly"
190
 
             ((x++))
191
 
        done
192
 
 
193
 
        echo $ipaddrs
194
 
}
195
 
 
196
 
generate_name_for_pid_file()
197
 
{
198
 
        declare filename=$(basename $0)
199
 
        
200
 
        echo "$RA_COMMON_pid_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE.pid"
201
 
        
202
 
        return 0;
203
 
}
204
 
 
205
 
generate_name_for_pid_dir()
206
 
{
207
 
        declare filename=$(basename $0)
208
 
        
209
 
        echo "$RA_COMMON_pid_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE"
210
 
        
211
 
        return 0;
212
 
}
213
 
 
214
 
generate_name_for_conf_dir()
215
 
{
216
 
        declare filename=$(basename $0)
217
 
 
218
 
        echo "$RA_COMMON_conf_dir/$(basename $0 | sed 's/^\(.*\)\..*/\1/')/$OCF_RESOURCE_INSTANCE"
219
 
        
220
 
        return 0;
221
 
}
222
 
 
223
 
create_pid_directory()
224
 
{
225
 
        declare program_name="$(basename $0 | sed 's/^\(.*\)\..*/\1/')"
226
 
        declare dirname="$RA_COMMON_pid_dir/$program_name"
227
 
 
228
 
        if [ -d "$dirname" ]; then
229
 
                return 0;
230
 
        fi
231
 
        
232
 
        chmod 711 "$RA_COMMON_pid_dir"
233
 
        mkdir -p "$dirname"
234
 
        
235
 
        if [ "$program_name" = "mysql" ]; then
236
 
                chown mysql.root "$dirname"
237
 
        elif [ "$program_name" = "tomcat-5" ]; then
238
 
                chown tomcat.root "$dirname"
239
 
        fi
240
 
 
241
 
        return 0;
242
 
}
243
 
 
244
 
create_conf_directory()
245
 
{
246
 
        declare dirname="$1"
247
 
 
248
 
        if [ -d "$dirname" ]; then
249
 
                return 0;
250
 
        fi
251
 
        
252
 
        mkdir -p "$dirname"
253
 
        
254
 
        return 0;
255
 
}
256
 
 
257
 
check_pid_file() {
258
 
        declare pid_file="$1"
259
 
 
260
 
        if [ -z "$pid_file" ]; then
261
 
                return 1;
262
 
        fi
263
 
 
264
 
        if [ ! -e "$pid_file" ]; then
265
 
                return 0;
266
 
        fi
267
 
 
268
 
        ## if PID file is empty then it should be safe to remove it
269
 
        read pid < "$pid_file"
270
 
        if [ -z "$pid" ]; then
271
 
                rm $pid_file
272
 
                ocf_log debug "PID File \"$pid_file\" Was Removed - Zero length";
273
 
                return 0;
274
 
        fi
275
 
 
276
 
        if [ ! -d /proc/`cat "$pid_file"` ]; then       
277
 
                rm "$pid_file"
278
 
                ocf_log debug "PID File \"$pid_file\" Was Removed - PID Does Not Exist";
279
 
                return 0;
280
 
        fi
281
 
 
282
 
        return 1;
283
 
}