Add sleep parameter to start.sh

This commit is contained in:
Leonard Steppy 2025-12-24 18:56:39 +01:00
parent b9e82b96e3
commit 61cb39b414
2 changed files with 104 additions and 76 deletions

View File

@ -61,7 +61,7 @@ function main {
"--quiet" | "-q") "--quiet" | "-q")
quiet=true quiet=true
;; ;;
"--help") "--help" | "-h")
help=true help=true
;; ;;
*) *)
@ -81,9 +81,9 @@ function main {
echo " standalone" echo " standalone"
echo "" echo ""
echo "OPTIONS:" echo "OPTIONS:"
echo " --fetch - print the current mode before reconfiguring the server. Nothing else will be printed." echo " --fetch Print the current mode before reconfiguring the server. Nothing else will be printed."
echo " --help - show this message" echo " -h --help Show this message"
echo " -q --quiet - Dont print any output, except for output which is caused by --fetch" echo " -q --quiet Don't print any output, except for output which is caused by --fetch"
exit 0 exit 0
fi fi

View File

@ -1,40 +1,57 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# THe name of the screen in which the proxy server will run
PROXY_SCREEN="proxy" PROXY_SCREEN="proxy"
# How many seconds to sleep before starting the server again, unless it is explicitly specified
DEFAULT_SLEEP_SECONDS=3
proxy=false function main {
bungee=false local proxy=false
help=false local bungee=false
local help=false
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
for arg in "$@"; do local cmd=$0
while [ $# -gt 0 ]; do
local arg=$1
case "$arg" in case "$arg" in
"--sleep" | "-s")
sleep_seconds=$2
shift 2
;;
"--proxy") "--proxy")
proxy=true proxy=true
if $bungee; then if $bungee; then
echo "--proxy can't be used together with --bungee" err "--proxy can't be used together with --bungee"
exit 1
fi fi
shift
;; ;;
"--bungee") "--bungee")
bungee=true bungee=true
if $proxy; then if $proxy; then
echo "--bungee can't be used together with --proxy" err "--bungee can't be used together with --proxy"
exit 1
fi fi
shift
;; ;;
"--help") "--help" | "-h")
help=true help=true
shift
;; ;;
*) *)
echo "Unknown argument. Use --help to see all options" err "Unknown argument: $arg"
exit 1
;; ;;
esac esac
done done
if $help; then if $help; then
echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy" echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy"
echo "--help Show help" echo ""
echo "Usage $cmd [OPTIONS]"
echo ""
echo "OPTIONS:"
echo " -s --sleep 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 " --proxy Start the server behind a velocity proxy"
echo " --bungee Start the server behind a bungeecord proxy" echo " --bungee Start the server behind a bungeecord proxy"
exit exit
@ -79,8 +96,19 @@ do
echo starting server... echo starting server...
./launch.sh ./launch.sh
echo sleeping... echo sleeping...
sleep 3 sleep "$sleep_seconds"
done done
}
# Shows ans error message and exits the program with code 1
#
# Usage: err <msg>
function err {
echo "$1"
exit 1
}
main "$@"