Here are the steps to make PM2 restart processes automatically after a reboot:
Step 1) Save the current process list
pm2 save
Step 2) Generate startup script for pm2
pm2 startup
Note : This will give output a command specific to your server's operating system. Copy and run the generated command in same terminal to enable PM2 startup on boot.
example : sudo env PATH=$PATH:/home/owncloud/.nvm/versions/node/v20.18.0/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u owncloud --hp /home/owncloud
Step 3) Verify the startup configuration
pm2 list
Optional: To set up a PM2 process to restart every 5 minutes using a cron job, you can follow these steps:
pm2 restart 0 --cron "*/5 * * * *"
pm2 show 0
Friday, October 11, 2024
Automatically Restart PM2 Processes After a Server Reboot
Subscribe to:
Post Comments (Atom)
https://drive.google.com/file/d/1cEYWHHQZw02yAbJOgdnPx4jmp3A5xK2B/view?usp=sharing
ReplyDelete