Skip to content

Commit f26e0f5

Browse files
authored
Merge pull request #135 from jsknnr/dev
fixed regression in server json config when not using external config…
2 parents 20293f9 + 559a524 commit f26e0f5

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

container/enshrouded_server_example.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,14 @@
5252
},
5353
"userGroups": [
5454
{
55-
"name": "Admin",
56-
"password": "changemeplease",
55+
"name": "Default",
56+
"password": "",
5757
"canKickBan": true,
5858
"canAccessInventories": true,
5959
"canEditWorld": true,
6060
"canEditBase": true,
6161
"canExtendBase": true,
6262
"reservedSlots": 0
63-
},
64-
{
65-
"name": "Friend",
66-
"password": "alsochangemeplease",
67-
"canKickBan": false,
68-
"canAccessInventories": true,
69-
"canEditWorld": true,
70-
"canEditBase": true,
71-
"canExtendBase": false,
72-
"reservedSlots": 0
7363
}
7464
],
7565
"bannedAccounts": [

container/entrypoint.sh

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if [ "$EXTERNAL_CONFIG" -eq 0 ]; then
3131
[ -z "${SERVER_PASSWORD:-}" ] && \
3232
echo "$(timestamp) WARN: SERVER_PASSWORD not set, server will be public"
3333
else
34-
echo "$(timestamp) INFO: EXTERNAL_CONFIG is set, checking for presence and permmission"
34+
echo "$(timestamp) INFO: EXTERNAL_CONFIG is set, checking for presence and permission"
3535
if [ ! -f "$ENSHROUDED_CONFIG" ]; then
3636
echo "$(timestamp) ERROR: EXTERNAL_CONFIG set but config not found at $ENSHROUDED_CONFIG"
3737
exit 1
@@ -42,6 +42,7 @@ else
4242
echo "$(timestamp) INFO: Adjust ownership and restart the container (e.g. sudo chown 10000:10000 /path/to/your/enshrouded_server.json)"
4343
exit 1
4444
fi
45+
echo "$(timestamp) INFO: External config found and ownership looks good"
4546
fi
4647

4748
########################################
@@ -66,6 +67,7 @@ fi
6667
# Config handling
6768
########################################
6869

70+
# Only modify config if we are not using external config
6971
if [ "$EXTERNAL_CONFIG" -eq 0 ]; then
7072
if [ ! -f "$ENSHROUDED_CONFIG" ]; then
7173
echo "$(timestamp) INFO: Server config not present, copying example"
@@ -88,21 +90,29 @@ if [ "$EXTERNAL_CONFIG" -eq 0 ]; then
8890
| .ip = $i
8991
| (if $p != "" then .userGroups[]?.password = $p else . end)
9092
' "$ENSHROUDED_CONFIG" > "$tmpfile" \
91-
&& mv "$tmpfile" "$ENSHROUDED_CONFIG"
93+
&& mv "$tmpfile" "$ENSHROUDED_CONFIG" && chmod 644 "$ENSHROUDED_CONFIG"
9294
fi
9395

96+
# We will use the query port for monitoring server state instead of pid
97+
# Retrieve port form the config as that is absolute source of truth
98+
QUERY_PORT=$(jq -r '.queryPort' "$ENSHROUDED_CONFIG")
99+
# Convert port to hex
100+
QUERY_PORT_HEX=$(printf '%04X' "$QUERY_PORT")
101+
94102
########################################
95-
# Savegame & logs
103+
# Permissions & logs
96104
########################################
97105

98106
mkdir -p "$ENSHROUDED_PATH/savegame" "$ENSHROUDED_PATH/logs"
99107

108+
# Check savegame directory is writable
100109
if ! touch "$ENSHROUDED_PATH/savegame/.permtest"; then
101110
echo "$(timestamp) ERROR: Savegame directory is not writable"
102111
exit 1
103112
fi
104113
rm -f "$ENSHROUDED_PATH/savegame/.permtest"
105114

115+
# Link logs to stdout
106116
: > "$ENSHROUDED_PATH/logs/enshrouded_server.log"
107117
ln -sf /proc/1/fd/1 "$ENSHROUDED_PATH/logs/enshrouded_server.log"
108118

@@ -117,22 +127,28 @@ echo "$(timestamp) INFO: Starting Enshrouded Dedicated Server"
117127
"${STEAMCMD_PATH}/compatibilitytools.d/GE-Proton${GE_PROTON_VERSION}/proton" \
118128
run "$ENSHROUDED_PATH/enshrouded_server.exe" &
119129

120-
# Wait for process to start
121-
for i in {1..10}; do
122-
if pgrep -f enshrouded_server.exe >/dev/null; then
130+
# Wait for server to be up by checking UDP port
131+
echo "$(timestamp) INFO: Waiting for server to be up and listening on UDP port $QUERY_PORT"
132+
133+
for i in {1..30}; do
134+
if awk '{print $2}' /proc/net/udp | grep -q ":$QUERY_PORT_HEX$"; then
135+
echo "$(timestamp) INFO: Server is up and listening on UDP port $QUERY_PORT"
123136
break
124137
fi
125-
sleep 6
126-
echo "$(timestamp) INFO: Waiting for enshrouded_server.exe"
127-
if [ "$i" -eq 10 ]; then
128-
echo "$(timestamp) ERROR: Timed out waiting for server to start"
138+
139+
if [ "$i" -eq 30 ]; then
140+
echo "$(timestamp) ERROR: Timed out waiting for server to be up and listening on UDP port $QUERY_PORT"
129141
exit 1
130142
fi
143+
144+
sleep 2
131145
done
132146

133-
# Hold us open until we recieve a SIGTERM
134-
while pgrep -f '[e]nshrouded_server.exe' >/dev/null; do
135-
sleep 10
147+
# Hold the container open while the server is running by monitoring the UDP port
148+
echo "$(timestamp) INFO: Monitoring server heartbeat via UDP port $QUERY_PORT"
149+
150+
while awk '{print $2}' /proc/net/udp | grep -q ":$QUERY_PORT_HEX$"; do
151+
sleep 3
136152
done
137153

138154
exit 0

0 commit comments

Comments
 (0)