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

172
start.sh
View File

@ -1,86 +1,114 @@
#!/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
case "$arg" in
"--proxy")
proxy=true
if $bungee; then
echo "--proxy can't be used together with --bungee"
exit 1
fi
;;
"--bungee")
bungee=true
if $proxy; then
echo "--bungee can't be used together with --proxy"
exit 1
fi
;;
"--help")
help=true
;;
*)
echo "Unknown argument. Use --help to see all options"
exit 1
;;
esac
done
if $help; then while [ $# -gt 0 ]; do
echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy" local arg=$1
echo "--help Show help" case "$arg" in
echo "--proxy Start the server behind a velocity proxy" "--sleep" | "-s")
echo "--bungee Start the server behind a bungeecord proxy" sleep_seconds=$2
exit shift 2
fi ;;
"--proxy")
proxy=true
if $bungee; then
err "--proxy can't be used together with --bungee"
fi
shift
;;
"--bungee")
bungee=true
if $proxy; then
err "--bungee can't be used together with --proxy"
fi
shift
;;
"--help" | "-h")
help=true
shift
;;
*)
err "Unknown argument: $arg"
;;
esac
done
if $proxy; then if $help; then
./configure.sh velocity echo "Create a start loop for the minecraft server, additionally behind a velocity proxy or bungeecord proxy"
echo ""
# create proxy screen if it doesn't exist yet echo "Usage $cmd [OPTIONS]"
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN" echo ""
# start the proxy echo "OPTIONS:"
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/proxy; ./launch.sh\n" echo " -s --sleep How many seconds to sleep after the server has stopped before starting it again"
echo " -h --help Show help"
echo "The velocity proxy has been started in the screen '$PROXY_SCREEN'" echo " --proxy Start the server behind a velocity proxy"
elif $bungee; then echo " --bungee Start the server behind a bungeecord proxy"
./configure.sh bungeecord exit
# 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 fi
exit 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
} }
while true # Shows ans error message and exits the program with code 1
do #
echo starting server... # Usage: err <msg>
./launch.sh function err {
echo sleeping... echo "$1"
sleep 3 exit 1
done }
main "$@"