From: Christian Heller Date: Sun, 8 Mar 2015 16:02:16 +0000 (+0100) Subject: Server/py: Add startup wrappers supporting Python variant. X-Git-Tag: tce~367 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7B%20deck_id%20%7D%7D/cards?a=commitdiff_plain;h=225927eddf3c5b50d1dc6d30e87031bf93a7bac5;p=plomrogue Server/py: Add startup wrappers supporting Python variant. --- diff --git a/roguelike_python b/roguelike_python new file mode 100755 index 0000000..b002721 --- /dev/null +++ b/roguelike_python @@ -0,0 +1,12 @@ +#!/bin/sh + +# Wrapper to the script so that its suppressed server messages get read on exit. +./start_server_client_union.sh "$@" + +# For some reason, mere sync won't ensure a log is written out, so wait a while. +sync +sleep 0.5 +if [ -e ./log ] +then + cat log +fi diff --git a/start_server_python_client_union.sh b/start_server_python_client_union.sh new file mode 100755 index 0000000..5894947 --- /dev/null +++ b/start_server_python_client_union.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# Abort the script on error. +set -e + +# Don't let any log leftovers from before interfere. +if [ -e ./log ] +then + rm log +fi + +# Give helpful message to players that want to start without compiling first. +if [ ! -e ./roguelike-client ] +then + echo 'No ./roguelike-client file found to execute. Try "./redo" first?' + false +fi + +# Use shell script's arguments for server and pipe server output to log file. +# This script's wrapper script will read it out on exit. +python3 ./plomrogue-server.py "$@" > log 2>&1 & + +# Give server some time to start up and exit on error. +sleep 0.01 + +# The client should not start if the server is not running. (If the server was +# running in the foreground, any error exit of it so far would be caught by "set +# -e" above. But "set -e" is blind to error codes generated in the background.) +kill -0 $! 2> /dev/null + +# Give server some time (max. 10 seconds) to generate its worldstate file. +i=0 +while [ ! -e server/worldstate ] && [ $i -le 1000 ] +do + sleep 0.01 + i=`expr $i + 1` +done +if [ ! -e server/worldstate ] +then + echo "Server failed generating worldstate file within given time limit." + false +fi + +# Only start the interface when everything else went well. +kill -0 $! 2> /dev/null +./roguelike-client