Last active
July 19, 2023 08:41
-
-
Save fahadsiddiqui/33cd84f2ef46dc2ae614560a7b79df2e to your computer and use it in GitHub Desktop.
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 | |
set -ex | |
PWD=$(pwd) | |
mkfifo /tmp/servicelogs.pipe || echo "pipe already exists" | |
runningPIDs=() | |
exitfn () { | |
#trap SIGINT # Restore signal handling for SIGINT | |
echo; echo 'Stopping services' | |
for theId in ${runningPIDs[@]}; do | |
echo "killing ${theId}" | |
kill "$theId" || echo "no such process maybe" | |
done | |
exit # then exit script. | |
} | |
trap "exitfn" INT | |
SERVICE_PREFIX="service-" | |
declare -a arr=("multiple" "folders" "to" "watch" "logs" "from") | |
for i in "${arr[@]}" | |
do | |
if [ -z $SERVICE ] || [ "$SERVICE" = "$i" ] || [ "$SERVICE" = "" ]; then | |
cd ../${SERVICE_PREFIX}$i | |
go run "./cmd/$i/main.go" 2>&1 > /tmp/servicelogs.pipe & | |
echo "$i started with pid $!" | |
runningPIDs+=($!) | |
fi | |
done | |
tail -f /tmp/servicelogs.pipe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment