aboutsummaryrefslogtreecommitdiffstats
path: root/monitor.sh
blob: 685e66e3a793a339201c6979b8962567770e29ab (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
#!/usr/bin/env sh

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;

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

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