Created
September 28, 2019 02:04
-
-
Save manjeshpv/60924207056773954f6a346db6cc5249 to your computer and use it in GitHub Desktop.
PM2 Graceful Reload - Halt Release if errors in code
This file contains 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
#!/bin/bash | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
printf "I ${RED}love${NC} Github\n " | |
# Assumption: PM2 running in cluster mode with atleast 2 instances, Instance ID's: 1, 2 name: api | |
echo -e "\n\n1. #################### Reseting Restart counters in PM2" | |
pm2 reset api | |
PID=1 | |
echo -e "\n\n2. #################### Restarting PM2 id $PID" | |
pm2 reload "$PID" | |
pm2 ls | |
echo -e "\n\n3. #################### Sleeping for 15 seconds" | |
sleep 15s | |
echo -e "\n\n4. #################### 15 seconds completed" | |
echo -e "\n\n5. Checking process app1(id:$PID) is greacefully reloaded. ?" | |
STATUS=$(pm2 describe "$PID" | grep online) | |
echo -e "\n\n6. Response from - pm2 describe $PID | grep online" | |
echo "$STATUS"; | |
if [ ! -z "$STATUS" ]; | |
then | |
echo -e "\n\n6. Process not restarting all threads"; | |
pm2 reload api | |
else | |
# stoping process if not comes online within 15 seconds | |
pm2 stop "$PID"; | |
echo -e "\n\n${RED}7. Process is not online. release failed${NC}"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment