It’s common for the process to crash/go down due to various reasons, which you can investigate and fix the issues but that may take a little time. However, one thing you can do it immediately to reduce the downtime for better availability is to automate restart of the process if it’s down. Let’s get this done through the freeway – shell scripts You can use following shell scripts to run through crontab, which will check the services at every 15 minutes (you can adjust the interval time) and will start if found not running. Sounds cool? In this article, I will give two examples of starting the services if down.
Auto-restart MySQL, PHP-FPM, Nginx if down
A few weeks back, I moved Geek Flare to DigitalOcean with EasyEngine and MariaDB crashed twice in one week.
You see it crashed early morning and was down for more than 3 hours, which is not good. It’s my blog, so no $$$ impact but I still feel bad for it. Ok, showtime now…
Create a file using vi editors at your desired location (in this demo I will put it under /opt/startifdown.sh) Copy & paste below script to the file and save it
Change the file permission to be executable
Test it manually to ensure the script is executable. You may stop the service and use the script to check if it’s starting up. Once you are satisfied, you can put this in cron to run every 15 minutes. Refer my crontab article if you need some inspiration in changing the interval time. Now, this little script will take care of starting the services if crashed and I won’t have those 3 hours of downtime. Much better!
Auto-restart WebSphere DMGR, Nodeagent, JVM if down
Create a file with following scripts – I will name it startwasifdown.sh Note: Change the path to suit your environment and add more lines for more than one JVM.
Change the file permission to be executable
Test it manually, and once you are happy with it, you can put this in cron to run it every 15 minutes or whatever suits you. This is just a guideline for you to automate the stuff. Love automation? Learn about bash shell scripting.