Skip to content

Instantly share code, notes, and snippets.

@fahadsiddiqui
Last active July 19, 2023 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahadsiddiqui/33cd84f2ef46dc2ae614560a7b79df2e to your computer and use it in GitHub Desktop.
Save fahadsiddiqui/33cd84f2ef46dc2ae614560a7b79df2e to your computer and use it in GitHub Desktop.
#!/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