Originally Posted by SAMP WIKI
Keeping the Server Online
With limited anti-crash options available in the SA-MP Server, there is a large possibility of receiving Segmentation Faults or any other error generated by your (Pawn) gamemode. This will shutdown the server, and you'll have to start it up yourself again. Method 1 All you need to use the program below is a Linux environment, and the possibility to use cron. This program will check if the samp03svr process is running, and if it isn't, start it up again. You'll need to install the following crontab: */1 * * * * /path/to/samp/checksamp.sh >/dev/null 2>&1 Help about using crontab can be found here. checksamp.sh: #!/bin/sh PROCESS_COUNT=$(ps -fu root | grep samp03svr | grep -v grep | wc -l) case $PROCESS_COUNT in 0) /path/to/samp03svr & ;; 1) #OK, program is already running once ;; *) #OK, program is already multiple times ;; esac Make sure that you have to correct paths set up, the script won't work if you haven't. The script is currently unable to handle multiple SA-MP Servers on the same machine, but works perfectly when there is only one running/needed. You need to chmod the checksamp.sh file to 0755 (+x)! Method 2 If you don't want to use crontab and if you want to have server log saved to a separate directory on server crash you can use this script. To keep your server online using this script, first you need to stop your server and then execute it with this command: nohup ./restart.sh & restart.sh: #!/bin/sh log=samp.log dat=`date` samp="/path/to/samp/server/samp03svr" cd /path/to/samp/server echo "${dat} watchdog script starting." >>${log} while true; do echo "${dat} Server exited, restarting..." >>${log} mv /path/to/samp/server/server_log.txt /path/to/samp/server/logs/server_log.`date '+%m%d%y%H%M%S'` ${samp} >> $log sleep 2 done This method will bring your server back up whenever it crashes or when the RCON exit command is issued. It will also save the server log into a separate directory. Method 3 You can also restart the server using this pair of shell scripts. Assumed is that the server is located in the /home/sampsvr directory. Script number 1 startgtaserver.sh: #!/bin/bash export GTA_PATH=/home/sampsvr cd $GTA_PATH while [ true ]; do cat {$GTA_PATH}/server_log.txt >> {$GTA_PATH}/full_server_log.txt rm {$GTA_PATH}/server_log.txt touch {$GTA_PATH}/server_log.txt ./samp03svr done This one goes near the server binary. Second script, named gtaserver.sh: #!/bin/bash server_start() { screen /home/sampsvr/startgtaserver.sh & # put in full path and name of startup script } server_stop() { killall startgtaserver.sh # your startup script name killall samp03svr # need to put in path to killall if its not in $PATH } server_restart() { server_stop sleep 1 server_start } case "$1" in 'start') server_start ;; 'stop') server_stop ;; 'restart') server_restart ;; *) echo "usage $0 start|stop|restart" esac Place the script in /usr/local/bin/. Just change paths in both scripts to yours, then you can start your server by typing gtaserver start, stop server by typing gtaserver stop, and finally restart it by typing gtaserver restart. Make sure the scripts are executable. |
./samp03svr
nohup ./samp03svr
put some effort by your own, instead of quoting the wiki exactly the same.
|