Last active
December 11, 2017 18:52
-
-
Save cedmundo/54a39c29bdf238ac11f5ce60799e9311 to your computer and use it in GitHub Desktop.
Example of building on demand for a project in Go
This file contains hidden or 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 | |
function killpidfile { | |
echo "Killing process" | |
if [ -f ".debug.pid" ]; then | |
kill -15 $(cat .debug.pid) | |
fi | |
} | |
function build { | |
echo "Rebuilding app" | |
source $UBI_ENV_CONFIG_DEBUG | |
echo "================ BUILDING ================" >> .debug.log | |
make debug >> .debug.log 2>&1 | |
} | |
function run { | |
echo "Starting service" | |
echo "================ RESTART ================" >> .debug.log | |
nohup bin/debug/ubiserver >> .debug.log 2>&1 & | |
echo $! > .debug.pid | |
} | |
# Check debug variables | |
# if [ -z $UBI_ENV_CONFIG_DEBUG ]; then | |
# echo "No UBI_ENV_CONFIG_DEBUG variable defined" | |
# exit | |
#fi | |
# Check if process already exists | |
if [ -f ".debug.pid" ]; then | |
PID=$(cat .debug.pid) | |
if !kill -0 $PID 2>/dev/null; then | |
kill -15 $PID | |
fi | |
rm .debug.pid | |
fi | |
# Build & run before entering the inotifywait cycle | |
build && run | |
# Restart everytime someone do changes | |
while true; do | |
inotifywait -e close_write,moved_to,create -r . | | |
while read -r directory events filename; do | |
echo "Changes on $filename" | |
ext=${filename##*.} | |
if [ $ext = 'go' ] | |
then | |
killpidfile | |
build && run | |
echo "Ready" | |
break | |
else | |
echo "Not a go file, ignoring" | |
fi | |
done; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment