-
Notifications
You must be signed in to change notification settings - Fork 0
/
stop_daq.sh
46 lines (41 loc) · 1.02 KB
/
stop_daq.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
#!/bin/bash
# Get Process PID
process_pid=$(</home/minlab/mtconnect-statusUpdate/metadata/daq_run.meta)
# Send the interrupt signal
kill -SIGINT "$process_pid"
# If process cannot be found
if [ $? -eq 0 ]; then
shutdown_state=0
else
shutdown_state=-1
fi
echo "Shutdown Initiated"
timer=0
termination_request=1
# Check for running process
ps -p "$process_pid" > /dev/null
while [ $? -eq 0 ]
do
sleep 1
timer=$((timer+1))
# If it is taking too long
if [ "$timer" -eq 100 ]; then
echo "Sending a 2nd Interrupt signal"
kill -SIGINT "$process_pid"
shutdown_state=-2
else
sleep 1
fi
# If it is taking way too long
if [ "$timer" -gt 200 ]; then
echo "Sending Termination signal, Count=$termination_request"
kill -SIGTERM "$process_pid"
termination_request=$((termination_request + 1))
shutdown_state=-3
else
sleep 2
fi
# Do a check
ps -p "$process_pid" > /dev/null
done
echo "Shutdown Complete"