minecraft-bash-scripts/proxy/start.sh
2025-12-25 23:09:37 +01:00

68 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# How many seconds to sleep before starting the server again, unless it is explicitly specified
DEFAULT_SLEEP_SECONDS=3
function show_help {
local cmd=$0
echo "Create a start loop for the proxy server and optionally start a number of paper servers with it"
echo ""
echo "Usage: $cmd [OPTIONS]"
echo ""
echo "OPTIONS:"
echo " -s --sleep <secs> How many seconds to sleep after stopping the server"
# TODO options for paper servers
echo " -h --help Show this messasge"
exit
}
function main {
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
local help=false
# Parse arguments
local cmd=$0
while [[ $# -gt 0 ]]; do
local arg=$1
case "$arg" in
"--sleep" | "-s")
sleep_seconds=$2
shift 2
;;
"--help" | "-h")
help=true
shift
;;
*)
err "Unknown argument: $arg"
;;
esac
done
if $help; then
show_help "$cmd"
fi
while true
do
echo "Starting proxy..."
./launch.sh
echo "Sleeping for $sleep_seconds seconds..."
sleep "$sleep_seconds"
done
}
# Shows an error message and exits the program with code 1
#
# Usage: err <msg>
function err {
echo "$1"
exit 1
}
main "$@"