aboutsummaryrefslogtreecommitdiffstats
path: root/monitor.sh
blob: e3bc9d4cf325d94b2043d16cc4e64624e50b2320 (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
#!/bin/bash

set -exo pipefail

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;

if [ -n "$WATCH_EVENTS" ]; then
  ADDITIONAL_ARGS="-e $WATCH_EVENTS"
else
  ADDITIONAL_ARGS=""
fi

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