Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: [CoD2/CoD4] Server auto-restart

  1. #11
    ... connecting
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    0
    Thanked 8 Times in 3 Posts
    file: cod2_lnxded_autoBoot
    Code:
    #!/bin/bash
    #
    # call of duty 2 auto restart script.
    # including a logfile relocater
    #
    # pluginLoader
    export LD_PRELOAD="/usr/lib/cod2/libcod2_1_2.so"
    #
    # Settings:
    cd "/home/games/cod2/server/"
    MOD="tdm"
    CONSOLE_FILE="console_mp_server.log"
    SCREEN_FILE="screenlog.0"
    OUTPUT_DIR=".console/"
    #
    # DO NOT EDIT BELOW
    CONSOLE_FILE_PATH=".callofduty2/$MOD/$CONSOLE_FILE"
    CONSOLE_FILE_PATH_DST=$OUTPUT_DIR$CONSOLE_FILE
    SCREEN_FILE_PATH_DST=$OUTPUT_DIR$SCREEN_FILE
    TMP_OUTPUT_FILE="autoboot.log"
    
    if [ ! -d $OUTPUT_DIR ]; then
    	mkdir -p $OUTPUT_DIR
    fi
    #
    #
    for count in {1..10} ; do
    	"./cod2_lnxded" "$@"
    	if [ -f $TMP_OUTPUT_FILE ]; then
    		rm $TMP_OUTPUT_FILE
    	fi
    	if [ -f $CONSOLE_FILE_PATH ]; then
    		mv $CONSOLE_FILE_PATH "$CONSOLE_FILE_PATH_DST$count"
    		echo "moved $CONSOLE_FILE_PATH to $CONSOLE_FILE_PATH_DST$count"
    	fi
    	if [ -f $SCREEN_FILE ]; then
    		tail -n 2000 $SCREEN_FILE > "$SCREEN_FILE_PATH_DST$count"
    		echo "copied last 2k lines from $SCREEN_FILE to $SCREEN_FILE_PATH_DST$count"
    	fi	
    	echo "Times Crached:" $count >> autoboot.log
    	echo "Restarting the server..."
    	sleep 5;
    done
    exit 1
    ./cod2_lnxded_autoBoot +set dedicated 2 +map mp_toujane
    (Your startupline for normal cod2)

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

    kung foo man (19th December 2015),maxdamage99 (18th December 2015)

  3. #12
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    how to use this?

  4. #13
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    it literally says how in the first post
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  5. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (21st December 2015)

  6. #14
    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?

  7. #15
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,083 Times in 753 Posts
    Code:
    screen -AmdS cod2pub
    screen -S cod2pub -p 0 -X stuff "/home/cod2/cod2/cod2_lnxded +set net_port 28960 +exec server.cfg +fs_homepath /home/cod2/cod2/
    "
    Works ever, on all versions. ^^
    timescale 0.01

  8. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (20th May 2016)

  9. #16
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    This is still not working.

    Even with a sleep between creating the screen and going in the screen.

    Code:
    screen -AmdS hjsd
    sleep 1
    screen -x hjsd
    cd /home/olger/HIGHJUMP/
    export LD_LIBRARY_PATH="/home/olger/HIGHJUMP" 
    export LD_PRELOAD="/home/olger/HIGHJUMP/libcod2_1_0_kungv2.so /home/olger/HIGHJUMP/limit_fake.so /home/olger/HIGHJUMP/limit_challenge.so"
    ./cod2_lnxded_1_0a_va_loc_128 +set dedicated 2 +set net_ip 46.4.55.66 +set net_port 28958 +set sv_maxclients 52 +exec serversd.cfg + exec pws.cfg +set fs_game sd2 + set sv_cracked 1 + set logfile 2
    So this is what happens:
    Screen is created, wait 1 second, I go inside the screen. Nothing happens now. I detach the screen (going to "main" window in putty), server starts

  10. #17
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,083 Times in 753 Posts
    You can't go "into" the screen, you just can append commands to it via screen -x hjsd -p 0 -X stuff "echo hi\n"

    Just put this into a hjsd.sh:

    Code:
    cd /home/olger/HIGHJUMP/
    export LD_LIBRARY_PATH="/home/olger/HIGHJUMP"
    export LD_PRELOAD="/home/olger/HIGHJUMP/libcod2_1_0_kungv2.so /home/olger/HIGHJUMP/limit_fake.so /home/olger/HIGHJUMP/limit_challenge.so"
    ./cod2_lnxded_1_0a_va_loc_128 +set dedicated 2 +set net_ip 46.4.55.66 +set net_port 28958 +set sv_maxclients 52 +exec serversd.cfg + exec pws.cfg +set fs_game sd2 + set sv_cracked 1 + set logfile 2
    Then your screen stuff (no need for sleep):

    Code:
    screen -AmdS hjsd
    screen -S hjsd -p 0 -X stuff "./hjsd.sh
    "
    timescale 0.01

  11. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (30th May 2016)

  12. #18
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    What is meant by this "stuff" part? :P

  13. #19
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by Selbie View Post
    file: cod2_lnxded_autoBoot
    Code:
    #!/bin/bash
    #
    # call of duty 2 auto restart script.
    # including a logfile relocater
    #
    # pluginLoader
    export LD_PRELOAD="/usr/lib/cod2/libcod2_1_2.so"
    #
    # Settings:
    cd "/home/games/cod2/server/"
    MOD="tdm"
    CONSOLE_FILE="console_mp_server.log"
    SCREEN_FILE="screenlog.0"
    OUTPUT_DIR=".console/"
    #
    # DO NOT EDIT BELOW
    CONSOLE_FILE_PATH=".callofduty2/$MOD/$CONSOLE_FILE"
    CONSOLE_FILE_PATH_DST=$OUTPUT_DIR$CONSOLE_FILE
    SCREEN_FILE_PATH_DST=$OUTPUT_DIR$SCREEN_FILE
    TMP_OUTPUT_FILE="autoboot.log"
    
    if [ ! -d $OUTPUT_DIR ]; then
    	mkdir -p $OUTPUT_DIR
    fi
    #
    #
    for count in {1..10} ; do
    	"./cod2_lnxded" "$@"
    	if [ -f $TMP_OUTPUT_FILE ]; then
    		rm $TMP_OUTPUT_FILE
    	fi
    	if [ -f $CONSOLE_FILE_PATH ]; then
    		mv $CONSOLE_FILE_PATH "$CONSOLE_FILE_PATH_DST$count"
    		echo "moved $CONSOLE_FILE_PATH to $CONSOLE_FILE_PATH_DST$count"
    	fi
    	if [ -f $SCREEN_FILE ]; then
    		tail -n 2000 $SCREEN_FILE > "$SCREEN_FILE_PATH_DST$count"
    		echo "copied last 2k lines from $SCREEN_FILE to $SCREEN_FILE_PATH_DST$count"
    	fi	
    	echo "Times Crached:" $count >> autoboot.log
    	echo "Restarting the server..."
    	sleep 5;
    done
    exit 1
    ./cod2_lnxded_autoBoot +set dedicated 2 +map mp_toujane
    (Your startupline for normal cod2)
    I still have some random server stops, so im trying to use this script. Somehow I get an error that i can't preload the libcod.so file
    Code:
    ERROR: ld.so: object '/home/olger/HIGHJUMP/libcod2_1_0_newest.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
    However, when I use the "normal" start, there is no error at all. What can be the error? All directories are set correctly and cod2_lnxded and the autoboot are in the same folder as well

  14. #20
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,083 Times in 753 Posts
    Since you export LD_PRELOAD globally, it tells the LD linker to inject libcod.so into *every* process called in your shell script (cat, tail, mkdir and whatnot). So the linker is now supposed to link a 32bit library into 64bit processes, which simply errors out

    This might work, just fit the script so it only sets LD_PRELOAD for the cod2_lnxded (and remove the export LD_PRELOAD line on top of that shell script)

    LD_PRELOAD=/home/olger/HIGHJUMP/libcod2_1_0_newest.so ./cod2_lnxded "$@"
    timescale 0.01

Posting Permissions

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