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

pm2
nomad picture nomad · Nov 7, 2017 · Viewed 11.8k times · Source

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.

Answer

Ivan Vovk picture Ivan Vovk · Jun 17, 2019

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