From 94ab55b6ab9ae71484c3cca2481704d454322d37 Mon Sep 17 00:00:00 2001 From: Leonard Steppy Date: Thu, 25 Dec 2025 23:09:37 +0100 Subject: [PATCH] Add sleep and help options to proxy start script --- proxy/start.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++----- start.sh | 8 +++--- 2 files changed, 70 insertions(+), 10 deletions(-) diff --git a/proxy/start.sh b/proxy/start.sh index 07b8c4e..a008eab 100755 --- a/proxy/start.sh +++ b/proxy/start.sh @@ -1,7 +1,67 @@ #!/usr/bin/env bash -while true -do - ./launch.sh - echo sleeping... - sleep 3 -done + +# 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 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 +function err { + echo "$1" + exit 1 +} + +main "$@" + diff --git a/start.sh b/start.sh index 89b8047..5fdfe8d 100755 --- a/start.sh +++ b/start.sh @@ -40,7 +40,7 @@ function main { local cmd=$0 # Parse arguments - while [ $# -gt 0 ]; do + while [[ $# -gt 0 ]]; do local arg=$1 case "$arg" in "--config" | "-c") @@ -118,7 +118,7 @@ function main { fi if $help; then - show_help $cmd + show_help "$cmd" fi # Apply configuration @@ -163,9 +163,9 @@ function main { while true do - echo starting server... + echo "Starting server..." ./launch.sh - echo sleeping... + echo "Sleeping for $sleep_seconds seconds..." sleep "$sleep_seconds" done }