forked from SystemRage/py-kms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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'" |