forked from koding/koding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch-node
executable file
·37 lines (31 loc) · 1.01 KB
/
watch-node
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
33
34
35
36
37
#!/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
if [[ `uname` == "Darwin" ]]; then
files=`find -L $watchfolder -type f -mtime -2s | grep -v "\.test\." | grep -v "models\.json"`
else
files=`find -L $watchfolder -type f -mmin $(echo 2/60 | bc -l) | grep -v "\.test\." | grep -v "models\.json"`
fi
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