File tree 2 files changed +39
-2
lines changed
2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ FROM mono:slim
3
3
# Update and install needed utils
4
4
RUN apt-get update && \
5
5
apt-get upgrade -y && \
6
- apt-get install -y curl nuget vim zip && \
6
+ apt-get install -y curl nuget vim zip procps && \
7
7
apt-get clean && \
8
8
rm -rf /var/lib/apt/lists/*
9
9
Original file line number Diff line number Diff line change @@ -27,5 +27,42 @@ if [ "${world:-null}" != null ]; then
27
27
CMD=" $CMD -world /config/$world "
28
28
fi
29
29
30
+ # Create named pipe if one doesn't already exist
31
+ # This is so we can send input to TerrariaServer
32
+ if [ ! -p " /vanilla/console" ]; then
33
+ mkfifo /vanilla/console
34
+ fi
35
+
36
+ # trap SIGTERM signal and call graceful_shutdown
37
+ trap ' kill ${!}; graceful_shutdown' SIGTERM
38
+
39
+ function graceful_shutdown() {
40
+ # Send a message to players that the server is shutting down
41
+ echo say ' Server shutting down' > /vanilla/console
42
+
43
+ echo " Stopping Terraria server..."
44
+ echo " Saving world"
45
+
46
+ echo exit > /vanilla/console
47
+
48
+ # Waiting for server to finish saving & shutting down
49
+ pid=$( pgrep -f ^./TerrariaServer)
50
+ if [ -z " $pid " ]; then exit 1; fi
51
+ while [ -e /proc/$pid ]; do
52
+ sleep 1
53
+ done
54
+ echo " World save complete"
55
+ echo " Shutting down"
56
+ exit 0
57
+ }
58
+
30
59
echo " Starting container, CMD: $CMD $@ "
31
- exec $CMD $@
60
+ (tail -f > /vanilla/console & $CMD $@ < console) &
61
+
62
+ tail -f /dev/null & wait ${! }
63
+
64
+ pid=$( pgrep -f ^./TerrariaServer)
65
+ if [ -z " $pid " ]; then exit 1; fi
66
+ while [ -e /proc/$pid ]; do
67
+ sleep 5
68
+ done
You can’t perform that action at this time.
0 commit comments