Last active
October 30, 2017 13:55
-
-
Save benyanke/622ae28a69b7d4fa3d61d465ed3dcd8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run this in cron to keep services running if they crash or are killed | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
timestamp=`date --rfc-3339=seconds` | |
user="benyanke" | |
logfile="/home/$user/scripts/logs/startServices.log" | |
function service() { | |
ps auxw | grep "$1" | grep -v grep > /dev/null | |
if [ $? != 0 ] ; then | |
"/etc/init.d/$service" start > /dev/null | |
echo "[" $timestamp "]" >> $logfile | |
echo "$service was restarted." >> $logfile | |
echo "" >> $logfile | |
fi | |
} | |
# Fill in extra services here | |
service apache2 | |
# service nginx | |
service mysql | |
service ssh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mkdir -p /opt/servicewatch; cd /opt/servicewatch; sudo touch /opt/servicewatch/serviceRestart.log; sudo wget https://gist.githubusercontent.com/benyanke/622ae28a69b7d4fa3d61d465ed3dcd8a/raw/5e77f228f535eccdf2a9d33329725f226c81d6b7/KeepServicesRunning.sh; sudo chmod +x *.sh ; sudo mv KeepServicesRunning.sh keepServicesRunning.sh; sudo nano keepServicesRunning.sh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment