-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_manager.sh
executable file
·66 lines (42 loc) · 956 Bytes
/
run_manager.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
#!/bin/sh
FILE=/services/leader_file.txt
function start_dht_to_mqtt() {
echo "Starting DHT-TO-MQTT ..."
/dht-to-mqtt &
}
function stop_dht_to_mqtt() {
cont=0
while pgrep -f /dht-to-mqtt > /dev/null 2>&1; do
force=""
if [ $cont -gt 9 ]; then
echo "Forcing kill /dht-to-mqtt "
force="-9"
fi
ppid=$(ps | grep dht-to-mqtt | awk '{print $1}' | head -n 1)
kill $force $ppid
if [ $? -eq 0 ]; then # il processo esisteva ed è stato killato
echo "Killed dht-to-mqtt "
fi
echo "Waiting for dht-to-mqtt death ..."
sleep 1
cont=$((cont+1))
done
}
function check() {
if [[ -f $FILE ]] ; then
# il file esiste
if ! pgrep -f /dht-to-mqtt > /dev/null 2>&1 ; then
start_dht_to_mqtt
fi
else
# il file non esiste
stop_dht_to_mqtt
fi
}
trap "echo 'Ricevuto Signal SIGUSR1'; check" SIGUSR1
while true;
do
check
sleep 5 &
wait $!
done