26 Dec 13, 01:14AM
(This post was last modified: 26 Dec 13, 01:16AM by RandumKiwi.)
(25 Dec 13, 11:26PM)Ronald_Reagan Wrote: Thank you for telling me, I will check on that within a day.
Run this script with Cron, every minute. It's a super efficient script, so it won't affect the running of your servers.
[SELECT ALL] Code:
#!/bin/sh
# Checks if your AssaultCube servers are up, and if not, attempts to
# reboot them and sends you an e-mail to let you know whether that
# reboot failed or not. Please ensure you've install mailutils:
#
# sudo apt-get install mailutils
#
# Change all of the below aliases for this to work!
###
# E-mail subject:
ESUBJECT="XYZ SERVER DIED!"
###
# E-mail address:
EMAILADDR="[email protected]"
###
###
# The AC directory (no trailing slash):
THEACDIR="/path/to/AC"
###
# Name of the server executable in bin_unix directory:
NAMEEXEC1="linux_server"
###
# Name of the shell-file to run that restarts your AC server:
ACSHEXEC1="server.sh"
###
###
# Where to place the files for counting fails, which will prevent excessive server restarts.
# Filenames are dated, so files can be arranged by name (no folders per-server required).
# It goes without saying, ensure the directory exists and read/write-permission is available.
#
FILECOUNTDIR="/path/to/where_ever"
###
# FYI: This essentially allows you to log when your server fails, so I suggest not to delete them.
# however, if you do want to delete them, please uncomment the following line and they'll be
# deleted once 24 hours old.
#DELETECOUNTFILES="1"
###
### This script has no log-rotate facility, your server shouldn't be crashing that much!
###
# Name of logfiles (i.e. your servername):
NAMESERV1="AC"
###
# What to write in your e-mail if your reboot was successful:
IFSUC1="Server died, reboot succesful at "$(date +%F-%T)"."
###
# What to write in your e-mail if your reboot was *NOT* successful:
IFFAIL1="Server died. Reboot failed at "$(date +%F-%T)"."
###
# What to write in your e-mail after 3 failed restarts in 12 hours:
IFDONE1="Server died 3x in 12 hours, something is VERY wrong. Please investigate, no further reboots will be done."
###
if [ -z "$(pidof $NAMEEXEC1)" ]; then
touch "$FILECOUNTDIR"/"$NAMESERV1"-at-"$(date +%F-%H.%M.%S)".fail && sleep 1 # Long version of time, for Windows compatiblity.
HOWMANYFAILS=`cd "$FILECOUNTDIR" && find ./"$NAMESERV1"* -mmin -720 | wc -l`
if [ "$HOWMANYFAILS" -le "3" ]; then
sh "$THEACDIR"/"$ACSHEXEC1"
sleep 5
if [ -n "$(pidof $NAMEEXEC1)" ]; then
echo "$IFSUC1" | mail -s "$ESUBJECT" "$EMAILADDR"
else
echo "$IFFAIL1" | mail -s "$ESUBJECT" "$EMAILADDR"
fi
elif [ "$HOWMANYFAILS" = "4" ]; then
echo "$IFDONE1" | mail -s "$ESUBJECT" "$EMAILADDR"
fi
if [ "$DELETECOUNTFILES" = "1" ]; then
cd "$FILECOUNTDIR" && find ./"$NAMESERV1"* -mmin +1440 | xargs rm -f
fi
fi
(note, this script DOES reinvent the wheel (there are programs in Linux that checks if programs have failed, etc), HOWEVER, the "wheel", is far too complex for my needs... this simple script will do nicely)