SA-MP Forums

Go Back   SA-MP Forums > SA-MP Server > Server Support

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 20/10/2008, 02:13 AM   #1
ZuppR
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.
Code:
#!/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".
Code:
*/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
Code:
*/1 * * * * /home/samp/autorestart.sh >/dev/null 2>&1

Check every 2 minutes
Code:
*/2 * * * * /home/samp/autorestart.sh >/dev/null 2>&1

Check every 5 minutes
Code:
*/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

ZuppR is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux server restarter Kurence Server Support 4 04/10/2009 08:46 PM
[Tutorial] Server restarter for Windows boylett Server Support 6 11/08/2009 03:09 PM
[Tool/Web/Other] [APP] Server Restarter 1.0 Pixels^ Filterscripts 26 24/06/2009 03:08 PM
Linux Server Restarter [Help] BP13 Help Archive 2 11/06/2009 03:16 AM
Restarter for Linux (please help!) SEC Server Support 26 14/01/2009 02:03 PM


All times are GMT. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.