From 09051773461b98d374d1b46dd0a2caa57768ab30 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Thu, 15 Jun 2017 22:38:53 -0400 Subject: add sbt-resolver like restart feature --- cbt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'cbt') diff --git a/cbt b/cbt index 4a5b736..e2014ec 100755 --- a/cbt +++ b/cbt @@ -290,6 +290,7 @@ stage1 () { USER_PRESSED_CTRL_C=130 CBT_LOOP_FILE="$CWD/target/.cbt-loop.tmp" +CBT_KILL_FILE="$CWD/target/.cbt-kill.tmp" if [ $loop -eq 0 ]; then which fswatch >/dev/null 2>/dev/null export fswatch_installed=$? @@ -305,6 +306,9 @@ while true; do if [ -f "$CBT_LOOP_FILE" ]; then rm "$CBT_LOOP_FILE" fi + if [ -f "$CBT_KILL_FILE" ]; then + rm "$CBT_KILL_FILE" + fi stage1 "$@" if [ ! $loop -eq 0 ] || [ $exitCode -eq $USER_PRESSED_CTRL_C ]; then log "not looping, exiting" "$@" @@ -316,6 +320,10 @@ while true; do files= if [ -f "$CBT_LOOP_FILE" ]; then files=($(sort "$CBT_LOOP_FILE")) + fi + pids= + if [ -f "$CBT_KILL_FILE" ]; then + pids=($(cat "$CBT_KILL_FILE")) # FIXME: should we uniq here? #rm "$CBT_LOOP_FILE" fi echo "" @@ -326,6 +334,14 @@ while true; do fi done fswatch --one-event "${files[@]}" + for pid in "${pids[@]}"; do + if [ $pid == "" ]; then + echo "warning: empty pid found in pid kill list" 1>&2 + else + log "killing process $pid" + kill -KILL $pid + fi + done fi done -- cgit v1.2.3