2

I am testing using the OCF:Heartbeat:Dummy script and I want to make a very basic setup just to know it works and build on that.

The only information I can find was this web blog here. https://raymii.org/s/tutorials/Corosync_Pacemaker_-_Execute_a_script_on_failover.html

It has some typos but basically worked for me.

The script currently just contains the following :

sudo nano /usr/local/bin/failover.sh && sudo chmod +x /usr/local/bin/failover.sh

#!/bin/sh

touch /tmp/testfailover.sh

Here is my setup :

cp /usr/lib/ocf/resource.d/heartbeat/Dummy /usr/lib/ocf/resource.d/heartbeat/FailOverScript

sudo nano /usr/lib/ocf/resource.d/heartbeat/FailOverScript

dummy_start() {
    dummy_monitor
    /usr/local/bin/failover.sh
    if [ $? =  $OCF_SUCCESS ]; then
    return $OCF_SUCCESS
    fi
    touch ${OCF_RESKEY_state}
}

sed -i 's/Dummy/FailOverScript/g' /usr/lib/ocf/resource.d/heartbeat/FailOverScript



sed -i 's/dummy/FailOverScript/g' /usr/lib/ocf/resource.d/heartbeat/FailOverScript

pcs resource create FailOverScript ocf:heartbeat:FailOverScript op monitor interval="30"

The only testing I can really do :

[root@node2 ~]# /usr/lib/ocf/resource.d/heartbeat/FailOverScript start ; echo $?
DEBUG: default start : 0
0

ocf-tester doesn't seem to exist in the latest HA Software Suite, not really sure how to manually install it, but the script "half works".

The script doesn't need monitoring, its supposed to be very basic, but it seems to be flapping and giving me the following error code. Any idea's what to do?

FailOverScript (ocf::heartbeat:FailOverScript):        Started
node2

Failed Actions:
* FailOverScript_monitor_30000 on node2 'not running' (7): call=
24423, status=complete, exitreason='none',
    last-rc-change='Tue Aug 16 15:53:50 2016', queued=0ms, exec=
9ms

Example of what I want to do:

Cluster start

Script runs "start.sh"

Cluster fails over to node2.

On node1 script runs "fail.sh"

On node2 script runs "start.sh"

and vis versa if it fails the other direction.

Note: The script does work, I get /tmp/testfailover.sh. I even tried putting another script under dummy_stop to remove the file and that worked, but it just keeps flapping along removing/adding/removing/adding file and starting/failing/stoping/starting etc etc.

Thanks for reading!

3
  • I started just using ClusterMon and modifying the already existing/working scripts... Sep 19, 2016 at 17:58
  • you should copy the script file in both the nodes
    – abhi
    Dec 8, 2019 at 8:29
  • @abhi I experience the same issue, it keeps looping on the script on 1 node like OP experienced, I already copied the script file and resource file to both node, still doesn't fix it. Have you already found the solution FreeSoftwareServers? Dec 21, 2020 at 5:27

1 Answer 1

1

I realized the problem, there's a typo on that guide. Your command shouldn't be between dummy_monitor and if [ $? = $OCF_SUCCESS ]; then. That's because the $? take the returned result of dummy_monitor command. It should be:

dummy_start() {
    dummy_monitor
    if [ $? =  $OCF_SUCCESS ]; then
    /usr/local/bin/failover.sh
    return $OCF_SUCCESS
    fi
    touch ${OCF_RESKEY_state}
}

Edit after some testing:

The format above only getting rid of the error, but doesn't actually run the script on failover, if you want to actually run the script on failover, use:

dummy_start() {
    dummy_monitor
    if [ $? =  $OCF_SUCCESS ]; then
    return $OCF_SUCCESS
    fi
    /usr/local/bin/failover.sh
    touch ${OCF_RESKEY_state}
}
1
  • 1
    Nice to see an answer soo long after the fact, glad you got it working. I obviously don't have a test environment setup anymore but thanks for feedback! Dec 23, 2020 at 18:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .