Results 1 to 10 of 24

Thread: [CoD2/CoD4] Server auto-restart

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Private CaptainSlow's Avatar
    Join Date
    Nov 2014
    Posts
    76
    Thanks
    38
    Thanked 28 Times in 23 Posts
    Here's a script I hacked together back in 2013 but it should still work.

    Install steps:
    1. Save the script as mon.sh
    2. Adjust the serverport to reflect your own config (28960 = default)
    3. Make the file executable and adjust the paths (file locations). Note: If you do not have a start.sh script to start your server, see below, I included one.
    4. Schedule it as a crontab every minute, like so:
    * * * * * /path/to/watchdog/script/mon.sh >/dev/null 2>&1

    Code:
    #!/bin/bash
    # COD2 Process Monitor - Server 1
    # Restart COD2 Server When It Goes Down
    
    #Restart Command
    RESTART="/path/to/start/script/start.sh"
    
    #path to pgrep command
    PGREP="/usr/bin/pgrep"
    
    # find httpd pid
    $PGREP -f '.*28960'
    
    if [ $? -ne 0 ] # if server not running
    then
    # restart server
    $RESTART
    fi
    This script works with multiple COD servers on the same physical server. Just save multiple copies of the script and adjust the server port.

    In case you are not using a bash script to start your server, here's an example that uses screen to run the server in the background. Save it as start.sh, adjust paths and make it executable (no need to schedule in crontab).
    Code:
    #!/bin/bash
    cd /home/cod2/cod2/
    
    # Start server now!
    screen -A -m -d -S cod2pub /home/cod2/cod2/cod2_lnxded +set net_port 28960 +exec server.cfg +fs_homepath /home/cod2/cod2/

  2. The Following 2 Users Say Thank You to CaptainSlow For This Useful Post:

    kung foo man (8th September 2015),Mitch (8th September 2015)

  3. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by CaptainSlow View Post
    Here's a script I hacked together back in 2013 but it should still work.

    Install steps:
    1. Save the script as mon.sh
    2. Adjust the serverport to reflect your own config (28960 = default)
    3. Make the file executable and adjust the paths (file locations). Note: If you do not have a start.sh script to start your server, see below, I included one.
    4. Schedule it as a crontab every minute, like so:
    * * * * * /path/to/watchdog/script/mon.sh >/dev/null 2>&1

    Code:
    #!/bin/bash
    # COD2 Process Monitor - Server 1
    # Restart COD2 Server When It Goes Down
    
    #Restart Command
    RESTART="/path/to/start/script/start.sh"
    
    #path to pgrep command
    PGREP="/usr/bin/pgrep"
    
    # find httpd pid
    $PGREP -f '.*28960'
    
    if [ $? -ne 0 ] # if server not running
    then
    # restart server
    $RESTART
    fi
    This script works with multiple COD servers on the same physical server. Just save multiple copies of the script and adjust the server port.

    In case you are not using a bash script to start your server, here's an example that uses screen to run the server in the background. Save it as start.sh, adjust paths and make it executable (no need to schedule in crontab).
    Code:
    #!/bin/bash
    cd /home/cod2/cod2/
    
    # Start server now!
    screen -A -m -d -S cod2pub /home/cod2/cod2/cod2_lnxded +set net_port 28960 +exec server.cfg +fs_homepath /home/cod2/cod2/
    So I want to use this script. I just the exact same script, but with other startup, port and screenname.
    I start it with
    Code:
    bash ./autoboot.sh
    The screen is created, but the server is not started inside the screen, but in the "main" Putty window.
    How to fix this?

Posting Permissions

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