Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kerus1024/245d6cc824135ea8b45bf49bd275a9e3 to your computer and use it in GitHub Desktop.
Save kerus1024/245d6cc824135ea8b45bf49bd275a9e3 to your computer and use it in GitHub Desktop.
Bash Shell Script Run multiple process with features that re-starts process when single process failed
#!/bin/bash
JOBS=()
run_jobs() {
$@ &
JOBS+=($!)
}
while true;
do
if [ ! -z "${JOBS[@]}" ]; then
echo "${JOBS[@]}" | xargs -r kill -9
echo "--------------------------------------"
echo -e "\n\n\n\n\nProcess (Re)start\n\n\n\n"
echo "--------------------------------------"
fi
JOBS=()
cd /home/kerus1024/datamerge/
run_jobs node app.js
cd /home/kerus1024/crawler
run_jobs node app.js a
run_jobs node app.js b
run_jobs node app.js c
wait -n ${JOBS[@]}
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment