Add option to dynamically configure paper servers in proxy start script
This commit is contained in:
parent
deca0a4a48
commit
b27ddb2c63
@ -3,27 +3,48 @@
|
|||||||
# How many seconds to sleep before starting the server again, unless it is explicitly specified
|
# How many seconds to sleep before starting the server again, unless it is explicitly specified
|
||||||
DEFAULT_SLEEP_SECONDS=3
|
DEFAULT_SLEEP_SECONDS=3
|
||||||
|
|
||||||
|
declare -A DEV
|
||||||
|
DEV[option]="dev"
|
||||||
|
DEV[screen]="steptech"
|
||||||
|
DEV[dir]=".."
|
||||||
|
|
||||||
|
# Which paper servers can be started with this script
|
||||||
|
SERVERS=( DEV )
|
||||||
|
|
||||||
|
# Which configuration to apply to the paper servers
|
||||||
|
CONFIG="proxy" # Velocity
|
||||||
|
|
||||||
function show_help {
|
function show_help {
|
||||||
local cmd=$0
|
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 "Create a start loop for the proxy server and optionally start a number of paper servers with it"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Usage: $cmd [OPTIONS]"
|
echo "Usage: $cmd [OPTIONS]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "OPTIONS:"
|
echo "OPTIONS:"
|
||||||
echo " -s --sleep <secs> How many seconds to sleep after stopping the server"
|
{
|
||||||
# TODO show server options
|
local fmt=" %s\t%s\t%s\n"
|
||||||
echo " -h --help Show this message"
|
|
||||||
|
printf "$fmt" "-s" "--sleep" "How many seconds to sleep after stopping the server"
|
||||||
|
printf "$fmt" "-n" "--no-loop" "Don't restart the proxy server once it stopped"
|
||||||
|
|
||||||
|
for server_name in "${SERVERS[@]}"; do
|
||||||
|
declare -n server="$server_name"
|
||||||
|
printf "$fmt" "" "--${server[option]}" "Start the ${server[screen]} server (${server[dir]})"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "$fmt" "-h" "--help" "Show this message"
|
||||||
|
} | column -t -s $'\t'
|
||||||
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
function main {
|
function main {
|
||||||
# TODO create servers
|
|
||||||
|
|
||||||
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
|
local sleep_seconds=$DEFAULT_SLEEP_SECONDS
|
||||||
local help=false
|
local help=false
|
||||||
|
local loop=true
|
||||||
|
local servers=()
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
local cmd=$0
|
local cmd=$0
|
||||||
@ -34,12 +55,28 @@ function main {
|
|||||||
sleep_seconds=$2
|
sleep_seconds=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
"--no-loop" | "-n")
|
||||||
|
loop=false
|
||||||
|
shift
|
||||||
|
;;
|
||||||
"--help" | "-h")
|
"--help" | "-h")
|
||||||
help=true
|
help=true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
err "Unknown argument: $arg"
|
local option_found=false
|
||||||
|
for server_name in "${SERVERS[@]}"; do
|
||||||
|
declare -n server="$server_name"
|
||||||
|
if [ "$arg" = "--${server[option]}" ]; then
|
||||||
|
servers+=("$server_name")
|
||||||
|
option_found=true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! $option_found; then
|
||||||
|
err "Unknown argument: $arg"
|
||||||
|
fi
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@ -48,13 +85,41 @@ function main {
|
|||||||
show_help "$cmd"
|
show_help "$cmd"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while true
|
# Start servers
|
||||||
do
|
for server_name in "${servers[@]}"; do
|
||||||
|
declare -n server="$server_name"
|
||||||
|
# Create server screen if it doesn't exist yet
|
||||||
|
local screen="${server[screen]}"
|
||||||
|
screen -ls | grep -q "$screen" || screen -dmS "$screen"
|
||||||
|
# Start the server
|
||||||
|
screen -S "$screen" -X stuff "cd $(pwd)/${server[dir]}; ./start.sh --no-loop --config \"$CONFIG\" --tmp\n"
|
||||||
|
echo "Started paper server in screen $screen"
|
||||||
|
done
|
||||||
|
|
||||||
|
function cleanup {
|
||||||
|
for server_name in "${servers[@]}"; do
|
||||||
|
declare -n server="$server_name"
|
||||||
|
local screen="${server[screen]}"
|
||||||
|
screen -S "$screen" -X stuff "stop\n"
|
||||||
|
echo "Stopped paper server in screen $screen"
|
||||||
|
done
|
||||||
|
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup SIGINT
|
||||||
|
|
||||||
|
while :; do
|
||||||
echo "Starting proxy..."
|
echo "Starting proxy..."
|
||||||
./launch.sh
|
./launch.sh
|
||||||
|
|
||||||
|
$loop || break
|
||||||
|
|
||||||
echo "Sleeping for $sleep_seconds seconds..."
|
echo "Sleeping for $sleep_seconds seconds..."
|
||||||
sleep "$sleep_seconds"
|
sleep "$sleep_seconds"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
# Shows an error message and exits the program with code 1
|
# Shows an error message and exits the program with code 1
|
||||||
|
|||||||
35
start.sh
35
start.sh
@ -18,12 +18,18 @@ function show_help {
|
|||||||
echo "Usage $cmd [OPTIONS]"
|
echo "Usage $cmd [OPTIONS]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "OPTIONS:"
|
echo "OPTIONS:"
|
||||||
echo " -c --config <mode> How to configure the server (see ./configure.sh --help). Possible values for mode are: proxy, bungee, standalone"
|
{
|
||||||
echo " -t --temp --tmp Apply the configuration only temporary, while the server is running. Requires --config."
|
local fmt=" %s\t%s\t%s\n"
|
||||||
echo " -s --sleep <secs> How many seconds to sleep after the server has stopped before starting it again"
|
|
||||||
echo " -h --help Show help"
|
printf "$fmt" "-c" "--config <mode>" "How to configure the server (see ./configure.sh --help). Possible values for mode are: proxy, bungee, standalone"
|
||||||
echo " --proxy Start the server behind a velocity proxy"
|
printf "$fmt" "-t" "--temp" "Apply the configuration only temporary, while the server is running. Requires --config."
|
||||||
echo " --bungee Start the server behind a bungeecord proxy"
|
printf "$fmt" "" "--tmp" "Alias to --temp"
|
||||||
|
printf "$fmt" "-s" "--sleep <secs>" "How many seconds to sleep after the server has stopped before starting it again"
|
||||||
|
printf "$fmt" "-n" "--no-loop" "Don't restart the server once it stopped"
|
||||||
|
printf "$fmt" "-h" "--help" "Show this message"
|
||||||
|
printf "$fmt" "" "--proxy" "Temporary configure this server for use with Velocity and start a Velocity proxy in the screen $PROXY_SCREEN while this server is running"
|
||||||
|
printf "$fmt" "" "--bungee" "Temporary configure this server for use with Bungeecord and start a Bungeecord proxy in the screen $PROXY_SCREEN while this server is running"
|
||||||
|
} | column -t -s $'\t'
|
||||||
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
@ -36,6 +42,7 @@ function main {
|
|||||||
local config=""
|
local config=""
|
||||||
local start_proxy=false
|
local start_proxy=false
|
||||||
local tmp=false
|
local tmp=false
|
||||||
|
local loop=true
|
||||||
|
|
||||||
local cmd=$0
|
local cmd=$0
|
||||||
|
|
||||||
@ -75,6 +82,10 @@ function main {
|
|||||||
sleep_seconds=$2
|
sleep_seconds=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
"--no-loop" | "-n")
|
||||||
|
loop=false
|
||||||
|
shift
|
||||||
|
;;
|
||||||
"--proxy")
|
"--proxy")
|
||||||
proxy=true
|
proxy=true
|
||||||
if $bungee; then
|
if $bungee; then
|
||||||
@ -133,7 +144,7 @@ function main {
|
|||||||
# create proxy screen if it doesn't exist yet
|
# create proxy screen if it doesn't exist yet
|
||||||
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
|
screen -ls | grep -q "$PROXY_SCREEN" || screen -dmS "$PROXY_SCREEN"
|
||||||
# start the proxy
|
# start the proxy
|
||||||
local proxy_dir="$(pwd)/proxy"
|
local proxy_dir=""
|
||||||
case "$config" in
|
case "$config" in
|
||||||
"velocity")
|
"velocity")
|
||||||
proxy_dir=$VELOCITY_DIR
|
proxy_dir=$VELOCITY_DIR
|
||||||
@ -142,7 +153,7 @@ function main {
|
|||||||
proxy_dir=$BUNGEE_DIR
|
proxy_dir=$BUNGEE_DIR
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
screen -S "$PROXY_SCREEN" -X stuff "cd $proxy_dir; ./launch.sh\n"
|
screen -S "$PROXY_SCREEN" -X stuff "cd $(pwd)/$proxy_dir; ./launch.sh\n"
|
||||||
echo "The proxy has been started in screen $PROXY_SCREEN"
|
echo "The proxy has been started in screen $PROXY_SCREEN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -161,13 +172,17 @@ function main {
|
|||||||
|
|
||||||
trap cleanup SIGINT
|
trap cleanup SIGINT
|
||||||
|
|
||||||
while true
|
while :; do
|
||||||
do
|
|
||||||
echo "Starting server..."
|
echo "Starting server..."
|
||||||
./launch.sh
|
./launch.sh
|
||||||
|
|
||||||
|
$loop || break
|
||||||
|
|
||||||
echo "Sleeping for $sleep_seconds seconds..."
|
echo "Sleeping for $sleep_seconds seconds..."
|
||||||
sleep "$sleep_seconds"
|
sleep "$sleep_seconds"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
# Shows an error message and exits the program with code 1
|
# Shows an error message and exits the program with code 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user