Post

Serv00使用pm2保活业务进程

PM2安装:

bash <(curl -s https://raw.githubusercontent.com/k0baya/alist_repl/main/serv00/install-pm2.sh)

PM2使用:

使用pm2拉起业务进程

pm2 xxx(xxx为原始业务启动命令)

保存pm2进程列表

pm2 save

重新加载pm2管理的进程

pm2 resurrect

保活检测脚本

1
2
3
4
5
6
7
8
#保活检测脚本,添加到定时任务一分钟执行一次
output=$(/home/xxxx/.npm-global/bin/pm2 status)
if echo "$output" | grep -q "Current process list is not synchronized with saved list"; then
echo "Process list is not synchronized. Executing pm2 resurrect..."
/home/xxxx/.npm-global/bin/pm2 resurrect
else
echo "Process list is synchronized."
fi

参考文档: https://saika.us.kg/2024/01/27/serv00_logs#Pm2

This post is licensed under CC BY 4.0 by the author.