From 332eabfb70ea97c55cae315fd01b213adfc3f83c Mon Sep 17 00:00:00 2001 From: Gene Hoffman Date: Mon, 9 Mar 2020 13:43:42 -0700 Subject: [PATCH] Created restart_harvester.sh --- scripts/restart_harvester.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/restart_harvester.sh diff --git a/scripts/restart_harvester.sh b/scripts/restart_harvester.sh new file mode 100644 index 0000000000..15b4676527 --- /dev/null +++ b/scripts/restart_harvester.sh @@ -0,0 +1,31 @@ +echo "Shutting down harvesters" + +_kill_harvester_servers() { + PROCS=`ps -e | grep -E 'chia_harvester' | awk '!/grep/' | awk '{print $1}'` + if [ -n "$PROCS" ]; then + echo "$PROCS" | xargs -L1 kill + fi +} + +_kill_harvester_servers + +BG_PIDS="" +_run_bg_cmd() { + "$@" & + BG_PIDS="$BG_PIDS $!" +} + +echo "Restarting harvesters" + +_run_bg_cmd python -m src.server.start_harvester + +_term() { + echo "Caught TERM or INT signal, killing all servers." + for PID in $BG_PIDS; do + kill -TERM "$PID" + done + _kill_servers +} + +trap _term TERM +trap _term INT