forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch-node
More file actions
executable file
·32 lines (26 loc) · 808 Bytes
/
watch-node
File metadata and controls
executable file
·32 lines (26 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
trap ctrl_c INT TERM KILL
function ctrl_c() { kill -KILL $pid $$; }
path=$@
watchfolder=$(dirname $1)
command="node $path"
# echo
# echo if you want to understand what this script is doing, un-comment the line below.
# echo [watch-node $$] running $command and daemonizing, watching folder $watchfolder every 2 secs.
# echo
$command &
pid=$!
while [[ true ]]; do
files=$(find -L $watchfolder -type f -newermt '2 seconds ago' | grep -v "\.test\." | grep -v "models\.json")
if [[ $files != "" ]]; then
echo [watch-node $$] files changed [$files] killing $pid $command
kill -KILL $pid >/dev/null
echo [watch-node $$] new pid is $pid
fi
if ! (ps -p $pid >/dev/null); then
$command &
pid=$!
echo "[watch-node $$] process (re)started new pid $pid cmd: $command"
fi
sleep 2
done