Skip to content

Commit

Permalink
add both legacy and inotify filewatch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasz committed Jan 27, 2018
1 parent dfb9714 commit f121d87
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash


[[ -f .env ]] && source ./.env

FILE='src/index.py'
INIT="bash -c 'DAFUQ_IS_WORDNIK_API_KEY=${DAFUQ_IS_WORDNIK_API_KEY} exec -a dafuqis-backend python3 ${FILE} &'"
checksum=$(md5sum $FILE)

function boot
{
Expand All @@ -12,9 +14,11 @@ function boot
sleep 1
}

function listen
function inotify_watch
{

echo "$(date) - - Starting listening for changes...."

while inotifywait -q -r -e modify src/
do
clear
Expand All @@ -23,6 +27,36 @@ function listen
done
}

function legacy_watch
{
echo -e "Notice: inotifywait not found in your system.
- Using legacy method to restart
- Can restart only if change is detected in index.py.
- If you want to enjoy feature of restarting on any changes in the directory, then install inotifywait in your system.
$(date) - - Started listening for changes...."

while true
do
checksum_new=$(md5sum $FILE)
if [ "$checksum" != "$checksum_new" ]
then
checksum=$checksum_new
echo "$(date) - - Change detected in $FILE, restarting...."
boot
fi
sleep 1
done
}


function listen
{

#[[ `which inotifywait` ]] && inotify_watch || legacy_watch
legacy_watch
}

# Start script
boot

Expand Down

0 comments on commit f121d87

Please sign in to comment.