How can I get pm2 to use my ecosystem.config.js file on reboot?
Asked Answered
pm2
M

3

27

My ecosystem.config.js file loads my environment great with this command:

pm2 start ecosystem.config.js

When I run any of these command, my environment is reloaded just fine:

pm2 reload myapp
pm2 restart myapp
pm2 reload ecosystem.config.js
pm2 restart ecosystem.config.js

Then I try to make sure I get my environment back after a reboot. If I run pm2 startup I get this:

sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u me --hp /home/me

After running that command, I can reboot my machine and my application is restarted automatically. However, I am missing my environment from the ecosystem.config.js file. Why? How do I make sure the environment from my ecosystem.config.js environment is loaded when the machine is rebooted? Thanks.

Maryettamaryjane answered 7/11, 2017 at 20:9 Comment(1)
this answer talks about how to make pm2 to use ecosystem.config.jsElectrothermics
L
29

Dont forget to save your config! pm2 save

In case you want pm2 on startup with changed logs path:

pm2 delete all
pm2 start ecosystem.js
pm2 save
pm2 startup
Lilithe answered 17/6, 2019 at 8:55 Comment(0)
P
11

I had the same issue. After executing the command suggested by pm2 startup, I found I had to first run pm2 delete all, then restart using pm2 start ecosystem.config.js. My environment is now loading as expected after rebooting.

Pukka answered 24/4, 2018 at 15:7 Comment(0)
S
4

May be worth sharing that a file named ecosystem.js, even if empty, needs to exist on the system in the user's home path so that pm2 can load it.

Sensitometer answered 10/11, 2022 at 3:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.