Created
February 26, 2020 16:45
-
-
Save klondikemarlen/c5a22b3ee89de2161a0f9da5db27beff to your computer and use it in GitHub Desktop.
Local file watcher to restart docker container.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
restart_app () { | |
local app_name="$1" | |
# consider pinging the server an only sending this if it is alive? | |
docker kill --signal="SIGUSR1" "$app_name" &> /dev/null | |
} | |
# Note: using -qq option with inotify will kill all events. So don't do that :p | |
app_restart_watcher () { | |
local app_name="$1" | |
local dir_to_watch="$2" | |
local pid_file="$3" | |
mkdir -p "$(dirname "$pid_file")" | |
(echo "$BASHPID" > "$pid_file"; \ | |
exec inotifywait -q --monitor --recursive --event modify "$dir_to_watch") | \ | |
while read event; do | |
# echo "read event" "$event" | |
# echo 'Trying to restart the app ...' | |
restart_app "$app_name" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Require some watcher for the
SIGUSR1
signal.E.g.