Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Created April 3, 2022 22:25
Show Gist options
  • Select an option

  • Save anushshukla/25c253322a2eba695bd9507c475a3d53 to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/25c253322a2eba695bd9507c475a3d53 to your computer and use it in GitHub Desktop.
PM2 process smart start / reload
declare -a processNames=(
"test"
"test2"
"test3"
"test4"
)
## now loop through the above array
for processName in "${processNames[@]}"
do
echo "$processName"
pm2ProcessID=`pm2 pid $processName`
echo "$pm2ProcessID"
if [ "${pm2ProcessID}" = "" ]; then
echo 'process start'
pm2 start ./build/src/index.js --name="${processName}"
else
echo 'process reload'
pm2 reload "${processName}"
fi;
done
echoi $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment