forked from waves-exchange/neutrino-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-wrap.sh
executable file
·70 lines (54 loc) · 1.43 KB
/
server-wrap.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# !/bin/bash
# Globals
args=?;
command=?; # - run script from package.json. Only command or script_name should be provided but not both
script_name=?;
restart_timeout=1 # in seconds
current_pid=?;
serve_no_update_pid=?;
function run_with_restarts {
if [ $command != "?" ]
then
npm run $command &
current_pid=$!;
npm run serve-and-update &
serve_no_update_pid=$!;
echo "PID is $current_pid; serve_no_update_pid is $serve_no_update_pid;"
elif [ $script_name != "?" ]
then
$("node $script_name $args")
fi
echo "Restart timeout cycle is $restart_timeout seconds"
sleep $restart_timeout;
kill -9 $current_pid;
kill -9 $serve_no_update_pid;
echo 'Restart app in 10 seconds...'
sleep 10;
run_with_restarts $@;
}
function parse_time {
local tm=$1;
local amount=$(echo $tm | sed 's/[^0-9]//');
local unit=$(echo $tm | awk '{ split($0,a,""); print a[length(a)] }');
local res=7200;
case "$unit" in
m) res=$(echo "60 * $amount" | bc) ;;
h) res=$(echo "60 * 60 * $amount" | bc) ;;
s) res=$amount ;;
esac
echo $res;
}
function main {
args=$@;
while [ -n "$1" ]
do
case "$1" in
--script) script_name=$2 ;;
--timeout) restart_timeout=$(parse_time $2) ;;
--command) command=$2 ;;
esac
shift
done
run_with_restarts $script_name;
}
main $@