Shell script to restart the providers if they’re unavailable/crashed
It is not uncommon for the method to crash or freeze as a result of numerous causes. You may examine and resolve the problems, however it might take a while.
Nevertheless, one factor you are able to do instantly to cut back downtime for higher availability is to automate the method restart if it’s not out there.
Let’s do that on the freeway – shell scripts
You need to use the next shell scripts to loop by way of crontab, which checks the providers each quarter-hour (you possibly can regulate the interval time) and begins it if it seems to not be working. Sounds good?
On this article I give two examples of how you can begin the providers when they aren’t out there.
If you’re utilizing CentOS/RHEL 7+, you too can learn this text which explains how you can use systemd to reboot.
MySQL, PHP-FPM, Nginx will robotically restart if it does not work
A number of weeks in the past I moved Geek Flare to DigitalOcean with EasyEngine and MariaDB crashed twice in a single week.
You see it crashed early within the morning and was out of order for over 3 hours which isn’t good. It is my weblog, so no $$$ impression, however I nonetheless really feel sorry for it.
OK, present time now…
- Create a file utilizing vi editors within the desired location (on this demo I put it below /decide/startifdown.sh)
- Copy and paste the script beneath into the file and reserve it
#!/bin/bash
#Scripts to start out providers if not working
ps -ef | grep nginx |grep -v grep > /dev/null
if [ $? != 0 ]
then
/and so forth/init.d/nginx begin > /dev/null
fi
ps -ef | grep php5-fpm |grep -v grep > /dev/null
if [ $? != 0 ]
then
/and so forth/init.d/php5-fpm begin > /dev/null
fi
ps -ef | grep mysql |grep -v grep > /dev/null
if [ $? != 0 ]
then
/and so forth/init.d/mysql begin > /dev/null
fi
- Change the file permission to be executable
chmod 755 startifdown.sh
Take a look at it manually to verify the script is executable.
You may cease the service and use the script to examine if it begins. When you’re comfortable you possibly can put this in cron to run each quarter-hour.
*/1 * * * * /decide/startifdown.sh
Try my crontab article should you want some inspiration on how you can change the interval time.
This little script will begin the providers in the event that they crash, and I will not have that 3 hours of downtime.
A lot better!
WebSphere DMGR, Nodeagent, JVM robotically restart if it’s not out there
Create a file with the next scripts – I name it startwasifdown.sh
#!/bin/bash
#Scripts to start out providers if not working
#Specify DMGR Path Right here
DMGR=/decide/IBM/WebSphere/AppServer/profiles/Dmgr01
#Specify Profile Path Right here
Profile=/decide/IBM/WebSphere/AppServer/profiles/AppSrv01
ps -ef | grep dmgr |grep -v grep > /dev/null
if [ $? != 0 ]
then
$DMGR/bin/startManager.sh > /dev/null
fi
ps -ef | grep nodeagent |grep -v grep > /dev/null
if [ $? != 0 ]
then
$Profile/bin/startNode.sh > /dev/null
fi
ps -ef | grep server1 |grep -v grep > /dev/null
if [ $? != 0 ]
then
$Profile/bin/startServer.sh server1 > /dev/null
fi
Comment: Change the trail to suit your setting and add extra guidelines for multiple JVM.
- Change the file permission to be executable
chmod 755 startwasifdown.sh
Take a look at it manually, and when you’re proud of it, you possibly can put this in cron to run it each quarter-hour or no matter you need.
*/1 * * * * /decide/ startwasifdown.sh
That is only a guideline so that you can automate issues.
Do you want automation? Study extra about bash shell scripting.