Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: [CoD2/CoD4] Server auto-restart

  1. #1
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts

    [CoD2/CoD4] Server auto-restart

    Quote Originally Posted by Ni3ls
    Hi man,

    My server keeps shutting down, because of segmentation errors. When you first helped me with setting up libcod on my vps, you made some script that auto restarts the server when it's offline. Can you send me that script again? It was extremely usefull.

    Greetz
    PHP Code:
    #!/bin/bash
    while true
    do
        
    LD_LIBRARY_PATH=. LD_PRELOAD=/path/to/libcod/libcod2_1_0.so /path/to/exe/cod2_lnxded +set fs_basepath /path/to/directory +set fs_homepath /path/to/directory +set fs_game yourmod +set net_ip 999.999.999.999 +set net_port 28960 +set developer 0 +set dedicated 2 +set sv_cracked 1 +exec config.cfg +map_rotate
        sleep 1
    done 
    save as exec.sh

    PHP Code:
    #!/bin/bash

    screen -S serv1 /path/to/exec.sh 
    save as serv1.sh

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

    kung foo man (24th August 2015),Ni3ls (27th August 2015),suck000 (4th July 2016)

  3. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Thanks man!

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    I get the error No such file or directory, while the files are there.
    Code:
    #!/bin/bash
    
    screen -S test /exectest.sh
    startexectest.sh

    Code:
    #!/bin/bash
    while true
    do
        LD_LIBRARY_PATH=. LD_PRELOAD=libcod2_1_0.so ./cod2_lnxded +set dedicated 2 +set net_ip 46.4.55.66 +set net_port 28972 +set sv_maxclients 52 +exec servertdm.cfg + exec pws.cfg +set fs_game test + set sv_cracked 1 + set logfile 2
        sleep 1
    done
    exectest.sh


    Both placed in same folder as from where I run the command
    Code:
    bash startexectest.sh

  5. #4
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Ni3ls View Post
    I get the error No such file or directory, while the files are there.
    Code:
    #!/bin/bash
    
    screen -S test /exectest.sh
    Both placed in same folder as from where I run the command
    Code:
    bash startexectest.sh
    Have you tried to execute it with 'sh'?
    Where did you place exectest.sh? In / (root) or home directory (~/exectest.sh)?

    Edit: if startexectest.sh and exectest.sh are in the same directory then you remove \ from your start script.
    Last edited by Mitch; 2nd September 2015 at 16:35.

  6. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by Ni3ls View Post
    I get the error No such file or directory, while the files are there.
    Code:
    #!/bin/bash
    
    screen -S test /exectest.sh
    startexectest.sh
    try screen -S test ./exectest.sh
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  7. #6
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Nah, put in the full path.

    PHP Code:
    #!/bin/bash

    screen -S test /home/username/cod2/exectest.sh 
    That way the file can be executed from any directory without issues.

    Also make sure the file permissions are setup correctly.

    chmod -R 755 ./CoD2

    Edit: Also if you're using root then you're doing it wrong.
    Last edited by filthy_freak_; 3rd September 2015 at 00:43.

  8. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (3rd September 2015)

  9. #7
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Works! But when will the server start again? When there is a script error? Or when somebody did /killserver?

  10. #8
    Private
    Join Date
    Oct 2014
    Posts
    32
    Thanks
    0
    Thanked 5 Times in 4 Posts
    You will need to query the server for 100% working autorestart :O

  11. #9
    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/

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

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

  13. #10
    Private CaptainSlow's Avatar
    Join Date
    Nov 2014
    Posts
    76
    Thanks
    38
    Thanked 28 Times in 23 Posts
    Also, if you're running a Windows server, I suggest looking at 'FireDaemon' which allows you to run any executable as a service. This means that if the exe (i.e. the gameserver) crashes, it automatically restarts it, along with other handy features:
    http://forums.firedaemon.com/howtos/call-of-duty-2.47/

  14. The Following User Says Thank You to CaptainSlow For This Useful Post:

    Mitch (14th September 2015)

Posting Permissions

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