-
Notifications
You must be signed in to change notification settings - Fork 9
/
Linux_StartScript.sh
178 lines (177 loc) · 7.19 KB
/
Linux_StartScript.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
#By Kristjan Krusic aka. krusic22
#Don't forget to adjust the variables according your own needs!
#This is an Java 16+ optimised script! Get the most recent AdoptJDK or ZuluJDK for ARM.
#This script is speed-optimized and won't reduce ram use!
#Less time spent on GC, the better the performance, but possibly higher ram usage.
#Note: 1G = 1024M
STARTRAM=128 #USE VALUES IN M! Sometimes setting this to the same value as MAXRAM can help performance.
MAXRAM=1024 #USE VALUES IN M!
JARNAME=paper.jar #Jar name, quite self-explanatory.
###
#Auto updater toggle.
UPDATER="true"
#After how many restarts should the script attempt to update the jar.
#Note, the jar will always be updated on first startup!
UPDATEAFTER="1"
#Default is new, using the PaperMC Donwnload API, use old if you want to download from a link.
UPDATERVERSION="new"
#Update program. Current options are curl and wget.
UPDATEPROGRAM="curl"
###
#PaperMC API Settings. More info: https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config
PROJECT="paper"
VERSION="1.17.1"
#Note: latest is not actually a part of the API, so the script gets the latest build ID using the API first.
BUILD="latest"
###
#OLD updater version download link.
JARLINK="https://papermc.io/api/v1/paper/1.16.5/latest/download"
###
#Only use one garbage collector!
GONE=true #Use G1 GC. Flags from: https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
SHEN=false #Use ShenandoahGC. Untested for now.
ZGC=false #The Z Garbage Collector. Please read: https://krusic22.com/2020/03/25/higher-performance-crafting-using-jdk11-and-zgc/
###
#Experimental stuff. Good luck.
EXP=false #Enable experimental stuff... It might cause unexpected problems but I haven't noticed any yet.
LP=false #Enable only if you have Large/Huge Pages enabled, transparent pages are recommended for regular users.
X86=false #Flags that should only work on X86.
###
#Jar parameters like --nogui or --forceUpgrade, you can list all options by setting this to --help.
AFTERJAR="--nogui"
###
#Unused Parameters, you might want to use some of them depending on your configuration, copy the parameters under Normal Parameters,
#since IgnoreUnrecognizedVMOptions is set, unknown / invalid options will be ignored instead of stopping the JVM.
#-XX:ActiveProcessorCount=4 #This should restrict the use of CPU cores, although this is more of a suggestion than a constraint.
#-Xlog:gc*:file=GC.log #This will log GC to a file called GC.log, which can be used to debug GC, replace 'file=GB.log' with 'stdout' if you want logging to the console. Other options you can change/add pid,level,tags,...
#-Xlog:gc*:file=GC.log:time,uptimemillis,tid #Same as above, but with local time, uptime/runtime and thread IDs.
#-Xlog:gc*=debug:file=GC.log:time,uptimemillis,tid #Same as above, but with some extra debug. Warning: This is going to grow quickly!
###
#Normal Parameters
PARMS="
-server
-XX:+IgnoreUnrecognizedVMOptions
-XX:+UnlockExperimentalVMOptions
-XX:+UnlockDiagnosticVMOptions
-XX:-OmitStackTraceInFastThrow
-XX:+ShowCodeDetailsInExceptionMessages
-XX:+DisableExplicitGC
-XX:+PerfDisableSharedMem
--illegal-access=permit
"
#G1 optimizations...
GONEP="
-XX:MaxGCPauseMillis=200
-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:MaxTenuringThreshold=1
"
#Shenandoah options that might be worth looking into, some of the options only got added in JDK12+, currently set to default values from AdoptJDK13.
SHENP="
-XX:ShenandoahAllocSpikeFactor=5
-XX:ShenandoahControlIntervalAdjustPeriod=1000
-XX:ShenandoahControlIntervalMax=10
-XX:ShenandoahControlIntervalMin=1
-XX:ShenandoahInitFreeThreshold=70
-XX:ShenandoahGarbageThreshold=25
-XX:ShenandoahGuaranteedGCInterval=300000
-XX:ShenandoahMinFreeThreshold=10
-XX:-ShenandoahRegionSampling
-XX:ShenandoahRegionSamplingRate=40
"
#ZGC options. Most of them only available in JDK13+.
#Copy them to the ZGCP area.
#-XX:-ZUncommit
#-XX:ZUncommitDelay=300
#-XX:SoftMaxHeapSize=4G
#-XX:+ZCollectionInterval=5
#-XX:ZAllocationSpikeTolerance=2.0
ZGCP="
"
#Experimental options... Use at your own risk!
if [ "$EXP" = true ]; then
echo "You have enabled Experimental Options! Use at your own risk!"
PARMS="$PARMS -XX:+ExitOnOutOfMemoryError -XX:+AlwaysPreTouch -XX:-DontCompileHugeMethods -XX:+TrustFinalNonStaticFields -XX:+UseFastUnorderedTimeStamps "
fi
#Large Pages config
if [ "$LP" = true ]; then
PARMS="$PARMS -XX:+UseTransparentHugePages -XX:LargePageSizeInBytes=2M -XX:+UseLargePages"
fi
#G1 Is only useful when you have some ram... The old recommendation was 4GB, but I've seen improvements even on 512MB.
if [ "$GONE" = true ]; then
PARMS="$PARMS -XX:+UseG1GC $GONEP"
fi
#Experimental ShenandoahGC
if [ "$SHEN" = true ]; then
PARMS="$PARMS -XX:+UseShenandoahGC $SHENP"
fi
#Experimental ZGC
if [ "$ZGC" = true ]; then
PARMS="$PARMS -XX:+UseZGC $ZGCP"
fi
#Experimental X86 abomination, some of the flags may not be ARCH specific, so they could work on other platforms as well.
if [ "$X86" = true ]; then
PARMS="$PARMS -XX:+UseCMoveUnconditionally -XX:+UseNewLongLShift -XX:+UseVectorCmov -XX:+UseXmmI2D -XX:+UseXmmI2F"
fi
###
#Updater. This time actually formatted for readability.
RUN=0
function Updater {
if [ "$UPDATER" = true ]; then
if [ "$(( "$RUN" % "$UPDATEAFTER"))" = 0 ] || [ "$RUN" = 0 ]; then
echo "Updating Jar..."
#New PaperMC API updater
if [ "$UPDATERVERSION" = "new" ]; then
if [ "$BUILD" = "latest" ]; then
if [ $UPDATEPROGRAM = "curl" ]; then
BUILD=$(curl -s https://papermc.io/api/v2/projects/$PROJECT/versions/$VERSION | grep -E -o '[0-9]+' | tail -1)
fi
if [ $UPDATEPROGRAM = "wget" ]; then
BUILD=$(wget -q https://papermc.io/api/v2/projects/$PROJECT/versions/$VERSION -O - | grep -E -o '[0-9]+' | tail -1)
fi
fi
JARLINK="https://papermc.io/api/v2/projects/$PROJECT/versions/$VERSION/builds/$BUILD/downloads/$PROJECT-$VERSION-$BUILD.jar"
if [ $UPDATEPROGRAM = "curl" ]; then
curl -s "$JARLINK" > "$JARNAME"
fi
if [ $UPDATEPROGRAM = "wget" ]; then
wget "$JARLINK" -O "$JARNAME" 2>/dev/null
fi
fi
#Old updater
if [ "$UPDATERVERSION" = "old" ]; then
if [ $UPDATEPROGRAM = "curl" ]; then
curl -s "$JARLINK" > "$JARNAME"
fi
if [ $UPDATEPROGRAM = "wget" ]; then
wget "$JARLINK" -O "$JARNAME" 2>/dev/null
fi
fi
fi
fi
RUN=$((RUN+1))
}
###
#You can stop this script by pressing CTRL+C multiple times.
while true
do
Updater
echo "Starting!"
java -Xms$STARTRAM\M -Xmx$MAXRAM\M $PARMS -jar $JARNAME $AFTERJAR
echo "Server will restart in:"
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
sleep 1
done