Skip to content

Instantly share code, notes, and snippets.

@inertia186
Last active December 13, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inertia186/4975355 to your computer and use it in GitHub Desktop.
Save inertia186/4975355 to your computer and use it in GitHub Desktop.
[Minecraft, SMP] This is a very basic launch script for Minecraft. It uses "screen" so you can inject external commands and scripts.
#!/bin/bash
MC=/Users/steve/Minecraft/
echo \#\#\#
echo \#\#\# It is normal to see a \"NameError: global name 'socket' is not defined\" here if the server really is down.
echo \#\#\#
query=`$MC/scripts/Dinnerbone-mcstatus-a24e563/cli.py -t 1 -r 0 localhost | wc -l`
query=$(sed -e 's/^[[:space:]]*//' <<<"$query")
if [ $query -ge 1 ]; then
echo Already started.
exit
fi
echo Starting ...
cd $MC
# This ensures we're using the server vm.
JAVA_OPTS="-server"
# Define a specific max and min heap. Do not use with -XX:+AggressiveHeap.
JAVA_OPTS="$JAVA_OPTS -Xmx4G -Xms2G"
# This option instructs the JVM to push memory use to the limit (use with
# caution). This option appears to conflict with -XX:+UseG1GC.
#JAVA_OPTS="$JAVA_OPTS -XX:+AggressiveHeap"
# Reduce stack requirements (use with -XX:+AggressiveHeap).
#JAVA_OPTS="$JAVA_OPTS -Xss"
# Garbge Collector: G1GC. Also, additional GC logging and disabled System.gc()
# calls, if any (usually, SMP only calls System.gc() when the "nogui" app parameter
# is absent).
JAVA_OPTS="$JAVA_OPTS -Xloggc:server_gc.log -XX:+UseG1GC -XX:+DisableExplicitGC"
# Use optimized versions of Get<Primitive>Field.
JAVA_OPTS="$JAVA_OPTS -XX:+UseFastAccessorMethods"
# Enables caching of commonly allocated strings.
JAVA_OPTS="$JAVA_OPTS -XX:+UseStringCache"
# Optimize String concatenation operations where possible.
JAVA_OPTS="$JAVA_OPTS -XX:+OptimizeStringConcat"
# Enables the use of compressed pointers (object references represented as 32 bit
# offsets instead of 64-bit pointers) for optimized 64-bit performance with Java
# heap sizes less than 32gb.
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops"
# Pre-touch the Java heap during JVM initialization. Every page of the heap is
# thus demand-zeroed during initialization rather than incrementally during
# application execution.
JAVA_OPTS="$JAVA_OPTS -XX:+AlwaysPreTouch"
# Inline a previously compiled method only if its generated native code size is
# less than this.
JAVA_OPTS="$JAVA_OPTS -XX:InlineSmallCode=2000"
# Enable biased locking. http://www.oracle.com/technetwork/java/tuning-139912.html#section4.2.5
JAVA_OPTS="$JAVA_OPTS -XX:+UseBiasedLocking"
# Enables the Java heap to take advantage of Non-Uniform-Memory-Architectures.
# JAVA will place data structures relevant to the thread which it owns /
# operates on, in memory locations closest to that particular processor.
# Depending on the environment, gains can be substantial. Intel market NUMA as
# Quick Path Interconnect.
#JAVA_OPTS="$JAVA_OPTS -XX:+UseNUMA"
#
# VM Triggers (optional)
#
#JAVA_OPTS="$JAVA_OPTS -XX:OnError=$MC/scripts/jvm_on_error.sh"
#JAVA_OPTS="$JAVA_OPTS -XX:OnOutOfMemoryError=$MC/scripts/jvm_on_out_of_memory.sh"
screen -dmS minecraft java $JAVA_OPTS -jar minecraft_server.jar nogui
# Uncoment this (and comment out the line above) to see any errors at launch without screen in the way.
#java $JAVA_OPTS -jar minecraft_server.jar nogui
@inertia186
Copy link
Author

It also checks to make sure the server is not already running. For this functionality, you need to download: http://github.com/Dinnerbone/mcstatus

If you are not on Java 7, you may need to disable G1GC.

@inertia186
Copy link
Author

I have personally confirmed that -XX:+UseNUMA is available on certain platforms (even on non-Solaris). Enable this to take advantage of certain memory allocation optimizations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment