Start Server Automatically (1)

Status
Not open for further replies.

estiaan1234

New member
Hi Guys,

My Server has been crashing a lot lately can anyone help me out how to create a cronjob for this?

my game is saved to $HOME/steamcmd/7daysded/./startserver.sh

i need this cron job to run every 5 minutes to check if process 7DaysToDie_86x_64x is running and if not start $HOME/steamcmd/7daysded/nohup ./startserver.sh

 
Here are a few script examples: https://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies

Another (crude but effective) script would be

Code:
#!/bin/bash
if [   `ps -u <user> | grep systemd | wc -l` == "1"             ]; then 
    echo restart 
fi
Replace <user> with your username or id, "systemd" with the name of the 7d2d process (I used "systemd" to test the script), and the echo with your startcode. Those are backticks by the way, not apostrophes.

Better test your script on the command line as well before you put it into the cron. Then test again.

 
Last edited by a moderator:
If you only want to start 7D2D server again in case of a reboot of the system you could also edit the rc.local.

Using Allocs server tools it would look like this:

Code:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
[i][b]7dtd.sh start smallisland[/b][/i]
exit 0
File is located in /etc/rc.local

Exchange smallisland with your instance name you created with allocs server tool.

This will start the server after a reboot.

Edit: Ah i see you want check for the server each n minutes, well maybe it helps some others searching for this topic too :)

 
Last edited by a moderator:
Hi,
Should i replace echo restart with this $HOME/steamcmd/7daysded/./startserver.sh ?
Yes

If I misunderstood and your whole server is crashing all the time, Sam_Neill's answer may be a more appropriate solution. But a constantly crashing server shouldn't be used anyway. Not that the crashing 7D2D isn't worrisome as well.

 
Last edited by a moderator:
Hi,

My Linux server isnt crashing, the 7dtd server just stops automatically for some reason i think it has something to do that i didnt wipe my server when rolling back from A18.1B5 to A18B155, but the oaks dont want to start from scratch so i have to keep the server up, it crashes 1-2 times a week atleast.

All i want is a script that would check if the 7DaysToDie_86x_64x process is running if not start it again

 
Yes but replace the 1 with a 0.

Try the script out on the command line. If it throws an error message it will tell you at which line. Check if the script does what you want. Then add it to the cronjob.

 
Hi,

i managed to get it right, your script kept giving me an error for some reason, but i figured out a script that worked

so i created a file called keepalivescript.sh and put in the below script

#!/bin/bashif pgrep -f "./7DaysToDieServer.x86_64 -configfile=serverconfig.xml -dedicated" > /dev/null

then

echo "Server is Running"

else

nohup $HOME/steamcmd/7daysded/./startserver.sh >> output.log

fi


then i created a crontab with the command to run every 5 minutes

crontab -e
with the following


*/5 * * * * $HOME/keepalivescript.sh

Hope this helps someone with the same issue in the future

 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top