-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.sh
More file actions
131 lines (114 loc) · 3.07 KB
/
server.sh
File metadata and controls
131 lines (114 loc) · 3.07 KB
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
#!/bin/sh
download() {
download_result=$(wget -c --content-disposition -P "$2" -N "$1" 2>&1 | tail -2 | head -1)
echo "$download_result"
}
build=true
debug=true
backup=false
restart=false
version=1.16.5
memory=8
debug_port=5005
jar_url="https://papermc.io/api/v1/paper/$version/latest/download"
download_plugins=(
'https://github.com/monun/kotlin-plugin/releases/latest/download/Kotlin-1.4.31.jar'
'https://github.com/monun/auto-update/releases/latest/download/AutoUpdate.jar'
'https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib.jar'
'https://media.forgecdn.net/files/3209/364/worldedit-bukkit-7.2.3.jar'
)
# Print configurations
echo "build = $build"
echo "debug = $debug"
echo "backup = $backup"
echo "restart = $restart"
echo "version = $version"
echo "memory = ${memory}G"
project_folder=$(pwd)
script=$(basename "$0")
server_folder="$project_folder/.${script%.*}"
mkdir -p "$server_folder"
mkdir -p "$server_folder/plugins"
mkdir -p "$server_folder/.jar"
cd "$server_folder" || exit
# Download jar
jar_result=$(download "$jar_url" "./.jar")
jar=$(grep -oG "‘.*’" <<< $jar_result)
jar="${jar:1:-1}"
echo "$jar_result"
# Download plugins
for i in "${download_plugins[@]}"
do
download "$i" "./plugins"
done
jvm_arguments=(
"-Xmx${memory}G"
"-Xms${memory}G"
"-XX:+ParallelRefProcEnabled"
"-XX:MaxGCPauseMillis=200"
"-XX:+UnlockExperimentalVMOptions"
"-XX:+DisableExplicitGC"
"-XX:+AlwaysPreTouch"
"-XX:G1HeapWastePercent=5"
"-XX:G1MixedGCCountTarget=4"
"-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"
"-Dcom.mojang.eula.agree=true"
)
if (($memory < 12))
then
jvm_arguments+=(
"-XX:G1NewSizePercent=30"
"-XX:G1MaxNewSizePercent=40"
"-XX:G1HeapRegionSize=8M"
"-XX:G1ReservePercent=20"
"-XX:InitiatingHeapOccupancyPercent=15"
)
else
echo "Enable high-capacity memory jvm options"
jvm_arguments+=(
"-XX:G1NewSizePercent=40"
"-XX:G1MaxNewSizePercent=50"
"-XX:G1HeapRegionSize=16M"
"-XX:G1ReservePercent=15"
"-XX:InitiatingHeapOccupancyPercent=20"
)
fi
if ($debug)
then
jvm_arguments+=("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$debug_port")
fi
jvm_arguments+=(
"-jar"
"$jar"
"--nogui"
)
while :
do
if ($build)
then
cd "$project_folder" || exit
./gradlew clean copyToServer
cd "$server_folder" || exit
fi
java "${jvm_arguments[@]}"
if ($backup)
then
read -r -t 5 -p "Press Enter to start the backup immediately `echo $'\n> '`"
echo 'Start the backup.'
backup_file_name=$(date +"%y%m%d-%H%M%S")
mkdir -p '.backup'
tar --exclude='./.backup' --exclude='./.jar' --exclude='*.gz' --exclude='./cache' -zcf ".backup/$backup_file_name.tar.gz" .
echo 'The backup is complete.'
fi
if (! ($restart))
then
break
fi
read -r -t 5 -p "The server restarts. Press Enter to start immediately or Ctrl+C to cancel `echo $'\n> '`"
done