[Tutorial] Server Restarter for linux
#1


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.
Код:
#!/bin/sh

sampdir="/home/samp"
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 ""

fi
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/autorestart.sh >/dev/null 2>&1
But! before throwing it in, you need to change the "/home/samp/autorestart.sh" 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/autorestart.sh >/dev/null 2>&1
Check every 2 minutes
Код:
*/2 * * * * /home/samp/autorestart.sh >/dev/null 2>&1
Check every 5 minutes
Код:
*/5 * * * * /home/samp/autorestart.sh >/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.
Enjoy

Reply


Messages In This Thread
[Tutorial] Server Restarter for linux - by ZuppR - 20.10.2008, 02:13
Re: [Tutorial] Server Restarter for linux - by ZuppR - 20.10.2008, 13:19
Re: [Tutorial] Server Restarter for linux - by ZuppR - 20.10.2008, 21:24
Re: [Tutorial] Server Restarter for linux - by Tenshi - 20.10.2008, 21:42
Re: [Tutorial] Server Restarter for linux - by Tenshi - 20.10.2008, 22:15
Re: [Tutorial] Server Restarter for linux - by Tenshi - 21.10.2008, 00:16
Re: [Tutorial] Server Restarter for linux - by ZuppR - 21.10.2008, 01:50
Re: [Tutorial] Server Restarter for linux - by Tenshi - 21.10.2008, 01:59
Re: [Tutorial] Server Restarter for linux - by Tenshi - 24.10.2008, 11:33
Re: [Tutorial] Server Restarter for linux - by [M]deLux - 24.10.2008, 13:49

Forum Jump:


Users browsing this thread: 1 Guest(s)