SA-MP Forums Archive
[Help]Keeping the Server Online for linux - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help]Keeping the Server Online for linux (/showthread.php?tid=515792)



[Help]Keeping the Server Online for linux - lucas_mdr1235 - 28.05.2014

hello! wish you could help me in the consule 'PuTTY' error.
PHP код:
root@PlayVirtualReality:~# cd samp
root@PlayVirtualReality:~/samp# cd samp03
root@PlayVirtualReality:~/samp/samp03# nohup ./restart.sh &
[127278
root
@PlayVirtualReality:~/samp/samp03# nohup: ignoring input and appending output to `nohup.out'
nohupfailed to run command `./restart.sh': Permission denied 
my code:
PHP код:
#!/bin/sh
log=samp.log
dat
=`date`
samp="/root/samp/samp03/samp03svr"
cd /root/samp/samp03
 
echo "${dat} watchdog script starting." >>${log}
while 
true; do
        echo 
"${dat} Server exited, restarting..." >>${log}
        
mv /root/samp/samp03/server_log.txt /root/samp/samp03/scriptfiles/Logs/server_log.`date '+%m%d%y%H%M%S'`
        ${
samp} >> $log
    sleep 2
done 
I am using method 2 of the link below.
https://sampwiki.blast.hk/wiki/Linux_Ser..._Server_Online


Re: [Help]Keeping the Server Online for linux - AssBlaster - 28.05.2014

That code looks pretty bad. Here's something I did a while ago:

This code will ensure that your server is restarted if it's down. (Save the file as: autorestart.sh)
PHP код:
#!/bin/sh
msampdir="/home/samp"
mprocess=`ps -C samp03svr | grep -v PID`
if [ ! 
"$mprocess]; then
    
echo "=- SA-MP server is not running. Restarting... -="
    
    
cd "$msampdir"
    
nohup ./samp03svr &
fi 
If you want to save logs, try this: (Save the file as: logrestarter.sh)
PHP код:
#!/bin/sh
logfile="/home/samp/server_log.txt"
timestamp=$(date --utc +%s)
thedate=$(date +"%B %d, %Y - %l:%M:%S")
logdir="/home/samp/server_logs"
if [ ! -"$logdir]
then
    mkdir 
"$logdir"
fi
cat 
"$logfile"$logdir"/Logs_Server_$timestamp.txt
echo "SAMP Logs refreshed at: $thedate"$logfile
In this case you will need to edit your crondtab file to the following:
PHP код:
SHELL=/bin/bash
PATH
=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO
=root
HOME
=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
  
*/* * * * samp /home/samp/autorestart.sh
  0 
*/12 * * * samp /home/samp/logrestarter.sh 
That will run a task every 1 minute and will check if your server is up and running. The other task will run every 12 hours and it will save your logs to the folder you chose.

After editing your crondtab file, run the following command in putty:

service crond restart

Just edit the paths to however you want it.

(Note; Make sure you chmod +x autorestart.sh, logrestarter.sh and server_log.txt)


Re: [Help]Keeping the Server Online for linux - lucas_mdr1235 - 28.05.2014

this is my difficulty in editing the file crondtab could help me.


Re: [Help]Keeping the Server Online for linux - rymax99 - 28.05.2014

Quote:
Originally Posted by lucas_mdr1235
Посмотреть сообщение
this is my difficulty in editing the file crondtab could help me.
Use ******, there's tons of articles on it, no sense in someone spoon feeding you here.


Re: [Help]Keeping the Server Online for linux - lucas_mdr1235 - 29.05.2014

I managed to edit, but now I turn off the server through the RCON and serves no league, which will be the reason? I left the last blank line! how to test to see if the system is working? what command to turn off the system autorestart.sh?