feat(Bash/restarter): add restarter to the available bin/ collection (#3991)

This commit is contained in:
Francesco Borzì
2020-12-15 12:59:18 +01:00
committed by GitHub
parent 7eb1720d3b
commit ab72d3ce91
2 changed files with 20 additions and 11 deletions

View File

@@ -6,16 +6,20 @@
_bin_path=$1 _bin_path=$1
_bin_file=$2 _bin_file=$2
_instant_crash_cnt=0 _instant_crash_count=0
_total_crashes=0 _restart_count=0
trap 'echo "va bene"' SIGHUP if [ "$#" -ne 2 ]; then
echo "Usage: simple-restarter path filename"
echo "Example: simple-restarter $HOME/azeroth-server/bin worldserver"
exit 1
fi
while true while true
do do
if [ ! -f "$_bin_path/$_bin_file" ]; then if [ ! -f "$_bin_path/$_bin_file" ]; then
echo "$_bin_path/$_bin_file doesn't exists!" echo "$_bin_path/$_bin_file doesn't exists!"
exit 0 exit 1
fi fi
STARTING_TIME=$(date +%s) STARTING_TIME=$(date +%s)
@@ -31,23 +35,23 @@ do
# exit 0 # exit 0
#fi #fi
echo "$_bin_file crashed (?), restarting..." echo "$_bin_file terminated, restarting..."
ENDING_TIME=$(date +%s) ENDING_TIME=$(date +%s)
DIFFERENCE=$(( $ENDING_TIME - $STARTING_TIME )) DIFFERENCE=$(( $ENDING_TIME - $STARTING_TIME ))
((_total_crashes++)) ((_restart_count++))
echo "$_bin_file Crashed after $DIFFERENCE seconds, total crashes: $_total_crashes" echo "$_bin_file Terminated after $DIFFERENCE seconds, termination count: : $_restart_count"
if [ $DIFFERENCE -lt 10 ]; then if [ $DIFFERENCE -lt 10 ]; then
# increment instant crash if runtime is lower than 10 seconds # increment instant crash if runtime is lower than 10 seconds
((_instant_crash_cnt++)) ((_instant_crash_count++))
else else
_instant_crash_cnt=0 # reset count _instant_crash_count=0 # reset count
fi fi
if [ $_instant_crash_cnt -gt 5 ]; then if [ $_instant_crash_count -gt 5 ]; then
echo "$_bin_file Restarter exited. Infinite crash loop prevented. Please check your system" echo "$_bin_file Restarter exited. Infinite crash loop prevented. Please check your system"
exit 0 exit 1
fi fi
done done

5
bin/acore-restarter Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
CUR_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CUR_PATH/../apps/startup-scripts/simple-restarter"