pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 don't restart automaticaly after system reboot

Open Suniron opened this issue 3 years ago • 7 comments

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!

Suniron avatar Feb 08 '22 21:02 Suniron

Facing the same issue

Sashakil12 avatar Feb 12 '22 20:02 Sashakil12

Facing the same issue...

image

mfmsajidh avatar Mar 16 '22 12:03 mfmsajidh

Any updates ?

mfmsajidh avatar Apr 12 '22 13:04 mfmsajidh

No 😨

Suniron avatar Apr 12 '22 13:04 Suniron

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)

oscadev avatar Mar 12 '23 21:03 oscadev

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!

FitIT-Admin avatar Sep 01 '23 03:09 FitIT-Admin

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.

markfonte avatar Jun 26 '24 05:06 markfonte

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

eddiewebb avatar Nov 11 '24 21:11 eddiewebb

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.

eddiewebb avatar Nov 11 '24 21:11 eddiewebb