Skip to content

Instantly share code, notes, and snippets.

@hktonylee
Created December 1, 2017 02:12
Show Gist options
  • Save hktonylee/777c2c773061e82030f3b0bbec4efc3e to your computer and use it in GitHub Desktop.
Save hktonylee/777c2c773061e82030f3b0bbec4efc3e to your computer and use it in GitHub Desktop.
Run multiple service in one script
#!/usr/bin/env bash
updateRate=1
shutdown() {
updateRate=0.2
for pid in $(jobs -p); do
pkill -TERM -P "$pid"
done
}
run() {
pushd . > /dev/null 2>&1
cd ./run
echo -ne "\rRunning fake market data... "
../run-fake-md.sh &
echo "$!"
echo -ne "\rRunning PPS..."
../run-lt-pps.sh &
echo "$!"
sleep 5;
echo -ne "\rRunning OPS..."
../run-lt-ops.sh &
echo "$!"
popd > /dev/null 2>&1
}
waitWithStatus() {
while (( $(jobs -p | wc -l) > 0 )); do
jobs > /dev/null 2>&1 # fix the `jobs -p` not pruning finished job
echo -ne "\033[2K"
echo -ne "Running..."
echo -n " [$(jobs -p | wc -l)] "
echo -n "$(jobs -p | tr '\n' ' ')"
echo -ne "\r"
sleep "$updateRate";
done
echo -ne "\033[2K"
echo "Done"
}
trap shutdown SIGINT
run
waitWithStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment