PDA

View Full Version : [CoD2/CoD4] Server auto-restart



filthy_freak_
24th August 2015, 13:06
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



#!/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



#!/bin/bash

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

save as serv1.sh

Ni3ls
24th August 2015, 14:22
Thanks man!

Ni3ls
2nd September 2015, 15:19
I get the error No such file or directory, while the files are there.

#!/bin/bash

screen -S test /exectest.sh
startexectest.sh


#!/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

bash startexectest.sh

Mitch
2nd September 2015, 16:32
I get the error No such file or directory, while the files are there.

#!/bin/bash

screen -S test /exectest.sh

Both placed in same folder as from where I run the command

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.

IzNoGoD
2nd September 2015, 19:56
I get the error No such file or directory, while the files are there.

#!/bin/bash

screen -S test /exectest.sh
startexectest.sh

try screen -S test ./exectest.sh

filthy_freak_
3rd September 2015, 00:32
Nah, put in the full path.



#!/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.

Ni3ls
3rd September 2015, 08:24
Works! But when will the server start again? When there is a script error? Or when somebody did /killserver?

fabio
3rd September 2015, 10:39
You will need to query the server for 100% working autorestart :O

CaptainSlow
8th September 2015, 11:52
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



#!/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).


#!/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/

CaptainSlow
14th September 2015, 17:50
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/

Selbie
18th December 2015, 15:31
file: cod2_lnxded_autoBoot


#!/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)

Ni3ls
19th December 2015, 16:40
how to use this?

IzNoGoD
19th December 2015, 17:48
it literally says how in the first post

Ni3ls
19th May 2016, 10:39
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



#!/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).


#!/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

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?

kung foo man
20th May 2016, 00:15
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. ^^

Ni3ls
27th May 2016, 14:35
This is still not working.

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


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

kung foo man
28th May 2016, 02:37
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:




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):




screen -AmdS hjsd
screen -S hjsd -p 0 -X stuff "./hjsd.sh
"

Ni3ls
28th May 2016, 15:20
What is meant by this "stuff" part? :P

Ni3ls
2nd June 2018, 17:03
file: cod2_lnxded_autoBoot


#!/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

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

kung foo man
4th June 2018, 18:49
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 "$@"

Ni3ls
8th June 2018, 17:02
cod2 autoboot file

#!/bin/bash
#
# call of duty 2 auto restart script.
# including a logfile relocater
#
# pluginLoader
#cd /home/olger/HIGHJUMP/
#export LD_LIBRARY_PATH="/home/olger/HIGHJUMP"

#
# Settings:
cd "/home/olger/HIGHJUMP/"
MOD="tdm2"
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

"LD_PRELOAD=/home/olger/HIGHJUMP/libcod2_1_0_newest.so ./cod2_lnxded_1_0a_va_loc_128" "$@"
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

to start the server in the screen

./cod2_lnxded_autoBoot +set dedicated 2 +set net_ip 46.4.55.66 +set net_port 28963 +set sv_maxclients 52 +exec servercar.cfg + exec pws.cfg +set fs_game tdm2 + set sv_cracked 1

error

ERROR: ld.so: object '/home/olger/HIGHJUMP/libcod2_1_0_newest.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
./cod2_lnxded_autoBoot: line 28: ./cod2_lnxded: No such file or directory
ERROR: ld.so: object '/home/olger/HIGHJUMP/libcod2_1_0_newest.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
Restarting the server...
ERROR: ld.so: object '/home/olger/HIGHJUMP/libcod2_1_0_newest.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.


What am i doing wrong?

kung foo man
8th June 2018, 17:43
Looks like your LD_PRELOAD is still global from a previous test, restart putty (and/or restart screen session) and try this:




#!/bin/bash
#
# call of duty 2 auto restart script.
# including a logfile relocater
#
# pluginLoader
#cd /home/olger/HIGHJUMP/

# exporting library path should never hurt
export LD_LIBRARY_PATH="/home/olger/HIGHJUMP"

#
# Settings:
cd "/home/olger/HIGHJUMP/"
MOD="tdm2"
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

LD_PRELOAD=/home/olger/HIGHJUMP/libcod2_1_0_newest.so ./cod2_lnxded_1_0a_va_loc_128 "$@"
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

Ni3ls
10th June 2018, 12:24
Okay server is running.
What kind of crashed will activate the script?
"killserver" doesnt do anything

kung foo man
10th June 2018, 17:29
just type quit?