aboutsummaryrefslogtreecommitdiffstats
path: root/monitor.sh
blob: 9af6f1983409a4aed4bd466103abf759fef4648b (plain) (blame)
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
#!/usr/bin/env sh

if [ -z ${HOOK_SCRIPT+x} ]; then
    echo "Missing HOOK_SCRIPT environment variable, set it to the script to run upon file changes";
    exit 1;
else
    if ! test -f $HOOK_SCRIPT; then
        echo "The file pointed to by HOOK_SCRIPT does not exist, check your container mounts.";
        exit 1;
    fi;

    if ! test -x $HOOK_SCRIPT; then
        echo "HOOK_SCRIPT is not an executable file (missing +x bit), check file permissions of the hook script."
        exit 1;
    fi;
fi;

ADDITIONAL_ARGS=""

if [ -z ${WATCH_EVENTS+x} ]; then
    echo "Found watch events"
    ADDITIONAL_ARGS="-e $WATCH_EVENTS"
fi;

echo "Final command: inotifywait $ADDITIONAL_ARGS -r /opt/monitor"

while inotifywait $ADDITIONAL_ARGS -r /opt/monitor; do
    $HOOK_SCRIPT
done;