Operating System - HP-UX
1837191 Members
2724 Online
110114 Solutions
New Discussion

How to run a script during failover?

 
SOLVED
Go to solution
dictum9
Super Advisor

How to run a script during failover?


I want to run a certain script during failover.
Which file do I put it in?
8 REPLIES 8
Patrick Wallek
Honored Contributor
Solution

Re: How to run a script during failover?

Your best bet would probably be to run it from the package control script for the appropriate package.
Sajjad Sahir
Honored Contributor

Re: How to run a script during failover?

Dear etc

Normally during the failover the application will be unavailable , that time i don't know how mcsg will works


thanks and regards

Sajjad Sahir
johnsonpk
Honored Contributor

Re: How to run a script during failover?

Hi,

You can use the customer_defined_halt_commands section in the package control script to execute any command or script during package shutdown(remember these script will be executed during normal package shut down and fail over ).

If you just need to execute the script during fail over not during pkg shutdown ,then u may need to add additional functionality such as create an application monitoring script and let the monitoring script to call the application start/stop script with a different argument for each scenario to handle the pkg shutdown and fail over differently.(just thought may not be simple though)


Thanks!
Johnson

Doug O'Leary
Honored Contributor

Re: How to run a script during failover?

Hey;

As others have already suggested, the package control script would be the correct place for it. I would suggest not putting it in the customer_defined_halt_commands as that wouldn't be guaranteed to run. If, for example, the primary node dies, the package never does a clean shut down.

You can put logic in the customer_defined_run_commands to determine what node the package is running on. If it's the primary node, then no failover and you don't do anything. If it's the adoptive node, then run whatever you wanted to run for the failover.

Something like the following:

check_node()
{ Primary=hostA
Alt=hostB
Host=$(hostname)

if [ "${Host}" = "${Alt}" ]
then
echo "Running on adoptive node - alerting X about failover"
... cmnds opcmsg, email, whatever else you want to do.
fi
}

funcion customer_defined_run_commands
{ check_node

... remainder of the normal function
}

Hope that helps.

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Viktor Balogh
Honored Contributor

Re: How to run a script during failover?

I would write a snippet into the cntl file similar to the check of the debug file...
Let's say you create a file:

# touch /etc/cmcluster/${PKG_DIR}/runnning

and check this file for existence. If it's there then the package should be running, so the stopping of the package is a failover, let's run that script!

if [ -f /etc/cmcluster/${PKG_DIR}/runnning ]
then
print "Hey, it's a FAILOVER!"
fi
****
Unix operates with beer.
Viktor Balogh
Honored Contributor

Re: How to run a script during failover?

I forgot to mention that in case of a planned shutdown first you must remove the file in order to avoid the execution of your script...

# rm /etc/cmcluster/${PKG_DIR}/runnning
****
Unix operates with beer.
johnsonpk
Honored Contributor

Re: How to run a script during failover?

>>>Doug:As others have already suggested, the package control script would be the correct place for it. I would suggest not putting it in the customer_defined_halt_commands as that wouldn't be guaranteed to run. If, for example, the primary node dies, the package never does a clean shut down.

I do agree ,But in A TOC condition will there be a chance executing any other script ???


>>You can put logic in the customer_defined_run_commands to determine what node the package is running on. If it's the primary node, then no failover and you don't do anything. If it's the adoptive node, then run whatever you wanted to run for the failover.

I hope u have suggested to run the script on the primary node during the pkg startup on adoptive node (from adoptive node call the script to run on primary)
Again..In the TOC condition will the primary node be available for executing the fail over script??This will rather create a mess and affect the package start up on the adoptive node !! correct me if i get u wrong


Thanks!!
Johnson


Doug O'Leary
Honored Contributor

Re: How to run a script during failover?

Hmm; guess I wasn't clear. The package control script is the same on both systems. The addition to the package control script that I suggested would run regardless of what node the package started on.

If the package starts on the primary node, the customer_defined_run_commands gets run, which then runs check_node. That function doesn't do anything because the package is running on the primary node.

Now, if the primary node crashes, after a few seconds, the package starts running on the adoptive node. It gets to the customer_defined_run_commands which then runs check_node, which then does whatever is desired because ${Host} = ${Alt}.

Basically, nothing's checked on the way down - only on the way up because you can't guarantee *how* the package is coming down.

Does that clear it up?

As other additional posts have also indicated, there's 100s of ways to skin this particular cat. That's the nice thing about UNIX; there's usually several *rgith* ways to do the same thing.

Hope that helps.

Doug O'Leary

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html