View Single Post
Old 20/10/2008, 02:13 AM   #1
Little Clucker
Join Date: Feb 2008
Posts: 11
Reputation: 0
Default [Tutorial] Server Restarter for linux

Seeing this topic has been brought up countless of times, i decided to do a little tutorial.

Then lets make it restart itself!
It's actually simple, and easy to do.

You don't really need anything specific, except for some basic unix knowledge.
This guide is written for debian based distro, but should however work just fine on almost any other.

First of all, open up putty(or any similar terminal)
Go to the dir where you want your autorestart script placed(doing this tutorial i used the sa-mp server dir)

Now, open up your favorite editor (such as pico)

Use the following script, and modify it to fit your directories.

process=`ps auxw | grep samp022svr | grep -v grep | awk '{print $11}'`

if [ -z "$process" ]; then

 echo "sa-mp server not running, restarting it."
 cd "$sampdir"
 nohup ./samp022svr &
 echo ""


At the current stage, it should look similar to this:

If it does, and you're sure that the dir's are replaced with yours, then hit ctrl-x and save it (the file name is important, we need to use it later on, so choose something practical )

Alright, so far so good, lets continue.
It's around the time to finish it off, but first you need to figure out how often you'd like crontab to check whether the server is running or not. (in this tutorial I'm checking every 60 seconds. )

Now it's time to put the following line into a crontab using the command "crontab -e".
*/1 * * * * /home/samp/ >/dev/null 2>&1

But! before throwing it in, you need to change the "/home/samp/" with the dir to where you placed the script you saved before.
You also need to decide what interval it should check whether the server is running or not, its pretty simple, let me show you a few examples on how to change the interval below.

Check every 1 minute
*/1 * * * * /home/samp/ >/dev/null 2>&1

Check every 2 minutes
*/2 * * * * /home/samp/ >/dev/null 2>&1

Check every 5 minutes
*/5 * * * * /home/samp/ >/dev/null 2>&1

As you can see, we're basically just changing the "*/1 *" (to learn more about crontab, ****** it).

Your crontab should look similar to this now:

If it does that, hit ctrl-x and save it.
Then you're done, and you're ready to test it out, by shutting down your server, and see how it reacts.

If you can't get it to work, simply just ask, and I'll try to help you out the best i can.

ZuppR is offline   Reply With Quote