Results 1 to 10 of 10

Thread: Start Server Automatically (1)

  1. #1
    Refugee
    Join Date
    Oct 2019
    Posts
    14
    Rep Power
    0

    Start Server Automatically (1)

    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

  2. #2
    Colony Founder meganoth's Avatar
    Join Date
    Mar 2017
    Posts
    2,888
    Rep Power
    1
    Here are a few script examples: https://stackoverflow.com/questions/...ess-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 meganoth; 5 Days Ago at 02:28 PM.

  3. #3
    Refugee
    Join Date
    Oct 2019
    Posts
    14
    Rep Power
    0
    Hi,

    Should i replace echo restart with this $HOME/steamcmd/7daysded/./startserver.sh ?

  4. #4
    Ranger Sam_Neill's Avatar
    Join Date
    Sep 2018
    Location
    Germany
    Posts
    256
    Rep Power
    1
    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.
    7dtd.sh start smallisland
    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 Sam_Neill; 5 Days Ago at 05:42 PM.

  5. #5
    Colony Founder meganoth's Avatar
    Join Date
    Mar 2017
    Posts
    2,888
    Rep Power
    1
    Quote Originally Posted by estiaan1234 View Post
    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 meganoth; 5 Days Ago at 07:47 PM.

  6. #6
    Refugee
    Join Date
    Oct 2019
    Posts
    14
    Rep Power
    0
    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

  7. #7
    Colony Founder meganoth's Avatar
    Join Date
    Mar 2017
    Posts
    2,888
    Rep Power
    1
    I just saw I made a mistake: The script should check for == "0", not for == "1".

  8. #8
    Refugee
    Join Date
    Oct 2019
    Posts
    14
    Rep Power
    0
    Hi Meganoth,

    can i just paste that code and replace the 0 with the 1 and replace the other stuff aswell?

  9. #9
    Colony Founder meganoth's Avatar
    Join Date
    Mar 2017
    Posts
    2,888
    Rep Power
    1
    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.

  10. #10
    Refugee
    Join Date
    Oct 2019
    Posts
    14
    Rep Power
    0
    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
    Last edited by estiaan1234; 3 Days Ago at 04:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •