Wednesday, January 15, 2014

Glassfish -- Script to detect the failure and start the server again

If your glassfish server becomes terminated somehow, then you can use following scripts to start it again. This scripts will be executed by cron and will detect the failure and start the glassfish again..
I prepared them for Linux and Solaris..
Note that, this method can be applied to any other processes.. We simple grep the process from the output of ps -ef, and start it if necessary.

LINUX
-----------------------

cron:
*/5 * * * * /root/erman_install/glassfish_restart_script ##  will be executed in every 5 mins

script:
ps -ef |grep glassfish.jar |grep -v grep
if [ "$?" == "1" ]
then
{
echo "Glassfish process not found"
echo "Starting Glassfish"
sh /root/erman_install/glassfish3/glassfish/bin/asadmin start-domain  >/dev/null 2>&1
}
else
echo "Found Glassfish process. Dont need to start Glassfish"
fi


Setup : Create the script , give the execute rights to relevant user , and make the cron entry.

SOLARIS
-----------------------

cron:

0,5,10,15,20,25,30,35,40,45,50,55 * * * *  /erman_install/glassfish_restart_script   ##if your cron is not so old, you can use */5 too.. This will be executed in every 5 mins, too.

Script:
#!/bin/bash
ps -ef |grep "/usr/java/bin/java -Dcom.sun.aas.instanceRoot=/erman_install/GlassFishESBv22/glas" |grep -v grep
if [ "$?" == "1" ]
then
{
echo "Glassfish process not found"
echo "Starting Glassfish"
sh /erman_install/GlassFishESBv22/glassfish/bin/asadmin start-domain  >/dev/null 2>&1
}
else
echo "Found Glassfish process. Dont need to start Glassfish"
fi

Setup : Create the script , give the execute rights to relevant user , and make the cron entry.

No comments :

Post a Comment