-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-server.sh
executable file
·88 lines (75 loc) · 1.91 KB
/
start-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
#!/bin/bash
read_rcon_password(){
RCON_PASSWORD=$(grep 'rcon.password=' /minecraft/server/server.properties | cut -d'=' -f2)
}
send_rcon(){
mcrcon -c -H localhost -P 25575 -p "$RCON_PASSWORD" "$@"
}
start_server(){
echo "Starting Minecraft server."
java -Xmx${JAVA_MEMORY_MAX} \
-Xms${JAVA_MEMORY_MIN} \
-XX:+UseG1GC \
-XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=200 \
-XX:+UnlockExperimentalVMOptions \
-XX:+DisableExplicitGC \
-XX:+AlwaysPreTouch \
-XX:G1NewSizePercent=20 \
-XX:G1ReservePercent=20 \
-XX:G1HeapRegionSize=32M \
-jar /minecraft/server/forge-${MINECRAFT_VERSION}-${FORGE_VERSION}.jar nogui &
MINECRAFT_PID=$!
}
send_countdown(){
for i in 5 4 3 2; do
send_rcon "say Server is $1 in $i minutes!"
sleep 60
done
send_rcon "say Server is $1 in 60 seconds."
sleep 30
send_rcon "say Server is $1 in 30 seconds. Please log out now!"
sleep 25
send_rcon "say Server is $1 in 5 seconds. Please log out now!"
sleep 5
send_rcon "say Server is $1 now!"
}
stop_server(){
echo "Stopping Minecraft server."
send_countdown "shutting down"
if [ ! -z "$MINECRAFT_PID" ]; then
kill -SIGTERM "$MINECRAFT_PID"
wait "$MINECRAFT_PID"
fi
}
restart_server(){
echo "Restarting Minecraft server."
send_countdown "restarting"
if [ ! -z "$MINECRAFT_PID" ]; then
kill -SIGTERM "$MINECRAFT_PID"
wait "$MINECRAFT_PID"
fi
sleep 5
start_server
}
trap stop_server SIGTERM SIGINT
echo "Starting server"
read_rcon_password
rm -f autostart.stamp
start_server
while true; do
sleep 10
if [ -e autostop.stamp ]; then
echo "autostop.stamp found. Stopping server."
rm -f autostop.stamp
stop_server
break
fi
if [ -e autostart.stamp ]; then
echo "autostart.stamp found. Restarting server."
rm -f autostart.stamp
restart_server
echo "Server process restarted."
fi
done
wait $!