estiaan1234 Posted November 9, 2019 Share Posted November 9, 2019 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 Link to comment Share on other sites More sharing options...
meganoth Posted November 9, 2019 Share Posted November 9, 2019 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 #!/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. Link to comment Share on other sites More sharing options...
estiaan1234 Posted November 9, 2019 Author Share Posted November 9, 2019 Hi, Should i replace echo restart with this $HOME/steamcmd/7daysded/./startserver.sh ? Link to comment Share on other sites More sharing options...
Sam_Neill Posted November 9, 2019 Share Posted November 9, 2019 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: #!/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 Link to comment Share on other sites More sharing options...
meganoth Posted November 9, 2019 Share Posted November 9, 2019 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. Link to comment Share on other sites More sharing options...
estiaan1234 Posted November 9, 2019 Author Share Posted November 9, 2019 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 Link to comment Share on other sites More sharing options...
meganoth Posted November 10, 2019 Share Posted November 10, 2019 I just saw I made a mistake: The script should check for == "0", not for == "1". Link to comment Share on other sites More sharing options...
estiaan1234 Posted November 10, 2019 Author Share Posted November 10, 2019 Hi Meganoth, can i just paste that code and replace the 0 with the 1 and replace the other stuff aswell? Link to comment Share on other sites More sharing options...
meganoth Posted November 11, 2019 Share Posted November 11, 2019 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. Link to comment Share on other sites More sharing options...
estiaan1234 Posted November 11, 2019 Author Share Posted November 11, 2019 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/bash if 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.