I have 2 app servers both configured to run a php cron job, but only 1 can run the job at any time. Since I am already using keepalived for other purposes, I am thinking of having some logic in the cron job to check if the node has the virtual ip, then execute the job. So theoretically even though both servers are running the cron job at the same time, only 1 will be executing the 'real' job.
But my question is how to check if the node has the vip? Can someone advise me on that?
Thanks.
I just had to do this. If you just want to check if the box you are on is floating the public ip and the ip is, say, a.b.c.d, then it is enough to run:
ip a | grep a.b.c.d
I'm pretty sure in bash you can use the output of that command as a conditional itself. If the machine is not floating the public ip, the output should be empty, hence evaluate to false and if there is a match for the ip, then it should evaluate to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With