Skip to content

Instantly share code, notes, and snippets.

@Cazcez
Last active December 13, 2022 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cazcez/1c6e62947d01f3fea61f2cba68fb1d03 to your computer and use it in GitHub Desktop.
Save Cazcez/1c6e62947d01f3fea61f2cba68fb1d03 to your computer and use it in GitHub Desktop.
A basic bash startup script with aikar's flag for starting Minecraft servers
#!/bin/bash
# define the java or path of a java version you need (default: java)
JAVA="java"
# name of the server .jar file
JAR_FILE="server.jar"
# define max ram (1024M/1G 2048M/2G...)
MAX_RAM=8G
# agree EULA of minecraft without editing eula.txt. Please note, this is still legally binding that you have read and agree to the Minecraft EULA. (true/false)
ACCEPT_EULA=true
# puts all your world folders into a specific folder. If you leave blank, nothing will change (worlds, files/worlds...)
WORLD_DIRECTORY="worlds"
# sets timezone of JVM. useful for those who have a server in a foreigner country (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
TIMEZONE="Europe/Istanbul"
# auto restart on shutdown
RESTART=false
# print something
echo Starting the server...
# do the actual work
${JAVA} -Xms${MAX_RAM} -Xmx${MAX_RAM} -XX:+UseG1GC -Duser.language=en -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 -Duser.region=EN -Dfile.encoding=UTF-8 -Dcom.mojang.eula.agree=${ACCEPT_EULA} -Duser.timezone="${TIMEZONE}" -jar $JAR_FILE nogui --world-dir "./${WORLD_DIRECTORY}"
# check if auto restart is true
if [[ "$RESTART" == true ]]; then
eval "bash $(basename "$0")"
fi
# ask to restart
read -p "Restart the server? [Y/N]: " chosen
if [[ "$chosen" == "Y" ]] || [[ "$chosen" == "y" ]]; then
# restart if "y" or "Y" is entered
eval "bash $(basename "$0")"
fi
echo Server closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment