Skip to content

Commit

Permalink
Create mc
Browse files Browse the repository at this point in the history
  • Loading branch information
rekkun authored Apr 16, 2020
1 parent 2b9351a commit 2ddf8f9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions opt/mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

mc_port=25566
port=${1:-${PORT:-8080}}

if [ -z "$NGROK_API_TOKEN" ]; then
echo "You must set the NGROK_API_TOKEN config var to create a TCP tunnel!"
exit 1
fi

# Start the TCP tunnel
ngrok_cmd="bin/ngrok tcp -authtoken $NGROK_API_TOKEN -log stdout --log-level debug ${NGROK_OPTS} ${mc_port}"
echo "Starting ngrok..."
eval "$ngrok_cmd | tee ngrok.log &"
ngrok_pid=$!

# Do an inline sync first, then start the background job
echo "Starting sync..."
bin/sync
if [ "$READ_ONLY" != "true" ]; then
eval "while true; do sleep ${AWS_SYNC_INTERVAL:-60}; bin/sync; done &"
sync_pid=$!
fi

# create server config
echo "server-port=${mc_port}" >> /app/server.properties
for f in whitelist banned-players banned-ips ops; do
test ! -f $f.json && echo -n "[]" > $f.json
done

limit=$(ulimit -u)
case $limit in
512) # 2X Dyno
heap="768m"
;;
32768) # PX Dyno
heap="4g"
;;
*) # 1X Dyno
heap="384m"
;;
esac

echo "Starting: minecraft ${mc_port}"
eval "screen -L -h 2048 -dmS minecraft java -Xmx${heap} -Xms${heap} -jar minecraft.jar nogui"
main_pid=$!

# Flush the logfile every second, and ensure that the logfile exists
screen -X "logfile 1" && sleep 1

echo "Tailing log"
eval "tail -f screenlog.0 &"
tail_pid=$!

trap "kill $ngrok_pid $main_pid $sync_pid $tail_pid" SIGTERM
trap "kill -9 $ngrok_pid $main_pid $sync_pid $tail_pid; exit" SIGKILL

eval "ruby -rwebrick -e'WEBrick::HTTPServer.new(:BindAddress => \"0.0.0.0\", :Port => ${port}, :MimeTypes => {\"rhtml\" => \"text/html\"}, :DocumentRoot => Dir.pwd).start'"

0 comments on commit 2ddf8f9

Please sign in to comment.