Created
April 3, 2022 22:25
-
-
Save anushshukla/25c253322a2eba695bd9507c475a3d53 to your computer and use it in GitHub Desktop.
PM2 process smart start / reload
This file contains hidden or 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
| 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