Discord

Server Monitor script for Linux

Posted in Coding

So you have a server running on Linux and sometimes it crashes ... some restart automatically, some dont. Here is a little bash script that will keep your server running.
My example server is an Urban Terror server and my start line is this ...
./urt-ffa.i386 +set net_port 27961 +exec server.cfg
To run the server in the background I add an ampersand & at the end.  So it doesnt exit when I logout of the SSH I add nohup at the beginning
nohup ./urt-ffa.i386 +set net_port 27961 +exec server.cfg &
So that works until the server crashes.  So what I did was create a little script that checks if the server is running every 30 seconds, if not then it starts it back up.  This file is called monitor.sh and I start it at the command line with 
nohup ./monitor.sh & 
I added the nohup and ampersand because I want THIS script to run in the background too, it needs to run after I logout.  One benefit of using nohup is that it outputs all the servers output into nohup.out so you have a log file. 

#!/bin/bash
cd /home/frank/urt/ffa
# start server
nohup ./urt-ffa.i386 +set net_port 27961 +exec server.cfg &

while true
do
sleep 30s
if ps -ef | grep -v grep | grep urt-ffa.i386 >/dev/null
then
date > lastchecked.txt
else
date >> lastcrashed.txt
nohup ./urt-ffa.i386 +set net_port 27961 +exec server.cfg &
fi

done

Comments  

0 # shootingblanks 2018-07-17 23:14
This is a dandy article
Reply | Reply with quote | Quote
0 # shootingblanks 2018-07-18 00:18
replaying to my own comment
Reply | Reply with quote | Quote
0 # shootingblanks 2018-07-18 00:13
fafsda fda fdsa f safda dsa fdsa fsafdsafsa fds afdsa
Reply | Reply with quote | Quote
0 # shootingblanks 2018-07-18 00:25
[wiki]https://en.wikipedia.org/wiki/Nigger_in_the_ woodpile[/wiki]
Reply | Reply with quote | Quote
0 # shootingblanks 2018-07-18 00:28
  • https://www.youtube.com/watch?v=V4cWxcuWLas&list=LLsjePNLJIWakC-eZBR95dkA&index=2
Reply | Reply with quote | Quote

Recently Online

shootingblanks   admin   UriyTex