Instance Down
Instance Down
The Instance was down twice last night. The first time I restarted MariaDB from my phone via a SSH session. The second time it was near time to go home when I noticed so I let it be until I could get to the house. I decided that seeing I cannot seem to get the services tweaked for all cases and I have not seen what is causing them to crash. Though PHP-FPM and MariaDB take turns shutting down on the Instance. I would at least like to make sure the Instance does not stay down for a prolonged period of time. I wrote a quick and dirty bash script to check the services on the Instance and to start them if they are not active. I then added a line on the system crontab to run the script every 15 minutes. So in a worse case scenario the Instance could be down for 15 minutes if it happens to go down directly after a check. For now this will make sure the Instance stays up until I can find out what is causing the shutdowns and fix the issues. I am sure there are many and it is not just one simple problem. 😉
If any other administrator is curios the script is quite simple.
#!/usr/bin/env bash
# Check to be sure all services are active, if not start them
# This shell script is invoked by cron every 15 minutes on this server
# note: The script does nothing if the services are active.
apache_status=$(systemctl is-active httpd)
mariadb_status=$(systemctl is-active mariadb)
phpfpm_status=$(systemctl is-active php-fpm)
if [ "$mariadb_status" == "failed" ]; then
systemctl start mariadb
fi
if [ "$phpfpm_status" == "failed" ]; then
systemctl start php-fpm
fi
if [ "$apache_status" == "failed" ]; then
systemctl start httpd
fi
unset apache_status
unset mariadb_status
unset phpfpm_status
This of course only works if you are using systemd
to manage your services on your system. I named the script services
(no extension as bash scripts should not have an extension in most cases). I also invoke it in via cron every 15 minutes. The crontab is located in /etc/crontab
for most 'nix type systems. I put the bash script in /var/www/html/bin
where all the other Instance scripts are. You should have cron run the script as root so that the services can be started if need be.
# Example crontab line in /etc/crontab
# insert this at the end of the current crontab
*/15 * * * * root cd /var/www/html/bin; ./services
Sorry for the inconvenience of the Instance being down.
Radio Free Trumpistan likes this.
Radio Free Trumpistan
in reply to Unus Nemo • •@Unus Nemo
Last night I was participating in Monsterdon but hadn't done anything but boost other posts for Hashtag Games when it went down once, so all I did was participate in doing exactly that on My Portal. I'm relieved that I didn't cause the second outage, ha. I wasn't aware of the 2nd time til just now, reading your post.
The time stamp on my last post last night is 01:24:01
Unus Nemo likes this.
Unus Nemo
in reply to Radio Free Trumpistan • •@Radio Free Trumpistan
I doubt you had anything to do with either outage. The first time it was MariaDB that went down and that has never happened due to hashtaggames, that was PHP-FPM. The second time it was PHP-FPM that went down and there was no activity on the site when it happened so I am looking into it. I posted right before I went to sleep, after writing the script so I am just getting up. 😉
Radio Free Trumpistan likes this.
Radio Free Trumpistan
in reply to Unus Nemo • •Good to know--and I can't say enough about how much I appreciate all the work you put into it. ❤
Unus Nemo likes this.