restart.sh
#1

Whenever I try to use the restart.sh script posted on samp wiki, I get the following error in putty:

Код:
nohup: failed to run command `./server.sh': No such file or directory
The file itself is the in right directory and the paths are correct inside the files.

Код:
#!/bin/sh
log=samp.log
dat=`date`
samp="/home/server/samp03/samp03svr"
cd /home/server/samp03
 
echo "${dat} watchdog script starting." >>${log}
while true; do
        echo "${dat} Server exited, restarting..." >>${log}
        mv /home/server/samp03/server_log.txt /home/server/samp03/logs/server_log.`date '+%m%d%y%H%M%S'`
        ${samp} >> $log
	sleep 2
done
When I run nohup ./samp03svr & the server starts fine but not when I run the restart.sh file.
Reply
#2

chmod +x server.sh
Reply
#3

it already has 777 privileges.
Reply
#4

I'll give you my method of doing things, since I feel it's probably one of the better, since it's extremely automated. Since this will crowd up /var/log/syslog with the message saying that it ran the cron script (if you care/read system logs), I made cron messages log to /var/log/cron.log. If you care about that, let me know and I'll explain how to move cron logs to another log location. Note that logs automatically refresh themselves in /var/log daily if I remember, so it's not a big deal at all.

For explanation purposes, we'll say that /home/sampserver/samp03svrlocation/autorestart.sh is the location of the auto restart script, and /home/sampserver/samp03svrlocation is the location which holds samp03svr.

I run this script in cron every minute:
One minute is most viable as running a auto restart script every second is just stupid, it doesn't even allow the SA-MP server to crash in peace.
To open cron, use crontab -e -u userhere (never run the SA-MP server as root).
Код:
*/1 * * * * /home/sampserver/samp03svrlocation/autorestart.sh >/dev/null 2>&1
If you need to keep your server offline for maintenance, simply comment out that cron entry with a #, or just rename the server.cfg file to something like cfg so it won't start.

/home/sampserver/samp03svrlocation/autorestart.sh contains this (I believe it's a modified version of something on the SA-MP wiki, I think I just added cd to it, I can't remember.):
Код:
#!/bin/sh
user=sampserveruser
serverlocation=/home/sampserver/samp03svrlocation #(same directory as samp03svr)
PROCESS_COUNT=$(ps -fu $user | grep samp03svr | grep -v grep | wc -l)
case $PROCESS_COUNT in
0)      cd $serverlocation
        nohup ./samp03svr >>nohup.out 2>&1 &
        printf "PID:%s:" "$!"
;;
1) #OK, program is already running once
;;
*) #OK, program is already multiple times
;;
esac
Make sure to make that script excutable with chmod +x autorestart.sh.

Added some variables in it to make it easier for you or anyone else to change. It's self explanatory, but you must change the variables of course. I've tested it and it works fine.

Some notes:
-I'm pretty sure that it'll work fine for multiple servers too as long as you run them on different users, as it checks for the process via the user.
-You need to make sure you're editing/adding the entry for crontab on the same user the SA-MP server is running on, otherwise it'll just start a new server process, since it finds the samp03svr processes via the user they're running on.

Please note, it's 1:35 AM for me, so if there's anything wrong, my bad. I actually did some edits to the server checker right now to add variables, and retested it, and it works fine.
Reply
#5

If it's "restart.sh", why are you trying to run server.sh ?

nohup ./restart.sh &
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)