Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.55k stars 2.63k forks source link

PM2 don't restart automaticaly after system reboot #5297

Open Suniron opened 2 years ago

Suniron commented 2 years ago

Hey there!

I'm really embarrassed with this problem: pm2 don't restart after a system crash (or just a simple system reboot).

I had read the documentation and maked the stratup strategy like that:

  1. Add my NodeJS conf into ecosystem file
  2. Start this ecosystem file with pm2
  3. Generate a startup script with pm2 startup
  4. Copy/paste the command to add the script on systemd
  5. Save the state with pm2 save
  6. Try a reboot and see that pm2 is not up after reboot

If i do a systemctl status , i see the error bellow: image

But, if i do manually pm2 resurrect, pm2 start and my app is alive. .

Thank's a lot for your help!

Sashakil12 commented 2 years ago

Facing the same issue

mfmsajidh commented 2 years ago

Facing the same issue...

image

mfmsajidh commented 2 years ago

Any updates ?

Suniron commented 2 years ago

No 😨

oscadev commented 1 year ago

I have to do a pm2 resurrect on each reboot. Sure, I can make a script that runs pm2 reboot on each boot, but thats a bandaid. What broke with PM2? This may have coincided with a node version change (uninstalling one version to install another)

FitIT-Admin commented 1 year ago

After hours and hours ... that's what worked for us (ubuntu +20): once you have managed your node app with pm2 (using pm2 start and checking with pm2 list and so on) the key command here is: pm2 startup This command will give you a Startup Script which you need to copy/paste wherther using a sudo user or root. The script looks like this: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u youruser --hp /home/youruserhome

And voila! your config is persistent now

Then verify with a reboot and reconnect and check your process running with a pm2 list

Hope it helps!

markfonte commented 4 months ago

After hours and hours ... that's what worked for us (ubuntu +20): once you have managed your node app with pm2 (using pm2 start and checking with pm2 list and so on) the key command here is: pm2 startup This command will give you a Startup Script which you need to copy/paste wherther using a sudo user or root. The script looks like this: sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u youruser --hp /home/youruserhome

And voila! your config is persistent now

Then verify with a reboot and reconnect and check your process running with a pm2 list

Hope it helps!

THANK YOU.

Following the prompts from pm2 startup worked for me.

eddiewebb commented 1 day ago

No change, ran command via sudo and directly as root.

eddiewebb commented 1 day ago

Got it !

for whatever reason the command printed was missing my user.

# given DOES NOT WORK
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 unstartup systemd -u  --hp /home/USERNAME

# Actual
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 unstartup systemd -u  USERNAME --hp /home/USERNAME

I noticed the missing user -u argument was causing invalid startup script.