From 5c0fc1fc767b7b447d787d8123b23e99a35b8577 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 10 Aug 2016 01:01:34 +0300 Subject: add herculeswrapper. For now this is basic wrapper. Allow: terminate all servers restart all servers restart char and map servers restart map server --- herculeswrapper/char.sh | 7 +++++++ herculeswrapper/include.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ herculeswrapper/login.sh | 7 +++++++ herculeswrapper/map.sh | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100755 herculeswrapper/char.sh create mode 100644 herculeswrapper/include.sh create mode 100755 herculeswrapper/login.sh create mode 100755 herculeswrapper/map.sh diff --git a/herculeswrapper/char.sh b/herculeswrapper/char.sh new file mode 100755 index 0000000..cdca266 --- /dev/null +++ b/herculeswrapper/char.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export PIPE=./log/charpipe.tmp + +source ${dir}/include.sh + +server_logic ./char-server 2s diff --git a/herculeswrapper/include.sh b/herculeswrapper/include.sh new file mode 100644 index 0000000..fe0c276 --- /dev/null +++ b/herculeswrapper/include.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function create_pipe { + trap "rm -f $PIPE" EXIT + if [[ ! -p $PIPE ]]; then + echo "Making pipe $PIPE" + rm -f $PIPE + mkfifo $PIPE + fi +} + +# $1 - text +function send_all_pipes { + echo $1 >$LOGIN_PIPE + echo $1 >$CHAR_PIPE +} + +# $1 - text +function send_char_pipe { + echo $1 >$CHAR_PIPE +} + +# $1 - server binary name +# $2 - sleep time +function server_logic { + create_pipe + $1 + + while true + do + if read line <$PIPE; then + echo pipe: $line + if [[ "$line" == 'exit' ]]; then + exit + fi + if [[ "$line" == 'restart' ]]; then + sleep $2 + $1 + fi + fi + done +} diff --git a/herculeswrapper/login.sh b/herculeswrapper/login.sh new file mode 100755 index 0000000..ae67bf8 --- /dev/null +++ b/herculeswrapper/login.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +export PIPE=./log/loginpipe.tmp + +source ${dir}/include.sh + +server_logic ./login-server 0s diff --git a/herculeswrapper/map.sh b/herculeswrapper/map.sh new file mode 100755 index 0000000..ed2a1bd --- /dev/null +++ b/herculeswrapper/map.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +export PIPE=./log/mappipe.tmp +export LOGIN_PIPE=./log/loginpipe.tmp +export CHAR_PIPE=./log/charpipe.tmp + +source ${dir}/include.sh + +create_pipe + +while [ 1 ] ; do + ./map-server + export ret=$? + case "${ret}" in + 0) + echo "Returned 0. Probably ctrl+c" + break + ;; + 100) + echo "Terminating server" + send_all_pipes "exit" + break + ;; + 101) + echo "Restarting all servers..." + send_all_pipes "restart" + sleep 5s + ;; + 102) + echo "Restarting chat and map servers..." + send_char_pipe "restart" + sleep 3s + ;; + 103) + echo "Restarting map server..." + ;; + esac +done -- cgit v1.2.3-70-g09d2