-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathspawn.sh
More file actions
51 lines (40 loc) · 837 Bytes
/
spawn.sh
File metadata and controls
51 lines (40 loc) · 837 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
control_port=3100
respawn() {
while true
do
echo start
$@ || true
echo done!
done
}
stop() {
kill $process
}
key=$1
num=$2
if [ -z "$num" ] ;then
num=4
fi
process=""
if [ -z "$key" ] ; then
echo "No key given" >> /dev/stderr
exit 1;
fi
limit=$(cat /proc/cpuinfo | grep -E '^processor' | wc -l)
for x in $(seq 1 $num)
do
cpu=$[ ($x - 1) % $limit ]
port=$[ $control_port + $x ]
respawn taskset --cpu-list $cpu node index.js --agent --tcp --bind :$port --connect_key $key --only_known --ca_path CACertificates.p7b &
process="$process $!"
done
respawn node index.js --proxy --bind :$control_port --ports $[ $control_port + 1 ]:$[ $control_port + $num ] --connect_key $key &
process="$process $!"
trap stop USR1
trap stop USR2
trap stop INT
for pid in $process
do
wait $pid
done