-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathark-server.sh
executable file
·209 lines (180 loc) · 5.54 KB
/
ark-server.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env bash
source settings.cfg
source setup_map.sh
# show help
USAGE="$(basename $0) mode [options]
available modes:
- install:
installs/updates steam and ark server in configured HOST_STEAM_PATH
- start:
start ark server
- stop:
stop ark server (or all servers)
"
if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ $# -le 0 ]; then
echo "$USAGE"
exit 0
fi
# start - mode
function start_server {
# Default map
MAP="TheIsland"
USAGE="$(basename $0) start map [-p/--port port] [-c/--cluster]"
while [[ $# -gt 0 ]]; do
case $1 in
-p|--port)
PORT="$2"
shift; shift;
;;
-c|--cluster)
if [ -z "${CLUSTER_NAME}" ]; then
echo "Cluster not configured! Please add CLUSTER_NAME to settings.cfg" >&2
exit 1
fi
CLUSTER="${CLUSTER_NAME}"
shift
;;
-h|--help)
echo "usage: $USAGE"
exit 0
;;
-*|--*)
echo "Unknown option $1" >&2
echo "usage: $USAGE" >&2
exit 1
;;
*)
MAP=$1
shift
;;
esac
done
# Setup map name and port
setup_map ${MAP} ${PORT}
# Set raw and query port based on client port
RAW_PORT=$((PORT+1))
QUERY_PORT=$((PORT-7777+27015))
# Set up game options
GAME_OPTS="${MAP}?listen"
if [ ! -z "${CLUSTER}" ]; then
GAME_OPTS="${GAME_OPTS}?SessionName=${CLUSTER}_${MAP}"
GAME_OPTS="${GAME_OPTS}?AltSaveDirectoryName=map_${CLUSTER}_${MAP}"
else
GAME_OPTS="${GAME_OPTS}?SessionName=${MAP}"
GAME_OPTS="${GAME_OPTS}?AltSaveDirectoryName=map_single_${MAP}"
fi
GAME_OPTS="${GAME_OPTS}?Port=${PORT}"
GAME_OPTS="${GAME_OPTS}?QueryPort=${QUERY_PORT}"
GAME_OPTS="${GAME_OPTS}?MaxPlayers=${MAX_PLAYER}"
GAME_OPTS="${GAME_OPTS}?DisableWeatherFog=true"
# If modded map is used the MAP_MOD variable needs to be set
if [ ! -z "${MAP_MOD}" ]; then
GAME_OPTS="${GAME_OPTS}?GameModIds=${MODS},${MAP_MOD}"
else
GAME_OPTS="${GAME_OPTS}?GameModIds=${MODS}"
fi
# Set up game parameters
GAME_PARAMS=""
if [ ! -z "${CLUSTER}" ]; then
GAME_PARAMS="${GAME_PARAMS} -clusterid=${CLUSTER}"
fi
# If EVENT variable is set use it as ActiveEvent parameter
if [ ! -z "${EVENT}" ]; then
GAME_PARAMS="${GAME_PARAMS} -ActiveEvent=${EVENT}"
fi
# Add additional Parameter from settings.cfg and some default parameters necessary for the server
GAME_PARAMS="${GAME_PARAMS} ${ADDITIONAL_PARAMS} -automanagedmods -server -high -log"
echo "-----------"
echo "Starting ARK Server with map: $MAP_NAME ($MAP)"
echo "Using ports: $PORT, $RAW_PORT, $QUERY_PORT"
echo "-----------"
CMD="/home/steam/ark/ShooterGame/Binaries/Linux/ShooterGameServer ${GAME_OPTS} ${GAME_PARAMS}"
echo $CMD
echo "-----------"
docker run -d --rm \
--volume ${HOST_STEAM_PATH}:/home/steam \
--publish ${PORT}:${PORT}/udp \
--publish ${RAW_PORT}:${RAW_PORT}/udp \
--publish ${QUERY_PORT}:${QUERY_PORT}/udp \
--ulimit nofile=100000:100000 \
--workdir=/home/steam/ark/ShooterGame/Saved/Logs \
--name ArkServer-${MAP_NAME} \
ark-server:latest ${CMD}
}
# stop mode
function stop_server {
TIMEOUT=180
STOP_ALL=0
USAGE="$(basename $0) stop [map] [-a/--all]"
MAPS=()
while [[ $# -gt 0 ]]; do
case $1 in
-a|--all)
STOP_ALL=1
shift
;;
-h|--help)
echo "usage: $USAGE"
exit 0
;;
-*|--*)
echo "unknown option $1" >&2
echo "usage: $USAGE" >&2
exit 1
;;
*)
MAPS+=("$1")
shift
;;
esac
done
CONTAINERS=$(docker ps --filter "name=ArkServer" --format "{{.Names}}")
for container in ${CONTAINERS}; do
if [ $STOP_ALL -eq 1 ]; then
docker stop --time ${TIMEOUT} ${container}
continue
fi
for map in "${MAPS[@]}"; do
if [ "$container" == "$map" ] || [ "$container" == "ArkServer-$map" ]; then
docker stop --time ${TIMEOUT} ${container}
continue
fi
done
done
}
function install_server {
# Install Steam (if necessary)
if [ ! -e "${HOST_STEAM_PATH}/steamcmd" ]; then
docker run -it --rm \
--volume ${HOST_STEAM_PATH}:/home/steam \
--name ArkServer-Setup \
ark-server:latest \
/bin/bash -c "mkdir steamcmd; curl -sqL 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' | tar -C steamcmd -zxvf - && steamcmd/steamcmd.sh +quit"
fi
# Install (or update) ArkServer
docker run -it --rm \
--volume ${HOST_STEAM_PATH}:/home/steam \
--name ArkServer-Setup \
ark-server:latest \
/bin/bash -c "steamcmd/steamcmd.sh +force_install_dir /home/steam/ark +login anonymous +app_update 376030 +quit"
}
# check mode
case $1 in
install)
shift;
install_server $@
;;
start)
shift;
start_server $@
;;
stop)
shift;
stop_server $@
;;
*)
echo "Mode '$1' unknown, usage:"
echo $USAGE
exit 1
esac
exit 0