2025-04-27 03:32:45
2025-04-27 03:32:45
2025-04-27 03:32:45
4232386
One Small Win At A Time
Wars Are Won, One Small Victory At A Time
A few days ago I decided to add a primitive logging feature to services
so I would know when the services were actually started. At around 8:15pm EST MariaDB was started and at 9:15pm EST PHP-FPM was started. Starting the services when they go down does not fix the problem that causes their failure in the first place. Though it does keep the Instance up and running. One small victory.
#!/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.
# Added primitive logging by appending to ../log/services.log every
# time that a service needs to be started.
# It is assumed that this script is launched from /var/www/html/bin
# and services.log is in /var/www/html/log
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
echo "$(date) Had to start MariaDB!" >> ../log/services.log
fi
if [ "$phpfpm_status" == "failed" ]; then
systemctl start php-fpm
echo "$(date) Had to start PHP-FPM!" >> ../log/services.log
fi
if [ "$apache_status" == "failed" ]; then
systemctl start httpd
echo "$(date) Had to start Apache!" >> ../log/services.log
fi
unset apache_status
unset mariadb_status
unset phpfpm_status