Last active
April 27, 2022 12:29
-
-
Save LukeHuckman/1f6550efb2912ffa28324e6bb2cd9268 to your computer and use it in GitHub Desktop.
Minecraft Paper server startup script using GNU Screen (compatible with Linux and WSL on dual boot systems)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
windowspath=#Windows-equivalent server path goes here | |
linuxpath=#Linux-equivalent server path goes here | |
winhost=#WSL hostname goes here | |
#Check if the server is already running | |
if $(screen -list | grep -q minecraft); then | |
exec screen -x minecraft | |
else | |
#Check what OS is currently running | |
if [[ $(uname -n) == "$winhost" ]]; then | |
serverpath=$windowspath | |
else | |
serverpath=$linuxpath | |
fi | |
#Create update directory if it doesn't exist | |
if [ ! -d "$serverpath/update" ]; then | |
mkdir $serverpath/update | |
fi | |
#Check for server updates | |
cd $serverpath/update | |
version=#Server version goes here | |
URL="https://papermc.io/api/v1/paper/$version/latest/download" | |
fetch=$(wget --spider --server-response $URL 2>&1 | grep -i content-disposition) | |
remoteversion=$(echo $fetch | cut -d'=' -f 2) | |
if ! [[ $remoteversion == $(cat currentversion.txt) ]] ; then | |
while true; do | |
read -p "Paper update available. Download? [Y/n] " yn | |
case $yn in | |
[Nn]* ) break;; | |
* ) echo Downloading update... | |
wget --content-disposition $URL | |
ls | grep ".jar" > currentversion.txt | |
mv *.jar ../paper.jar | |
break;; | |
esac | |
done | |
fi | |
#Start the server in a screen | |
if [ -z "$STY" ]; then | |
screen -mS minecraft /bin/bash -c " | |
cd $serverpath | |
exec java -jar -Xms4G -Xmx4G -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 paper.jar -nogui" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment