Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pm2

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.

like image 471
nomad Avatar asked Nov 07 '17 20:11

nomad


People also ask

Will pm2 start your applications after system reboot?

PM2 is designed to work with the default init system on a Linux system (which it can auto-detect) to generate the startup script and configure PM2 as a service that can be restarted at system boot. The startup sub-command tells PM2 to detect available init system, generate configuration and enable the startup system.

Where is ecosystem config js pm2?

The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.

How does pm2 restart work?

PM2 allows to reload (auto fallback to restart if not in cluster) an application based on a memory limit/ Please note that the PM2 internal worker (which checks memory), starts every 30 seconds, so you may have to wait a bit before your process gets restarted automatically after reaching the memory threshold.


2 Answers

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
like image 89
Ivan Vovk Avatar answered Oct 18 '22 18:10

Ivan Vovk


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.

like image 34
David Avatar answered Oct 18 '22 18:10

David