25

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.

nomad
  • 1,699
  • 5
  • 21
  • 35

3 Answers3

25

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
Ivan Vovk
  • 929
  • 14
  • 28
10

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.

David
  • 101
  • 1
  • 3
1

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.

Patrick Moore
  • 13,251
  • 5
  • 38
  • 63