#!/usr/bin/env bash # 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 # TODO accept list of servers as argument 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 show server options echo " -h --help Show this message" exit } function main { # TODO create servers 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 "$@"