SA-MP Forums

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

Reply
 
Thread Tools Display Modes
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
Old 20/10/2008, 01:19 PM   #2
ZuppR
Little Clucker
 
Join Date: Feb 2008
Posts: 11
Reputation: 0
Default Re: [Tutorial] Server Restarter for linux

Quote:
Originally Posted by Westie
I'm afraid that you're a bloody failure, because you use pico/nano. :P I don't get why you're using ps for your process ID, why don't you just use pidof instead?
Haha
Pico/nano simply is the best.

ps/pidof, just a matter of what you like, both would do just perfect. :P
ZuppR is offline   Reply With Quote
Old 20/10/2008, 09:24 PM   #3
ZuppR
Little Clucker
 
Join Date: Feb 2008
Posts: 11
Reputation: 0
Default Re: [Tutorial] Server Restarter for linux

Quote:
Originally Posted by Westie
(I use vi btw)

BTW, is the $11 a typo? Shouldn't it be $1 with ps?
Ah yes, a typo.
My bad.
ZuppR is offline   Reply With Quote
Old 20/10/2008, 09:42 PM   #4
Tenshi
Huge Clucker
 
Join Date: Feb 2007
Location: USA/East Coast (for now)
Posts: 207
Reputation: 32
Default Re: [Tutorial] Server Restarter for linux

I did:

*/1 * * * * /var/removed/ptp/autorestart/ohsamp.sh >/dev/null 2>&1

in putty and i got:

E486: Pattern not found: 1 * * * *

i using windows nano but i dont know if i supposed to connect with that, i am using putty, please help
__________________
Quote:
* 07:52:58 [AM] * You were kicked from #sa-mp by JailBait (Refusing to get naked.)
Tenshi is offline   Reply With Quote
Old 20/10/2008, 10:15 PM   #5
Tenshi
Huge Clucker
 
Join Date: Feb 2007
Location: USA/East Coast (for now)
Posts: 207
Reputation: 32
Default Re: [Tutorial] Server Restarter for linux

still get E486: Pattern not found: * * * * *

i did
*/ * * * * /var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1
then i tryed
1*/ * * * * /var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1
same error, and i cant use:
*/ * * * * /var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1
or
* * * * /var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1
putty doesn't read **** and it goes to /var/www/....

(using putty)
__________________
Quote:
* 07:52:58 [AM] * You were kicked from #sa-mp by JailBait (Refusing to get naked.)
Tenshi is offline   Reply With Quote
Old 21/10/2008, 12:16 AM   #6
Tenshi
Huge Clucker
 
Join Date: Feb 2007
Location: USA/East Coast (for now)
Posts: 207
Reputation: 32
Default Re: [Tutorial] Server Restarter for linux

Quote:
Originally Posted by Trucecity
* * * * * /var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1
putty doesn't read * * * * * and it goes to /var/www/....

(using putty)
same, i get:
E846: pattern not found: var
and * * * * * disapears and shows this var/www/vhosts/ptpserver.com/private/ptp/autorestart/ohsamp.sh >/dev/null 2>&1 and gives me errors... a bit weird on my end.

i will get my friend on this and see if he gets the same errors and i will report back here.
__________________
Quote:
* 07:52:58 [AM] * You were kicked from #sa-mp by JailBait (Refusing to get naked.)
Tenshi is offline   Reply With Quote
Old 21/10/2008, 01:50 AM   #7
ZuppR
Little Clucker
 
Join Date: Feb 2008
Posts: 11
Reputation: 0
Default Re: [Tutorial] Server Restarter for linux

Which distro are you using?
ZuppR is offline   Reply With Quote
Old 21/10/2008, 01:59 AM   #8
Tenshi
Huge Clucker
 
Join Date: Feb 2007
Location: USA/East Coast (for now)
Posts: 207
Reputation: 32
Default Re: [Tutorial] Server Restarter for linux

Quote:
Originally Posted by Bry4n
Which distro are you using?
w/ crapy plesk...
CentOS 5
Operating system Linux 2.6.9-023stab048.4-enterprise
__________________
Quote:
* 07:52:58 [AM] * You were kicked from #sa-mp by JailBait (Refusing to get naked.)
Tenshi is offline   Reply With Quote
Old 24/10/2008, 11:33 AM   #9
Tenshi
Huge Clucker
 
Join Date: Feb 2007
Location: USA/East Coast (for now)
Posts: 207
Reputation: 32
Default Re: [Tutorial] Server Restarter for linux

anyone?
__________________
Quote:
* 07:52:58 [AM] * You were kicked from #sa-mp by JailBait (Refusing to get naked.)
Tenshi is offline   Reply With Quote
Old 24/10/2008, 01:49 PM   #10
[M]deLux
Big Clucker
 
Join Date: Jun 2007
Posts: 134
Reputation: 0
Default Re: [Tutorial] Server Restarter for linux

try to create the crontab in a new, empty file

then do
Code:
crontab new_empty_file
now check with
Code:
crontab -d
if your cron occurs there

hint: you may use
Code:
-u someuser
with the crontab command to setup it for another user
[M]deLux is offline   Reply With Quote
Reply

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 07:05 AM.


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