I am setting up a HA cluster for a web application with 2 nodes (2 physical servers):
- node1 (current
- node2 (current
Using Corosync & Pacemaker I was able to create the cluster and some resources agents including an IP failover and a Webserver (apache).
Failoverresource exists on only one node at a time
Uses a python script to make API calls to my hosting provider in order to update the IP failover destination
WebServerresource exists (as a clone) on every available node
Standard OCF resource using Apache's
- There is a constraint that says that
WebServermust be running at the same time on a server in order for considering it as available.
Now I would like to create a custom resource agent (like I did for the IP failover) that will:
- Switch the mysql instance of the current slave node into a master node
- Switch the mysql instance of the current master node into a slave node of the new master node
- Basically do the same for Redis instance
Ideally, the resource would be started on only one node (master), and stopped on all other nodes (slaves). Therefore, starting the resource would put the current node in
master mode, and stopping it would put it in
I made a script that can easily achieve all of these operations. Here's how it works.
Turn local node in master mode:
# /usr/local/bin/db_failover_switch.sh master
Turn local node in slave mode:
# /usr/local/bin/db_failover_switch.sh slave 188.8.131.52
The synopsis is pretty straightforward to understand. The problem I am facing, is that I obviously need to set the master IP in order for the slave to configure MySQL and Redis services accordingly.
In case of failover, I want:
- Resource starts on
- Resource stops on
In order to stop the resource (i.e. setting it into slave mode), I need to know the IP address (hostname will do) of the node which has the resource running.
Is there a way I can have a dynamic parameter that Pacemaker will pass to my resource agent? Or maybe can I retrieve the clusters information directly from my resource agent script to know which is the node running a specific resource?