-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathminecraft-server
92 lines (83 loc) · 2.31 KB
/
minecraft-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
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
#!/bin/bash
#
# minecraft-server Start up and shut down minecraft-server
#
# chkconfig: 345 99 1
# description: Starts minecraft-server
# Source function library.
. /etc/init.d/functions
# Adjust below to match your system
WORKDIR="/usr/local/minecraft-server"
MIN_MEMORY_ALLOCATION="2G"
MAX_MEMORY_ALLOCATION="2G"
# Additional Java flags recommended by Aikar: https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
# Modify as needed.
JAVA_FLAGS="-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true"
# Don't modify below
RETVAL=0
getpid() {
pid=`ps -eo pid,comm | grep java | awk '{ print $1 }'`
}
start() {
echo -n $"Starting minecraft: "
getpid
if [ -z "$pid" ]; then
cd $WORKDIR
nohup /usr/bin/java -Xms$MIN_MEMORY_ALLOCATION -Xmx$MAX_MEMORY_ALLOCATION $JAVA_FLAGS -server -jar $WORKDIR/server.jar nogui > $WORKDIR/service.log 2>&1 &
RETVAL=$?
fi
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/minecraft-server
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping minecraft: "
getpid
RETVAL=$?
if [ -n "$pid" ]; then
kill -9 $pid
sleep 1
getpid
if [ -z "$pid" ]; then
rm -f /var/lock/subsys/minecraft-server
echo_success
else
echo_failure
fi
else
echo_failure
fi
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
getpid
if [ -n "$pid" ]; then
echo "minecraft-server (pid ${pid}) is running..."
else
RETVAL=1
echo "minecraft-server is stopped"
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0