forked from rusdacent/docker-inotify-command
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path60_create_monitors.sh
executable file
·42 lines (30 loc) · 988 Bytes
/
60_create_monitors.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
#!/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 to <monitor name>.conf, 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 to <monitor name>.conf, check the settings, then rerun the container. Exiting."
cp /files/sample.conf /config/sample.conf
chmod a+w /config/sample.conf
exit 1
fi
for CONFIG_FILE in "${CONFIG_FILES[@]}"
do
FILENAME=$(basename "$CONFIG_FILE")
echo "$(ts) Creating monitor for $FILENAME"
FILEBASE="${FILENAME%.*}"
mkdir -p /etc/service/$FILEBASE
cat > /etc/service/$FILEBASE/run <<EOF
#!/bin/bash
/files/monitor.py "$CONFIG_FILE"
EOF
chmod a+x /etc/service/$FILEBASE/run
done