forked from coppit/docker-inotify-command
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.sh
executable file
·57 lines (44 loc) · 1.18 KB
/
monitor.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
#!/bin/bash
function ts {
echo [`date '+%Y-%m-%d %H:%M:%S'`] MASTER:
}
echo "$(ts) Starting master controller"
if [ -f /config/sample.conf ]; then
echo "$(ts) /config/sample.conf exists. Rename it, check the settings, then rerun the container. Exiting."
exit 1
fi
readarray -t CONFIG_FILES < <(ls /config/*.conf)
# If there is no config file copy the default one
if [[ "$CONFIG_FILES" == "" ]]
then
echo "$(ts) Creating sample config file. Rename it, check the settings, then rerun the container. Exiting."
cp /files/sample.conf /config/sample.conf
chmod a+w /config/sample.conf
exit 1
fi
PIDS=()
for CONFIG_FILE in "${CONFIG_FILES[@]}"
do
echo "$(ts) Launching monitor for $CONFIG_FILE"
/files/monitor.py $CONFIG_FILE &
PIDS+=($!)
done
# Sleep for a second to allow the monitors to check their config files
sleep 1
while true
do
for ((i = 0; i < ${#PIDS[@]}; i++))
do
if ps -p ${PIDS[$i]} > /dev/null
then
continue
fi
echo "$(ts) Monitor for ${CONFIG_FILES[$i]} has died (PID ${PIDS[$i]}). Killing other monitors and exiting."
for PID in "${PIDS[@]}"
do
kill -9 $PID >/dev/null 2>&1
done
exit 2
done
sleep 60
done