-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker-runner.sh
executable file
·169 lines (131 loc) · 4.79 KB
/
docker-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
set -e
cleanup() {
echo "Exit received"
echo "Stopping server"
./lgsm-gameserver stop
echo "Server Stopped"
echo "Shutting down"
exit 0
}
trap 'cleanup' SIGINT SIGTERM
for f in startup-scripts/*.sh; do
bash "$f" -H || break
done
#Set ENV defaults
if [ -n "$LGSM_PORT" ]; then
if [ -z "$LGSM_CLIENTPORT" ]; then
clientport=$(($LGSM_PORT-10))
echo "clientPort $clientport"
export LGSM_CLIENTPORT=$clientport
fi
if [ -z "$LGSM_SOURCETVPORT" ]; then
sourcetvport=$(($LGSM_PORT+5))
echo "sourcetvport $sourcetvport"
export LGSM_SOURCETVPORT=$sourcetvport
fi
fi
./monitor &
parse-env --env "LGSM_" > env.json
rm -f INSTALLING.LOCK
if [ -z "$LGSM_GAMESERVERNAME" ]; then echo "Need to set LGSM_GAMESERVERNAME environment"
exit 1
fi
echo "IP is set to "${LGSM_IP}
echo "Gomplating main config"
mkdir -p ~/linuxgsm/lgsm/config-lgsm/$LGSM_GAMESERVERNAME
gomplate -d env=~/linuxgsm/env.json -f ~/linuxgsm/lgsm/config-default/config-lgsm/common.cfg.tmpl -o ~/linuxgsm/lgsm/config-lgsm/$LGSM_GAMESERVERNAME/common.cfg
if [ -f ~/linuxgsm/lgsm/config-lgsm/$LGSM_GAMESERVERNAME/$LGSM_GAMESERVERNAME.cfg.tmpl ]; then
gomplate -d env=~/linuxgsm/env.json -f ~/linuxgsm/lgsm/config-lgsm/$LGSM_GAMESERVERNAME/$LGSM_GAMESERVERNAME.cfg.tmpl -o ~/linuxgsm/lgsm/config-lgsm/$LGSM_GAMESERVERNAME/$LGSM_GAMESERVERNAME.cfg
fi
echo "Gomplating game configs"
for d in /home/linuxgsm/linuxgsm/lgsm/config-default/config-game-template/*/ ; do
configGameFolder=$(basename $d)
for f in $d/*.tmpl ; do
configGameFile=$(basename $f)
outputConfigGameFile=$(basename $f .tmpl)
outputFile="/home/linuxgsm/linuxgsm/lgsm/config-default/config-game/$configGameFolder/$outputConfigGameFile"
gomplate -f $f -o $outputFile
chmod u+x,g+x $outputFile
done
done
echo "DONE GOMPLATING"
echo "Start tailing logs"
if [ "$LGSM_CONSOLE_STDOUT" == "true" ]; then
tail -F ~/linuxgsm/log/console/lgsm-gameserver-console.log &
fi
if [ "$LGSM_SCRIPT_STDOUT" == "true" ]; then
tail -F ~/linuxgsm/log/script/lgsm-gameserver-script.log &
fi
if [ "$LGSM_ALERT_STDOUT" == "true" ]; then
tail -F ~/linuxgsm/log/script/lgsm-gameserver-alert.log &
fi
if [ "$LGSM_GAME_STDOUT" == "true" ]; then
tail -F ~/linuxgsm/log/server/output_log*.txt &
fi
if [ -n "$LGSM_UPDATEINSTALLSKIP" ]; then
case "$LGSM_UPDATEINSTALLSKIP" in
"UPDATE")
touch INSTALLING.LOCK
./linuxgsm.sh $LGSM_GAMESERVERNAME
mv $LGSM_GAMESERVERNAME lgsm-gameserver
./lgsm-gameserver auto-install || true
exitcode="$?"
if [ "$exitcode" -gt "0" ] && [ "$exitcode" != "3" ]; then
# Retry once
echo "Unexpected error when updating ($exitcode). Trying again."
./lgsm-gameserver auto-install || true
exitcode="$?"
fi
rm -f INSTALLING.LOCK
if [ "$exitcode" != "0" ] && [ "$exitcode" != "3" ]; then
# exitcode 3 is a warning, in this case the warning we don't care about is steam not being installed
# any other thing not being installed is an issue, but steam will be installed if it's missing.
# we can't use the one in apt-get for some reason (it installs but it always hangs installing games)
echo "Unexpected exit code during install $exitcode"
exit $exitcode
fi
echo "Game has been updated. Starting"
;;
"INSTALL")
touch INSTALLING.LOCK
./linuxgsm.sh $LGSM_GAMESERVERNAME
mv $LGSM_GAMESERVERNAME lgsm-gameserver || true
ls -ltr
./lgsm-gameserver auto-install || true
exitcode="$?"
if [ "$exitcode" -gt "0" ] && [ "$exitcode" != "3" ]; then
# Retry once
echo "Unexpected error when installing ($exitcode). Trying again."
./lgsm-gameserver auto-install || true
exitcode="$?"
fi
echo "Install returned code $exitcode"
rm -f INSTALLING.LOCK
if [ "$exitcode" != "0" ] && [ "$exitcode" != "3" ]; then
# exitcode 3 is a warning, in this case the warning we don't care about is steam not being installed
# any other thing not being installed is an issue, but steam will be installed if it's missing.
# we can't use the one in apt-get for some reason (it installs but it always hangs installing games)
echo "Unexpected exit code during uninstall $exitcode"
exit $exitcode
fi
echo "Game has been installed. Exiting"
exit
;;
esac
fi
if [ ! -f lgsm-gameserver ]; then
echo "No game is installed, please set LGSM_UPDATEINSTALLSKIP"
exit 1
fi
# # configure game-specfic settings
# gomplate -f ${servercfgfullpath}.tmpl -o ${servercfgfullpath} // I can't predict what the filename is.
if [ "$LGSM_STOP_ON_FAILURE" == "true" ]; then
./lgsm-gameserver start
else
./lgsm-gameserver start || true
fi
sleep 30s
./lgsm-gameserver details
wait $!
sleep 30s