summaryrefslogtreecommitdiffstats
path: root/ldirectord/OCF/ldirectord.in
blob: aea462606f4cb9aab4f6d3006f6c46ec31b1592f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/sh
#
#   ldirectord OCF RA. Wrapper around @sbindir@/ldirectord to
#   be OCF RA compliant and therefore to get the possibility
#   to monitor ldirectord by HAv2.
#   Tested on SuSE Linux Enterprise Server 10.
#
#   Should conform to the specification found at
#    https://github.com/ClusterLabs/resource-agents/blob/master/doc/dev-guides/ra-dev-guide.asc
#   and
#    https://github.com/ClusterLabs/OCF-spec/blob/master/ra/resource-agent-api.md
#
#   ToDo: Add parameter to start several instances of ldirectord
#   with different config files.
#
# Copyright (c) 2007 Andreas Mock (andreas.mock@web.de)
#                    All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#######################################################################
#
#	OCF Parameters
#	OCF_RESKEY_configfile
#	OCF_RESKEY_ldirectord
#
#######################################################################
# Initialization:

HA_VARRUNDIR=${HA_VARRUN}

. ${OCF_ROOT}/lib/heartbeat/ocf-shellfuncs

LDIRCONF=${OCF_RESKEY_configfile:-@sysconfdir@/ha.d/ldirectord.cf}
LDIRECTORD=${OCF_RESKEY_ldirectord:-@sbindir@/ldirectord}

meta_data() {
        cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="ldirectord" version="0.9">
<version>1.0</version>

<longdesc lang="en">
It's a simple OCF RA wrapper for ldirectord and uses the ldirectord interface
to create the OCF compliant interface. You win monitoring of ldirectord.
Be warned: Asking ldirectord status is an expensive action.
</longdesc>
<shortdesc lang="en">Wrapper OCF Resource Agent for ldirectord</shortdesc>

<parameters>

<parameter name="configfile" unique="1">
<longdesc lang="en">
The full pathname of the ldirectord configuration file.
</longdesc>
<shortdesc lang="en">configuration file path</shortdesc>
<content type="string" default="@sysconfdir@/ha.d/ldirectord.cf" />
</parameter>

<parameter name="ldirectord">
<longdesc lang="en">
The full pathname of the ldirectord.
</longdesc>
<shortdesc lang="en">ldirectord binary path</shortdesc>
<content type="string" default="@sbindir@/ldirectord" />
</parameter>

</parameters>

<actions>
<action name="start"   timeout="15" />
<action name="stop"    timeout="15" />
<action name="monitor" depth="0"  timeout="10" interval="20" />
<action name="meta-data"  timeout="10" />
<action name="validate-all"  timeout="10" />
</actions>
</resource-agent>
END
}

#######################################################################

ldir_init() {
    # check the supplied parameters exist enough that we can do all the other
    # operations
    if [ ! -f $LDIRCONF ]; then
        ocf_log warn "$LDIRCONF not found, ldirectord not installed"
        exit $OCF_ERR_INSTALLED
    fi

    if [ ! -x $LDIRECTORD ]; then
        ocf_log warn "$LDIRECTORD not found, ldirectord not installed"
        exit $OCF_ERR_INSTALLED
    fi
}

ldirectord_usage() {
        cat <<END
usage: $0 {start|stop|monitor|validate-all|meta-data}

Expects to have a fully populated OCF RA-compliant environment set.
END
}

ldirectord_exit() {
    exit $1
}

ldirectord_start() {
    ldirectord_status
    RET=$?

    # if ldirectord is running or there's an error, pass on this return code
    if [ $RET -ne $OCF_NOT_RUNNING ]; then
        return $RET
    fi

    ocf_log info "Starting ldirectord"
    echo $LDIRECTORD $LDIRCONF start
    $LDIRECTORD $LDIRCONF start
    RET=$?
    if [ $RET -ne 0 ]; then
        return $OCF_ERR_GENERIC
    fi

    # call status again to make sure we're running properly
    ldirectord_status
}

ldirectord_stop() {
    # a status check is simple enough to see if ldirectord is running or not.
    # It will also error out if there's configuration parsing errors so we
    # can try kill ldirectord even if the config is broken.
    ldirectord_status
    RET=$?

    # ldirectord may be running, hard to tell when status returns an error
    if [ $RET -eq $OCF_ERR_GENERIC ]; then
        # get the PID of the right ldirectord process
        PID=`pgrep -f "$LDIRECTORD $LDIRCONF start" 2>&1`
        RET=$?
        
        if [ $RET -eq 0 ]; then
            ocf_log warn "Killing ldirectord($PID) with SIGTERM"
            kill $PID
        fi

        pgrep -f "$LDIRECTORD $LDIRCONF start" >/dev/null 2>&1
        RET=$?
        # if ldirectord is not running any more, we've (kind of) successfully
        # stopped it
        if [ $RET -eq 1 ]; then
            return $OCF_SUCCESS
        else
            # ldirectord is still running? Kill it badly
            ocf_log warn "Killing ldirectord($PID) with SIGKILL"
            kill -9 $PID

            pgrep -f "$LDIRECTORD $LDIRCONF start" >/dev/null 2>&1
            RET=$?
            # if it's not dead after here, we can't really do anything more
            if [ $RET -eq 1 ]; then
                return $OCF_SUCCESS
            fi
        fi

        # if none of our kills work, return an error. This should force the
        # resource unmanaged
        # on this node, requiring manual intervention.
        return $OCF_ERR_GENERIC
    else
        ocf_log info "Stopping ldirectord"
        # if ldirectord status is not an error, issue a stop. Multiple stops
        # will return 0
        $LDIRECTORD $LDIRCONF stop
        RET=$?
        case $RET in
            0) return $RET;;
            *) return 1;;
        esac
    fi
}

# simple check to see if ldirectord is running, returns the proper OCF codes.
ldirectord_status() {
    OUTPUT=`$LDIRECTORD $LDIRCONF status 2>&1`
    case $? in
        0) return $OCF_SUCCESS;;
        1) expr match "$OUTPUT" '.*ldirectord stale pid file.*' >/dev/null
           if [ $? -eq 0 ]; then
               return $OCF_NOT_RUNNING
           else
              return $OCF_ERR_GENERIC
           fi;;
        2) ocf_log err "$LDIRCONF has configuration errors"
           echo $OUTPUT
           return $OCF_ERR_GENERIC;;
        3) return $OCF_NOT_RUNNING;;
        *) echo $OUTPUT
           return $OCF_ERR_GENERIC;;
    esac
}

ldirectord_monitor() {
    # check if the process is running first
    ldirectord_status
    RET=$?

    if [ $RET -ne $OCF_SUCCESS ]; then
        return $RET
    fi

    # do more advanced checks here for high OCF_CHECK_LEVELs. Don't know what
    # more we can do at this time,
    # a status call already hits LVS in the kernel.
}

ldirectord_validate() {
    #ldir_init is already called, there's nothing more we can validate unless
    #we add more attributes
    return 0
}

case $1 in
	meta-data|usage|help) : ;;
	*) ldir_init $@ ;;
esac

case $__OCF_ACTION in
meta-data)      meta_data
                exit $OCF_SUCCESS
                ;;
start)  ldirectord_start
                ldirectord_exit $?
                ;;
stop)   ldirectord_stop
                ldirectord_exit $?
                ;;
monitor)    ldirectord_monitor
                ldirectord_exit $?
                ;;
validate-all)   ldirectord_validate
                ldirectord_exit $?
                ;;
usage|help)     ldirectord_usage
                exit $OCF_SUCCESS
                ;;
*)              ldirectord_usage
                exit $OCF_ERR_UNIMPLEMENTED
                ;;
esac