From 61cb39b414b0beadebb7a0f748efc1cf7201c7d3 Mon Sep 17 00:00:00 2001 From: Leonard Steppy Date: Wed, 24 Dec 2025 18:56:39 +0100 Subject: [PATCH] Add sleep parameter to start.sh --- configure.sh | 8 +-- start.sh | 172 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 104 insertions(+), 76 deletions(-) diff --git a/configure.sh b/configure.sh index f28be87..b304190 100755 --- a/configure.sh +++ b/configure.sh @@ -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 diff --git a/start.sh b/start.sh index d085e84..faf42bc 100755 --- a/start.sh +++ b/start.sh @@ -1,86 +1,114 @@ #!/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 - 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 + local cmd=$0 -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 "--proxy Start the server behind a velocity proxy" - echo "--bungee Start the server behind a bungeecord proxy" - exit -fi + while [ $# -gt 0 ]; do + local arg=$1 + case "$arg" in + "--sleep" | "-s") + sleep_seconds=$2 + shift 2 + ;; + "--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 - ./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" + 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 " -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 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 -do - echo starting server... - ./launch.sh - echo sleeping... - sleep 3 -done +# Shows ans error message and exits the program with code 1 +# +# Usage: err +function err { + echo "$1" + exit 1 +} + +main "$@"