142 lines
3.5 KiB
Bash
Executable File
142 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# THe name of the screen in which the proxy server will run
|
|
PROXY_SCREEN="proxy"
|
|
# How many seconds to sleep before starting the server again, unless it is explicitly specified
|
|
DEFAULT_SLEEP_SECONDS=3
|
|
|
|
function main {
|
|
local proxy=false
|
|
local bungee=false
|
|
local help=false
|
|
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
|
|
local config=""
|
|
local start_proxy=false
|
|
|
|
local cmd=$0
|
|
|
|
while [ $# -gt 0 ]; do
|
|
local arg=$1
|
|
case "$arg" in
|
|
"--config" | "-c")
|
|
local mode=$2
|
|
case "$mode" in
|
|
"proxy" | "bungee" | "standalone")
|
|
;;
|
|
case *)
|
|
err "Invalid mode for --config: $mode"
|
|
;;
|
|
esac
|
|
config=$mode
|
|
if $proxy; then
|
|
err "--config can't be used together with --proxy"
|
|
elif $bungee; then
|
|
err "--config can't be used together with --bungee"
|
|
fi
|
|
shift 2
|
|
;;
|
|
"--sleep" | "-s")
|
|
sleep_seconds=$2
|
|
shift 2
|
|
;;
|
|
"--proxy")
|
|
proxy=true
|
|
if $bungee; then
|
|
err "--proxy can't be used together with --bungee"
|
|
elif [[ -n $config ]]; then
|
|
err "--proxy can't be used together with --config"
|
|
fi
|
|
shift
|
|
;;
|
|
"--bungee")
|
|
bungee=true
|
|
if $proxy; then
|
|
err "--bungee can't be used together with --proxy"
|
|
elif [[ -n $config ]]; then
|
|
err "--bungee can't be used together with --config"
|
|
fi
|
|
shift
|
|
;;
|
|
"--help" | "-h")
|
|
help=true
|
|
shift
|
|
;;
|
|
*)
|
|
err "Unknown argument: $arg"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if $help; then
|
|
echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy"
|
|
echo ""
|
|
echo "Usage $cmd [OPTIONS]"
|
|
echo ""
|
|
echo "OPTIONS:"
|
|
echo " -c --config <mode> How to configure the server. Possible values for mode are: proxy, bungee, standalone"
|
|
echo " -s --sleep <secs> How many seconds to sleep after the server has stopped before starting it again"
|
|
echo " -h --help Show help"
|
|
echo " --proxy Start the server behind a velocity proxy"
|
|
echo " --bungee Start the server behind a bungeecord proxy"
|
|
exit
|
|
fi
|
|
|
|
# TODO perform configuration according to config parameter
|
|
|
|
if $proxy; then
|
|
./configure.sh velocity
|
|
|
|
# create proxy screen if it doesn't exist yet
|
|
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
|
|
# start the proxy
|
|
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/proxy; ./launch.sh\n"
|
|
|
|
echo "The velocity proxy has been started in the screen '$PROXY_SCREEN'"
|
|
elif $bungee; then
|
|
./configure.sh bungeecord
|
|
|
|
# create proxy screen if it doesn't exist yet
|
|
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
|
|
# start the proxy
|
|
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/bungee; ./launch.sh\n"
|
|
|
|
echo "The bungeecord proxy has been started in the screen '$PROXY_SCREEN'"
|
|
else
|
|
./configure.sh standalone
|
|
fi
|
|
|
|
trap cleanup SIGINT
|
|
|
|
cleanup() {
|
|
if $proxy || $bungee; then
|
|
# stop the proxy
|
|
screen -S "$PROXY_SCREEN" -X stuff "end\n"
|
|
echo "The proxy has been stopped"
|
|
fi
|
|
|
|
exit
|
|
}
|
|
|
|
while true
|
|
do
|
|
echo starting server...
|
|
./launch.sh
|
|
echo sleeping...
|
|
sleep "$sleep_seconds"
|
|
done
|
|
}
|
|
|
|
# Shows ans error message and exits the program with code 1
|
|
#
|
|
# Usage: err <msg>
|
|
function err {
|
|
echo "$1"
|
|
exit 1
|
|
}
|
|
|
|
main "$@"
|
|
|
|
|
|
|
|
|