Created By Taufiq - 2022
This simple script will check your PM2 process, if there existing PM2 it will stop the process and delete the process then start new PM2 process
install npm PM2 as user or globally
npm install pm2
npm install -g pm2
#!/bin/bash | |
# Font & Color variables | |
red='\033[0;31m' | |
green='\033[0;32m' | |
clear='\033[0m' | |
Bold='\e[1m' | |
#PM2 process variables | |
PROCESS="server" | |
PROCESS_PATHS="path/to/service --name $PROCESS " | |
echo -e "Checking $PROCESS service status..." | |
if (pm2 list | grep $PROCESS);then | |
echo -e "PM2 $PROCESS : ${red}${Bold}Found${clear}, Terminate Client !" && | |
pm2 stop $PROCESS && pm2 delete $PROCESS && | |
echo -e "${green}${Bold}Start new $PROCESS Service...${Clear}" && | |
pm2 serve $PROCESS_PATHS && | |
echo -e "PM2 $PROCESS : ${green}${Bold}Online${clear}, Happy Ending !" | |
else | |
pm2 serve $PROCESS_PATHS && | |
echo -e "PM2 $PROCESS : ${green}${Bold}Online${clear}, Happy Ending !" | |
fi |