12-08-2008, 09:45 PM
Here's code how you can set up Monit to keep monitoring game server and making sure it's running good.
With this setup Monit will restart the server - if it's not working - maximum three times in ten minutes. Then it will give up and send you email telling that the server is down. In most cases this probably means that Monit gets the server up and running and never sends the email. Thus, if you ever get email from this you'll know the server has been down for 10 minutes and it's been restarted three times already, so there's something really wrong.
Instructions for Debian:
1. apt-get install monit
2. Edit /etc/default/monit (change startup=1 and CHECK_INTERVALS=30)
3. Edit /etc/monit/monitrc (add line: include /etc/monit.d/*)
4. Create directory /etc/monit.d/ (mkdir /etc/monit.d)
5. Paste the contents below to /etc/monit.d/srcds_server1
* Special: use these startup scripts (start.sh and stop.sh). Copy & paste the code to your srcds install directory.
/home/user/csds/start.sh
/home/user/csds/stop.sh
/etc/monit.d/srcds_server1
Ask more information here if you don't get it working.
I've had this running for few days now. The game server hasn't crashed during that time so severely that Monit should've done something, so I haven't seen this work except in the testing phase.
Post here or send me PM if you use the script. I can provide support here or via PM.
With this setup Monit will restart the server - if it's not working - maximum three times in ten minutes. Then it will give up and send you email telling that the server is down. In most cases this probably means that Monit gets the server up and running and never sends the email. Thus, if you ever get email from this you'll know the server has been down for 10 minutes and it's been restarted three times already, so there's something really wrong.
Instructions for Debian:
1. apt-get install monit
2. Edit /etc/default/monit (change startup=1 and CHECK_INTERVALS=30)
3. Edit /etc/monit/monitrc (add line: include /etc/monit.d/*)
4. Create directory /etc/monit.d/ (mkdir /etc/monit.d)
5. Paste the contents below to /etc/monit.d/srcds_server1
* Special: use these startup scripts (start.sh and stop.sh). Copy & paste the code to your srcds install directory.
/home/user/csds/start.sh
Code:
#!/bin/sh
cd /home/user/csds/
screen -A -m -d -S csds ./srcds_run -game cstrike -console +maxplayers 32 +port 27015 +ip 1.2.3.4 -tickrate 66 +map de_dust2
/home/user/csds/stop.sh
Code:
#!/bin/bash
screen -dr csds -X quit
/etc/monit.d/srcds_server1
Code:
CHECK HOST srcds_server1 ADDRESS 1.2.3.4
START PROGRAM = "/home/user/csds/start.sh" AS UID user AND GID user
STOP PROGRAM = "/home/user/csds/stop.sh" AS UID user AND GID user
IF FAILED PORT 27015 TYPE UDP
SEND "\0xFF\0xFF\0xFF\0xFFi"
EXPECT ""
WITH TIMEOUT 1 SECONDS
FOR 3 CYCLES
THEN RESTART
EVERY 3 CYCLES
IF 3 RESTARTS WITHIN 10 CYCLES THEN TIMEOUT
ALERT your_email@something.foo ON {timeout}
WITH MAIL-FORMAT {
from: monit@$HOST
subject: $HOST: Srcds down
message: $HOST: Srcds down since $DATE
}
Ask more information here if you don't get it working.
I've had this running for few days now. The game server hasn't crashed during that time so severely that Monit should've done something, so I haven't seen this work except in the testing phase.
Post here or send me PM if you use the script. I can provide support here or via PM.