forked from lloesche/valheim-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
valheim-server
executable file
·60 lines (56 loc) · 1.79 KB
/
valheim-server
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
#!/bin/bash
cd /opt/valheim
valheim_server="/opt/valheim/valheim_server.x86_64"
valheim_server_pid=-1
SERVER_NAME=${SERVER_NAME:-My Server}
SERVER_PORT=${SERVER_PORT:-2456}
WORLD_NAME=${WORLD_NAME:-Dedicated}
SERVER_PASS=${SERVER_PASS:-secret}
SERVER_PUBLIC=${SERVER_PUBLIC:-1}
timeout=20
kill_signal=TERM
export SteamAppId=892970
export LD_LIBRARY_PATH="/opt/valheim/linux64/"
main() {
while :; do
if [ -f "$valheim_server" ]; then
break
else
echo "Valheim Server is not yet downloaded - waiting"
sleep 10
fi
done
echo "Running Valheim Server"
"$valheim_server" -nographics -batchmode -name "$SERVER_NAME" -port $SERVER_PORT -world "$WORLD_NAME" -password "$SERVER_PASS" -public $SERVER_PUBLIC &
valheim_server_pid=$!
wait
}
shutdown() {
if [ $valheim_server_pid -eq -1 ]; then
echo "Valheim server is not running yet - ignoring shutdown request"
return
fi
echo "Shutting down Valheim Server with PID $valheim_server_pid"
kill -INT $valheim_server_pid
shutdown_timeout=$(($(date +%s)+$timeout))
while [ -d "/proc/$valheim_server_pid" ]; do
if [ $(date +%s) -gt $shutdown_timeout ]; then
shutdown_timeout=$(($(date +%s)+$timeout))
echo "Timeout while waiting for server to shutdown - sending SIG$kill_signal to PID $valheim_server_pid"
kill -$kill_signal $valheim_server_pid
case "$kill_signal" in
INT)
kill_signal=TERM
;;
*)
kill_signal=KILL
esac
fi
echo "Waiting for Valheim Server with PID $valheim_server_pid to shutdown"
sleep 3
done
echo "Shutdown complete"
exit
}
trap shutdown SIGINT SIGTERM
main