linux: improved script for headless servers; other scripts more friendly for mods

This commit is contained in:
filux 2015-11-14 00:11:48 +01:00
parent 492d821e0b
commit 2b06670b10
8 changed files with 348 additions and 91 deletions

@ -1 +1 @@
Subproject commit bf04854ade7cd0fc51483c857e590acfef4fbc26
Subproject commit 593b45885701827f068e567f8e926edeac5445c5

View File

@ -10,14 +10,19 @@ LANG=C
SCRIPTLOCATION="$(readlink -f "$0")"
GAMEDIR="$(dirname "$SCRIPTLOCATION")"
ARCHITECTURE="$(uname -m | tr '[A-Z]' '[a-z]')"
BugReport1="'https://github.com/MegaGlest/megaglest-source/issues'"
BugReport2="'https://forum.megaglest.org/index.php?board=23.0'"
BugReportEngine="https://github.com/MegaGlest/megaglest-source/issues"
BugReportBoth="https://forum.megaglest.org/index.php?board=23.0"
# -------
# useful for mods
BugReportBoth2="$BugReportBoth"
BugReportData="https://github.com/MegaGlest/megaglest-data/issues"
EXC_BINARY="megaglest"
SHORT_GAME_NAME="megaglest"
# -------
LIBDIR="lib"; ExitStatus=0; LibsWarnings=""; IgnoredLibs=""
if [ ! -d "$GAMEDIR/$LIBDIR" ]; then mkdir "$GAMEDIR/$LIBDIR"; fi
if [ "$1" = "--tool-editor" ]; then OperatingMode="--tool-editor"
elif [ "$1" = "--tool-g3dviewer" ]; then OperatingMode="--tool-g3dviewer"
elif [ "$1" = "--tool-buginfo" ]; then OperatingMode="--tool-buginfo"
else OperatingMode="--game"; fi
if [ "$1" = "--tool-editor" ] || [ "$1" = "--tool-g3dviewer" ] || [ "$1" = "--tool-buginfo" ];
then OperatingMode="$1"; else OperatingMode="--game"; fi
BeginTime="$(date +"%s")"
if [ "$(which lsb_release 2>/dev/null)" != "" ]; then
OS_INFO_P="$(which lsb_release) -d"
@ -42,10 +47,10 @@ if [ "$OperatingMode" != "--tool-buginfo" ]; then
|| If for some reason you see an error related with library, then you should try install this library
|| in your linux. Hints with full names and with default versions of just detected missing libraries you
|| see below.
|| You can also perform mini update by launch 'megaglest-mini-update.sh' script, which may solve tiny problems.
|| You can also perform mini update by launch '${SHORT_GAME_NAME}-mini-update.sh' script, which may solve tiny problems.
|| If it is other problem or after your tries it still doesn't work then please report a bug
|| here: $BugReport1
|| or here: $BugReport2."
|| here: '$BugReportEngine',
|| or here: '$BugReportBoth'."
LibsWarnings="$LibsWarnings
||
|| Found LDCONFIG variable [$LDconfigType][$LDCONFIG]...
@ -60,11 +65,9 @@ if [ "$OperatingMode" != "--tool-buginfo" ]; then
ArchSortLibs="yes"
fi
if [ "$OperatingMode" = "--game" ]; then
ldd_target="$GAMEDIR/megaglest"
elif [ "$OperatingMode" = "--tool-editor" ]; then
ldd_target="$GAMEDIR/megaglest_editor"
elif [ "$OperatingMode" = "--tool-g3dviewer" ]; then
ldd_target="$GAMEDIR/megaglest_g3dviewer"
ldd_target="$GAMEDIR/$EXC_BINARY"
else
ldd_target="$GAMEDIR/$2"
fi
c_required_libs="$(ldd "$ldd_target")"
@ -108,9 +111,9 @@ if [ "$OperatingMode" != "--tool-buginfo" ]; then
if [ "$SO_WANTED_LIB" != "$SO_LIB_PATTERN" ]; then
LibsWarnings="$LibsWarnings
|| new library link [.../$LIBDIR/$SO_WANTED_LIB2] pointed to [$hasSO]."
ln -f -s $hasSO $SO_LINKED_LIB
ln -f -s "$hasSO" "$SO_LINKED_LIB"
else
if [ -e "$SO_LINKED_LIB" ]; then rm -f $SO_LINKED_LIB; fi
if [ -e "$SO_LINKED_LIB" ]; then rm -f "$SO_LINKED_LIB"; fi
if [ "$(echo "$c_required_libs" | grep "$SO_LIB_PATTERN[ \t]*=>[ \t]*not found")" != "" ]; then
#rare exception
LibsWarnings="$LibsWarnings
@ -257,15 +260,16 @@ if [ "$OperatingMode" != "--tool-buginfo" ]; then
#fi
checkLibsStatus "$libs_list"
if [ -f "$GAMEDIR/megaglest-configure-desktop.sh" ]; then
$GAMEDIR/megaglest-configure-desktop.sh
rm -f $GAMEDIR/megaglest-configure-desktop.sh
if [ -f "$GAMEDIR/${SHORT_GAME_NAME}-configure-desktop.sh" ]; then
"$GAMEDIR/${SHORT_GAME_NAME}-configure-desktop.sh"
rm -f "$GAMEDIR/${SHORT_GAME_NAME}-configure-desktop.sh"
fi
else
ExitStatus="$2"
LibsWarnings="$3"
BeginTime="$4"
ErrorTime="$5"
BinaryToCheck="$6"
fi
if [ "$OperatingMode" = "--game" ]; then
if [ -d "$GAMEDIR/$LIBDIR" ]; then
@ -274,30 +278,42 @@ if [ "$OperatingMode" = "--game" ]; then
export VLC_PLUGIN_PATH="${GAMEDIR}/${LIBDIR}/vlc"
fi
fi
$GAMEDIR/megaglest $@
"$GAMEDIR/$EXC_BINARY" $@
ExitStatus="$?"
BinaryToCheck="$EXC_BINARY"
ErrorTime="$(date +"%s")"
fi
if [ "$ExitStatus" -ne "0" ] || [ "$OperatingMode" = "--tool-editor" ] || [ "$OperatingMode" = "--tool-g3dviewer" ]; then
if [ "$OperatingMode" = "--game" ]; then ErrorTime="$(date +"%s")"; fi
DiffTime="$(($ErrorTime-$BeginTime))"
if [ "$DiffTime" -le "15" ]; then
echo "$LibsWarnings" | sed 's/^[\t ]*||//g' >&2; echo
if [ "$IgnoredLibs" != "" ]; then
echo "... and as information useful only for game developers, List of ignored libs:" >&2
echo "$IgnoredLibs" >&2; echo
if [ "$(echo "$@" | grep "^[ \t]*--help[ \t]*$")" = "" ] && [ "$(echo "$@" | grep "^[ \t]*-h[ \t]*$")" = "" ]; then
DiffTime="$(($ErrorTime-$BeginTime))"
if [ "$DiffTime" -le "15" ] && [ -e "$GAMEDIR/$BinaryToCheck" ] && [ -x "$GAMEDIR/$BinaryToCheck" ]; then
echo "$LibsWarnings" | sed 's/^[\t ]*||//g' >&2; echo
if [ "$IgnoredLibs" != "" ]; then
echo "... and as information useful only for game developers, List of ignored libs:" >&2
echo "$IgnoredLibs" >&2; echo
fi
else
BugReportInfo="$BugReportInfo
|| OS info. [$OS_INFO], Arch.[$ARCHITECTURE], Dir.[$GAMEDIR]
||
|| If you see an unknown error then please report a bug
|| here: '$BugReportBoth2',
|| or if you think that bug is related with game engine here:
|| '$BugReportEngine'"
if [ "$BugReportData" != "" ] && [ "$BugReportData" != "$BugReportBoth2" ] && [ "$BugReportData" != "$BugReportEngine" ] ; then
BugReportInfo="$BugReportInfo,
|| or if you think that bug is related with game data here:
|| '$BugReportData'."
else
BugReportInfo="$BugReportInfo."
fi
echo "$BugReportInfo" | sed 's/^[\t ]*||//g' >&2; echo
fi
else
BugReportInfo="$BugReportInfo
|| OS info. [$OS_INFO], Arch.[$ARCHITECTURE], Dir.[$GAMEDIR]
||
|| If you see an unknown error then please report a bug
|| here: $BugReport1
|| or here: $BugReport2."
echo "$BugReportInfo" | sed 's/^[\t ]*||//g' >&2; echo
#if [ "$OperatingMode" = "--game" ] && [ -f "$GAMEDIR/${SHORT_GAME_NAME}-mini-update.sh" ]; then
#echo "... attempt to perform mini update, which may solve tiny problems:" >&2
#"$GAMEDIR/${SHORT_GAME_NAME}-mini-update.sh"
#fi
fi
#if [ "$OperatingMode" = "--game" ] && [ -f "$GAMEDIR/megaglest-mini-update.sh" ]; then
#echo "... attempt to perform mini update, which may solve tiny problems:" >&2
#$GAMEDIR/megaglest-mini-update.sh
#fi
fi
exit $ExitStatus
exit "$ExitStatus"

View File

@ -6,11 +6,16 @@ LANG=C
SCRIPTLOCATION="$(readlink -f "$0")"
GAMEDIR="$(dirname "$SCRIPTLOCATION")"
# -------
# useful for mods
EXC_BINARY="megaglest_g3dviewer"
BASIC_SCRIPT="start_megaglest"
# -------
LIBDIR="lib"
WARNINGS="$($GAMEDIR/start_megaglest --tool-g3dviewer 2>&1)"
WARNINGS="$("$GAMEDIR/$BASIC_SCRIPT" --tool-g3dviewer "$EXC_BINARY" 2>&1)"
if [ -d "$GAMEDIR/$LIBDIR" ]; then
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${GAMEDIR}/${LIBDIR}"
fi
BeginTime="$(date +"%s")"
$GAMEDIR/megaglest_g3dviewer $@
$GAMEDIR/start_megaglest --tool-buginfo "$?" "$WARNINGS" "$BeginTime" "$(date +"%s")"
"$GAMEDIR/$EXC_BINARY" $@
"$GAMEDIR/$BASIC_SCRIPT" --tool-buginfo "$?" "$WARNINGS" "$BeginTime" "$(date +"%s")" "$EXC_BINARY"

View File

@ -1,60 +1,266 @@
#!/bin/bash
#!/bin/sh
#
# Start a headless MegaGlest game server (and keep it running)
# Start a headless game server (and keep it running)
#
# Using this script, a headless game server is started, waiting for players to
# Using this script, a headless game server is started, waiting for players to
# connect (if your firewall configuration permits). Players connect and start a
# game. As soon as the game ends, the server will quit, and this script will
# start up a new server immidiately. This is a stability measure to rule out
# the unlikely case where side effects (such as memory leaks or corruption)
# game. As soon as the game ends, the server will quit, and this script will
# start up a new server immidiately. This is a stability measure to rule out
# the unlikely case where side effects (such as memory leaks or corruption)
# could drain on system resources.
#
# For this to work, Internet originated traffic must be able to reach the
# For this to work, Internet originated traffic must be able to reach the
# server on the following ports:
# TCP port 61357: game protocol port
# TCP port 61358: FTP control port
# TCP ports 61359 to 61366: FTP data ports
#
# Once publishing to the master server succeeded (this can be verified at
# <http://master.megaglest.org>) you may connect to your headless game server
# using a copy of MegaGlest you have installed on a Desktop computer. The first
# user connecting to a headless server controls it. If this user disconnects,
# master server's site) you may connect to your headless game server
# using a copy of game you have installed on a Desktop computer. The first
# user connecting to a headless server controls it. If this user disconnects,
# the next user who connects (or had already connected) takes control.
#
# Please read http://wiki.megaglest.org/Dedicated_Server for more information
#
# ----------------------------------------------------------------------------
# Written by Tom Reynolds <tomreyn[at]megaglest.org>
# Copyright (c) 2013 Tom Reynolds, The MegaGlest Team, under GNU GPL v3.0+
# 2013 Written by Tom Reynolds <tomreyn[at]megaglest.org>
# 2015 Rewritten by filux <heross(@@)o2.pl>
# Copyright (c) 2013-2015 under GNU GPL v3.0+
# ----------------------------------------------------------------------------
LANG=C
trap "kill -- -$$" HUP INT QUIT TERM EXIT
# Install location
DIR_GAME="$(dirname "$(readlink -f "$0")")"
KERNEL="$(uname -s | tr '[A-Z]' '[a-z]')"
if [ "$(echo "$(readlink -f "$0" >/dev/null 2>&1; echo $?)" | grep '^[0-9]$')" -eq "0" ]; then
GAMEDIR="$(dirname "$(readlink -f "$0")")"
else
GAMEDIR="$(cd "$(dirname "$0")"; pwd)"
fi
HOME_DIR="$HOME"
B_SCRIPT_DIR="$GAME_DIR"
# -------
# useful for mods
BASIC_SCRIPT="start_megaglest"
FAKE_EXC_BINARY_MAC="MegaGlest"
EXC_BINARY="megaglest"
SHORT_GAME_NAME="megaglest"
# -------
PORTSTART=62001
NUM_OA_SERVERS=2
# Log file location (beware, this can grow large)
#LOG_SERVER=/dev/null
LOG_SERVER=~/.megaglest/server.log
# LOG_SERVER=/dev/null
if [ "$(which curl 2>/dev/null)" = "" ]; then
echo "WARNING: Downloading tool 'curl' DOES NOT EXIST on this system, please install it." >&2
fi
if [ "$KERNEL" = "darwin" ]; then
if [ -e "$GAMEDIR/../../MacOS/$FAKE_EXC_BINARY_MAC" ]; then
BASIC_SCRIPT="$FAKE_EXC_BINARY_MAC"; B_SCRIPT_DIR="$(cd "${GAMEDIR}/../../MacOS/"; pwd)"
elif [ -e "$GAMEDIR/$FAKE_EXC_BINARY_MAC.sh" ]; then
BASIC_SCRIPT="$FAKE_EXC_BINARY_MAC.sh"
fi
fi
if [ "$(which lscpu 2>/dev/null)" != "" ]; then NUMCORES="$(lscpu -p | grep -cv '^#')"
elif [ "$(which sysctl 2>/dev/null)" != "" ]; then NUMCORES="$(sysctl -n hw.ncpu)"; fi
if [ "$NUMCORES" = "" ]; then NUMCORES=1; fi
echo "Notice: Detected processor with $NUMCORES cores." >&2
case $NUMCORES in
1) MAX_LOAD_MULT="0.65";; 2) MAX_LOAD_MULT="0.80";; 3) MAX_LOAD_MULT="0.90";; *) MAX_LOAD_MULT="0.95";;
esac
MAX_LOAD="$(echo "$NUMCORES $MAX_LOAD_MULT" | awk '{print $1*$2}')"
# ---
if [ "$1" != "" ] && [ "$(echo "$1" | grep '^[0-9]\+$')" != "" ]; then SERVERCOUNT="$1"
else SERVERCOUNT=0; fi
if [ "$2" != "" ] && [ "$(echo "$2" | grep '[0-9.:]\+' | grep -v '[A-Za-z]')" != "" ]; then
SERVER_GREP_IP="$(echo "$2" | sed 's/\./\\./g')"; else SERVER_GREP_IP=""; fi
if [ "$3" != "" ] && [ "$(echo "$3" | grep '^[0-9]\+$')" != "" ]; then PORTSTART="$3"; fi
PORT="$(($PORTSTART + $(($(($SERVERCOUNT - 1)) * 11))))"
STATUSPORT="$(($PORT - 1))"
PORT_FD="$(echo "$PORT" | cut -c1-3)"
cd $DIR_GAME
ulimit -c unlimited
SERVER_SCRIPT="$(basename "$0")"
if [ -f "$GAMEDIR/glest.ini" ]; then
GLEST_INI="$(cat "$GAMEDIR/glest.ini")"
LOG_DIR="$(echo "$GLEST_INI" | awk -F '=' '/^LogPath=/ {print $2}' | sed -e 's:\$HOME:'"$HOME_DIR"':g')"
MASTER_SERVER="$(echo "$GLEST_INI" | awk -F '=' '/^Masterserver=/ {print $2}')"
if [ "$(echo "$MASTER_SERVER" | grep '/$')" ]; then CLEAR_M_SERVER="${MASTER_SERVER}showServersForGlest.php"
else CLEAR_M_SERVER="$MASTER_SERVER/showServersForGlest.php"; fi
elif [ "$SERVER_GREP_IP" != "" ]; then
echo "WARNING: file 'glest.ini' not found, maybe '$SERVER_SCRIPT' script is placed in the wrong location." >&2
fi
if [ -e "$B_SCRIPT_DIR/$BASIC_SCRIPT" ]; then SERVER_EXEC="$B_SCRIPT_DIR/$BASIC_SCRIPT"
elif [ -e "$GAMEDIR/$EXC_BINARY" ]; then SERVER_EXEC="$GAMEDIR/$EXC_BINARY"
else SERVER_EXEC="$EXC_BINARY"; fi
if [ "$SERVERCOUNT" -eq "0" ]; then
if [ "$SERVER_EXEC" != "$EXC_BINARY" ]; then ulimit -c unlimited; fi
USED_PORTS=""; LOG_FILE="server.log"
else
USED_PORTS=" --use-ports=$PORT,$PORT,$STATUSPORT"
LOG_FILE="server_${SERVERCOUNT}.log"
echo "Info: Server nr. $SERVERCOUNT ($2 ; $PORT)." >&2
fi
SER_PARAMETERS="--headless-server-mode=vps,exit$USED_PORTS"
SER_GREP_PARAMETERS="$(echo "$SER_PARAMETERS" | sed 's/--/\\--/g')"
if [ "$SERVERCOUNT" -gt "0" ]; then
sleep "$(($SERVERCOUNT * 30))"s
fi
if [ "$LOG_SERVER" != "" ]; then :
elif [ "$LOG_DIR" != "" ]; then
mkdir -p "$LOG_DIR"
if [ "$(echo "$LOG_DIR" | grep '/$')" ]; then LOG_SERVER="${LOG_DIR}${LOG_FILE}"
else LOG_SERVER="$LOG_DIR/$LOG_FILE"; fi
else
LOG_SERVER=/dev/null
fi
cd "$GAMEDIR"
AVG_LOAD="unknown"; SER_SITUATION="unknown"; CHECK_AVG_LOAD_M=0
if [ -e "/proc/loadavg" ]; then CHECK_AVG_LOAD_M=1
elif [ "$(which sysctl 2>/dev/null)" != "" ]; then CHECK_AVG_LOAD_M=2; fi
while true; do
if [ -f "$LOG_SERVER" ]; then mv -f "$LOG_SERVER" "$LOG_SERVER.1"; fi
if [ -f "core" ]; then mv -f "core" "core.1"; fi
date > "$LOG_SERVER"
echo 'Starting server...' | tee -a "$LOG_SERVER"
./start_megaglest --headless-server-mode=vps,exit >> "$LOG_SERVER" 2>&1
if [ $? -ne 0 ];
then
echo 'ERROR: Server has quit unexpectedly.' >> "$LOG_SERVER"
echo 'ERROR: Server has quit unexpectedly.' >&2
echo ' Please inspect '"$LOG_SERVER"'.' >&2
exit 1
else
echo 'Server has quit.' | tee -a "$LOG_SERVER"
fi
if [ -f "$LOG_SERVER" ]; then mv -f "$LOG_SERVER" "$LOG_SERVER.1"; fi
if [ -e "core" ]; then mv -f "core" "core.1"; fi
date > "$LOG_SERVER"
while true; do
if [ "$CHECK_AVG_LOAD_M" -eq "1" ]; then
AVG_LOAD="$(awk '{print $2}' /proc/loadavg)"
elif [ "$CHECK_AVG_LOAD_M" -eq "2" ]; then
AVG_LOAD="$(sysctl -n vm.loadavg | awk -F '{' '{print $2}' | awk '{print $2}')"
fi
if [ "$AVG_LOAD" != "unknown" ]; then
SER_SITUATION="$(echo "$AVG_LOAD $MAX_LOAD" | awk '{if ($1 > $2) print "highload"}')"
fi
if [ "$SER_SITUATION" = "highload" ]; then
if [ "$OLD_SER_SITUATION_STATUS" = "" ]; then
echo "WARNING: Detected high load on the server." >&2
OLD_SER_SITUATION_STATUS="yes"
fi
sleep 5m; sleep "$((RANDOM % 180))"s
else
OLD_SER_SITUATION_STATUS=""
if [ "$SERVERCOUNT" -ne "0" ] && [ "$SERVERCOUNT" -ne "1" ] && [ "$MASTER_SERVER" != "" ] && [ "$SERVER_GREP_IP" != "" ]; then
NUM_O_FREE_SER="$(curl -s -L "$CLEAR_M_SERVER" | grep '^\([^|]*|\)\{4\}'"$SERVER_GREP_IP"'|.*$' \
| grep '^\([^|]*|\)\{11\}'"$PORT_FD"'' | grep '^\([^|]*|\)\{13\}0|.*$' | wc -l)"
else
NUM_O_FREE_SER=""
fi
if [ "$NUM_O_FREE_SER" != "" ] && [ "$NUM_O_FREE_SER" -ge "$NUM_OA_SERVERS" ]; then
if [ "$OLD_NUM_OFS_STATUS" = "" ]; then
echo "Notice: Waiting for situation when server may be really needed." >&2
OLD_NUM_OFS_STATUS="yes"
fi
sleep 2m; sleep "$((RANDOM % 60))"s
else
OLD_NUM_OFS_STATUS=""
break
fi
fi
done
if [ "$SERVERCOUNT" -eq "1" ] && [ ! -e "$GAMEDIR/${SHORT_GAME_NAME}-mini-update.sh" ] && \
[ -e "$GAMEDIR/../${SHORT_GAME_NAME}-dev_version-update.sh" ]; then
if [ ! -f "$GAMEDIR/${SHORT_GAME_NAME}-dev_version-update-done.log" ]; then
echo "... dev_version update:" >&2
"$GAMEDIR/../${SHORT_GAME_NAME}-dev_version-update.sh" "$GAMEDIR"; sleep 1s
echo "#" > "$GAMEDIR/${SHORT_GAME_NAME}-dev_version-update-done.log"; sleep 1s
"$GAMEDIR/$SERVER_SCRIPT" $@ &
break
else
rm -f "$GAMEDIR/${SHORT_GAME_NAME}-dev_version-update-done.log"
fi
fi
echo 'Starting server...' | tee -a "$LOG_SERVER"
if [ "$MASTER_SERVER" != "" ] && [ "$SERVER_GREP_IP" != "" ]; then
( check_nr=0; force_restart=0; loop_start="yes"; BeginTime="$(date +"%s")"; sleep 4m
while true; do
SER_PID="$(ps -ef | grep "$SER_GREP_PARAMETERS" | awk '/\/'"$EXC_BINARY"' / {print $2}')"
if [ "$loop_start" = "yes" ]; then SER_PID_S="$SER_PID"; loop_start="no"; fi
CheckTime="$(date +"%s")"; DiffTime="$(($CheckTime-$BeginTime))"
if [ "$SER_PID" != "" ] && [ "$SER_PID" = "$SER_PID_S" ]; then
FIND_SER="$(curl -s -L "$CLEAR_M_SERVER" | grep '^\([^|]*|\)\{4\}'"$SERVER_GREP_IP"'|.*$' \
| grep '^\([^|]*|\)\{11\}'"$PORT"'|.*$')"
if [ "$FIND_SER" = "" ]; then
if [ "$OLD_FIND_SER_STATUS" = "" ]; then
echo "WARNING: The master server doesn't see this server." >&2
OLD_FIND_SER_STATUS="yes"
fi
else
OLD_FIND_SER_STATUS=""
SER_STATUS="$(echo "$FIND_SER" | awk -F '|' '{print $14}')"
if [ "$SER_STATUS" = "" ] || [ "$(echo "$SER_STATUS" | grep '^[0-9]\+$')" = "" ]; then
echo "ERROR: Server status cannot be determined." >&2
fi
fi
if [ "$SER_STATUS" != "2" ] && [ "$DiffTime" -gt "43200" ]; then
echo "Notice: The server is working continuously for over 12 hours." >&2; force_restart=1
elif [ "$SER_STATUS" = "2" ]; then
if [ "$OLD_PROG_STATUS" = "" ]; then
echo "Status: Game in progress..." >&2
OLD_PROG_STATUS="yes"; BeginTime2="$(date +"%s")"
fi
DiffTime2="$(($CheckTime-$BeginTime2))"
if [ "$DiffTime2" -gt "14400" ]; then
echo "WARNING: The game is in progress for over 4 hours." >&2; force_restart=1
else
sleep 8m
fi
elif [ "$SER_STATUS" = "1" ]; then
if [ "$OLD_READY_STATUS" = "" ]; then
OLD_READY_STATUS="yes"; BeginTime3="$(date +"%s")"
fi
DiffTime3="$(($CheckTime-$BeginTime3))"
if [ "$DiffTime3" -gt "3600" ]; then
echo "WARNING: The game seems to waiting for start for over an hour." >&2; force_restart=1
fi
else
OLD_READY_STATUS=""
fi
if [ "$force_restart" -eq "1" ]; then
FIND_SER=""; if [ "$check_nr" -lt "120" ]; then check_nr=120; fi
if [ "$LOG_DIR" != "" ]; then echo "#" > "$LOG_DIR/${SHORT_GAME_NAME}-server-forced-restart.log"; sleep 2s; fi
fi
if [ "$FIND_SER" = "" ]; then
check_nr="$(($check_nr + 1))"
if [ "$check_nr" -lt "119" ]; then :
elif [ "$check_nr" -eq "119" ] && [ "$force_restart" -ne "1" ]; then
echo "ERROR: The master server doesn't see this server for over 4 hours." >&2
elif [ "$check_nr" -ge "123" ]; then kill -9 "$SER_PID"
else kill "$SER_PID"; fi
else
check_nr=0
fi
sleep 2m
else
break
fi
done
) &
fi
"$SERVER_EXEC" $SER_PARAMETERS >> "$LOG_SERVER" 2>&1
if [ "$?" -ne "0" ]; then
if [ ! -f "$LOG_DIR/${SHORT_GAME_NAME}-server-forced-restart.log" ]; then
echo 'ERROR: Server has quit unexpectedly.' >> "$LOG_SERVER"
echo 'ERROR: Server has quit unexpectedly.' >&2
if [ "$SERVERCOUNT" -eq "0" ]; then
echo ' Please inspect '"$LOG_SERVER"'.' >&2
exit 1
fi
sleep 5s
if [ "$SERVERCOUNT" -eq "1" ] && [ "$SERVER_GREP_IP" != "" ] && [ -e "$GAMEDIR/${SHORT_GAME_NAME}-mini-update.sh" ]; then
echo "... attempt to perform mini update, which may solve tiny problems:" >&2
"$GAMEDIR/${SHORT_GAME_NAME}-mini-update.sh"; sleep 1s
fi
else
echo 'Notice: Server was restarted by script.' >> "$LOG_SERVER"
rm -f "$LOG_DIR/${SHORT_GAME_NAME}-server-forced-restart.log"
fi
sleep "$((RANDOM % 30))"s
else
echo 'Server has quit.' | tee -a "$LOG_SERVER"
fi
done

View File

@ -6,11 +6,16 @@ LANG=C
SCRIPTLOCATION="$(readlink -f "$0")"
GAMEDIR="$(dirname "$SCRIPTLOCATION")"
# -------
# useful for mods
EXC_BINARY="megaglest_editor"
BASIC_SCRIPT="start_megaglest"
# -------
LIBDIR="lib"
WARNINGS="$($GAMEDIR/start_megaglest --tool-editor 2>&1)"
WARNINGS="$("$GAMEDIR/$BASIC_SCRIPT" --tool-editor "$EXC_BINARY" 2>&1)"
if [ -d "$GAMEDIR/$LIBDIR" ]; then
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}${GAMEDIR}/${LIBDIR}"
fi
BeginTime="$(date +"%s")"
$GAMEDIR/megaglest_editor $@
$GAMEDIR/start_megaglest --tool-buginfo "$?" "$WARNINGS" "$BeginTime" "$(date +"%s")"
"$GAMEDIR/$EXC_BINARY" $@
"$GAMEDIR/$BASIC_SCRIPT" --tool-buginfo "$?" "$WARNINGS" "$BeginTime" "$(date +"%s")" "$EXC_BINARY"

View File

@ -8,7 +8,7 @@ CURRENTDIR="$(dirname "$(readlink -f "$0")")"
cd "$CURRENTDIR"
ENGINE_VERSION="$(../mg-version.sh --version)"
MU_PACKAGE_NAME="megaglest-mu-$ENGINE_VERSION-linux.tar.gz"
MU_PACKAGE_NAME='megaglest-mu-$ENGINE_VERSION-linux.tar.gz'
mkdir -p lib-x86; mkdir -p lib-x86_64
if [ "$?" -eq "0" ]; then
echo '#!/bin/sh
@ -21,23 +21,43 @@ CURRENTDIR="$(dirname "$(readlink -f "$0")")"
cd "$CURRENTDIR"
ENGINE_VERSION="'"$ENGINE_VERSION"'"
MU_PACKAGE_NAME="megaglest-mu-$ENGINE_VERSION-linux.tar.gz"
MU_PACKAGE_NAME="'"$MU_PACKAGE_NAME"'"
MU_ADDRESS="https://github.com/MegaGlest/megaglest-source/releases/download/$ENGINE_VERSION/$MU_PACKAGE_NAME"
if [ "$(which curl 2>/dev/null)" = "" ]; then
echo "Downloading tool '"'curl'"' DOES NOT EXIST on this system, please install it."
exit 1
fi
ARCHITECTURE="$(uname -m | tr '"'[A-Z]'"' '"'[a-z]'"')"
if [ "$ARCHITECTURE" = "x86_64" ]; then LibDir="lib-x86_64"; else LibDir="lib-x86"; fi
wget -c --progress=bar $MU_ADDRESS 2>&1; sleep 0.5s
if [ -e "$MU_PACKAGE_NAME" ]; then tar xzf "$MU_PACKAGE_NAME" -C "./"; rm -f "$MU_PACKAGE_NAME"; fi
if [ -d "megaglest-mini_update" ]; then
if [ -d "megaglest-mini_update/$LibDir" ]; then
mv "megaglest-mini_update/$LibDir" "megaglest-mini_update/lib"
rm -rf "lib" "lib-x86_64" "lib-x86" "megaglest-mini_update/lib-x86_64" "megaglest-mini_update/lib-x86"
if [ ! -e "$MU_PACKAGE_NAME" ]; then
echo "Downloading $MU_PACKAGE_NAME ..."
curl -L -# "$MU_ADDRESS" -o "$MU_PACKAGE_NAME"; sleep 2s
if [ -e "$MU_PACKAGE_NAME" ] && [ "$(tar -tf "$MU_PACKAGE_NAME" 2>/dev/null)" != "" ]; then
echo "Extracting $MU_PACKAGE_NAME ..."; sleep 2s
tar xzf "$MU_PACKAGE_NAME" -C "./"; sleep 1s
fi
mv "megaglest-mini_update/"* "./"; rm -rf "megaglest-mini_update"
if [ -e "megaglest-mini_update/megaglest-mini-update.sh" ]; then
cp -f --no-dereference --preserve=all "megaglest-mini_update/megaglest-mini-update.sh" ./; sleep 0.5s
./megaglest-mini-update.sh; sleep 0.5s
else
rm -f "$MU_PACKAGE_NAME"
fi
else
if [ -d "megaglest-mini_update" ]; then
if [ -d "megaglest-mini_update/$LibDir" ]; then
mv "megaglest-mini_update/$LibDir" "megaglest-mini_update/lib"; sleep 0.25s
rm -rf "lib" "lib-x86_64" "lib-x86" "megaglest-mini_update/lib-x86_64" "megaglest-mini_update/lib-x86"; sleep 0.25s
fi
mv -f "megaglest-mini_update/"* "./"; sleep 0.5s; rm -rf "megaglest-mini_update"
echo "Mini update finished."
fi
rm -f "$MU_PACKAGE_NAME"
fi
exit 0' > "megaglest-mini-update.sh"
chmod +x "megaglest-mini-update.sh"
if [ "$1" != "--only_script" ]; then
rm -f "megaglest-mu-"*"-linux.tar.gz"
if [ -d "megaglest-mini_update" ]; then rm -rf "megaglest-mini_update"; fi
mkdir -p "megaglest-mini_update"
@ -46,7 +66,7 @@ exit 0' > "megaglest-mini-update.sh"
megaglest-mini-update.sh megaglest-configure-desktop.sh "megaglest-mini_update"
cp -R -f --no-dereference --preserve=all lib-x86 lib-x86_64 "megaglest-mini_update"
sleep 0.5s
GZIP=-9 tar czf "$MU_PACKAGE_NAME" "megaglest-mini_update"
GZIP=-9 tar czf "megaglest-mu-$ENGINE_VERSION-linux.tar.gz" "megaglest-mini_update"
rm -rf "megaglest-mini_update"
rm -f "megaglest-mini-update.sh"
fi

View File

@ -65,7 +65,7 @@ if [ -e "$RELEASEDIR/glest.ico" ]; then rm "$RELEASEDIR/glest.ico"; fi
#cp bundle_resources/*.icns "$RELEASEDIR"
cp {../shared/,}*.ini "$RELEASEDIR"
if [ -e "$RELEASEDIR/glest-dev.ini" ]; then rm "$RELEASEDIR/glest-dev.ini"; fi
cp megaglest bundle_resources/MegaGlest.sh "$RELEASEDIR"
cp megaglest ../linux/start_megaglest_gameserver bundle_resources/MegaGlest.sh "$RELEASEDIR"
if [ -e "megaglest_editor" ]; then
cp megaglest_editor "$RELEASEDIR"

View File

@ -308,6 +308,11 @@ IF(BUILD_MEGAGLEST)
DESTINATION ${MEGAGLEST_MANPAGE_INSTALL_PATH})
ENDIF()
IF(NOT WIN32)
INSTALL(FILES
"${PROJECT_SOURCE_DIR}/mk/linux/start_megaglest_gameserver"
DESTINATION ${MEGAGLEST_DATA_INSTALL_PATH})
ENDIF()
INSTALL(FILES
"${PROJECT_SOURCE_DIR}/mk/shared/glestkeys.ini"
"${PROJECT_SOURCE_DIR}/mk/shared/servers.ini"