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

View File

@ -1,40 +1,57 @@
#!/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
proxy=false
bungee=false
help=false
function main {
local proxy=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
"--sleep" | "-s")
sleep_seconds=$2
shift 2
;;
"--proxy")
proxy=true
if $bungee; then
echo "--proxy can't be used together with --bungee"
exit 1
err "--proxy can't be used together with --bungee"
fi
shift
;;
"--bungee")
bungee=true
if $proxy; then
echo "--bungee can't be used together with --proxy"
exit 1
err "--bungee can't be used together with --proxy"
fi
shift
;;
"--help")
"--help" | "-h")
help=true
shift
;;
*)
echo "Unknown argument. Use --help to see all options"
exit 1
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 "--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 " --bungee Start the server behind a bungeecord proxy"
exit
@ -79,8 +96,19 @@ do
echo starting server...
./launch.sh
echo sleeping...
sleep 3
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 "$@"