#!/bin/bash

# Note: This script runs /app/exe/* at startup, and then any files moved into /app/exe/
# (note - create files elsewhere and move them to avoid race conditions).
# This allows deployments to work from a different Docker container by simply pushing
# into a volume mounted in the correct place.
# Remove the old file from /app/exe/ before moving the new one.
# It doesn't kill off the old process, instead the new one kills the old one.

for EXE in /app/exe/*; do
    "$EXE"&
done

inotifywait --quiet --monitor -e moved_to --format "%f" /app/exe |\
    while read MOVED
    do
        "/app/exe/$MOVED"&
    done