Pm2: PM2 not start after system reboot

Created on 17 Mar 2017  Β·  21Comments  Β·  Source: Unitech/pm2

Expected behaviour

Saved processes start automatically after the machine starts up

Actual behaviour

The processes are not started after the system is started

Steps to reproduce

$ pm2 startup
[PM2] Init System found: systemd
[PM2] You have to run this command as root. Execute the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u alex --hp /home/alex



md5-26d3be4d1e7f17173fad5f036db3e465



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



md5-26d3be4d1e7f17173fad5f036db3e465



[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=alex
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TimeoutStartSec=8
Environment=PATH=/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/alex/.pm2
PIDFile=/home/alex/.pm2/pm2.pid

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-alex.service
Command list
[ 'chmod +x /etc/systemd/system/pm2-alex.service',
  'systemctl enable pm2-alex',
  'systemctl start pm2-alex',
  'systemctl daemon-reload',
  'systemctl status pm2-alex' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-alex.service
[PM2] Making script booting at startup...
>>> Executing chmod +x /etc/systemd/system/pm2-alex.service
[DONE] 
>>> Executing systemctl enable pm2-alex
Created symlink from /etc/systemd/system/multi-user.target.wants/pm2-alex.service to /etc/systemd/system/pm2-alex.service.
[DONE] 
>>> Executing systemctl start pm2-alex
[DONE] 
>>> Executing systemctl daemon-reload
[DONE] 
>>> Executing systemctl status pm2-alex
● pm2-alex.service - PM2 process manager
   Loaded: loaded (/etc/systemd/system/pm2-alex.service; enabled; vendor preset: enabled)
   Active: active (running) since ΠΏΡ‚ 2017-03-17 12:16:15 EET; 120ms ago
     Docs: https://pm2.keymetrics.io/
 Main PID: 3552 (PM2 v2.4.2: God)
   CGroup: /system.slice/pm2-alex.service
           └─3552 PM2 v2.4.2: God Daemon (/home/alex/.pm2)               

Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: [PM2] Spawning PM2 daemon with pm2_home=/home/alex/.pm2
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: [PM2] PM2 Successfully daemonized
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: [PM2] Resurrecting
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: [PM2] Restoring processes located in /home/alex/.pm2/dump.pm2
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: [PM2][ERROR] No processes saved; DUMP file doesn't exist
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: β”‚ App name β”‚ id β”‚ mode β”‚ pid β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem β”‚ watching β”‚
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Π±Π΅Ρ€ 17 12:16:15 G500 pm2[3545]:  Use `pm2 show <id|name>` to get more details about an app
Π±Π΅Ρ€ 17 12:16:15 G500 systemd[1]: Started PM2 process manager.
[DONE] 
+---------------------------------------+
[PM2] Freeze a process list on reboot via:
$ pm2 save

[PM2] Remove init script via:
$ pm2 unstartup systemd



md5-26d3be4d1e7f17173fad5f036db3e465



pm2 start /home/alex/Develop/node-vk-spamer/index.js -n spamer



md5-26d3be4d1e7f17173fad5f036db3e465



[PM2] Starting /home/alex/Develop/node-vk-spamer/index.js in fork_mode (1 instance)
[PM2] Done.
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ mode β”‚ pid  β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem       β”‚ watching β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ spamer   β”‚ 0  β”‚ fork β”‚ 3652 β”‚ online β”‚ 0       β”‚ 0s     β”‚ 6%  β”‚ 21.8 MB   β”‚ disabled β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Use `pm2 show <id|name>` to get more details about an app



md5-26d3be4d1e7f17173fad5f036db3e465



pm2 save



md5-26d3be4d1e7f17173fad5f036db3e465



[PM2] Saving current process list...
[PM2] Successfully saved in /home/alex/.pm2/dump.pm2



md5-26d3be4d1e7f17173fad5f036db3e465



reboot



md5-cc5fcec3c5597d0e6d3e4cc09db8a218



pm2 list



md5-26d3be4d1e7f17173fad5f036db3e465



[PM2] Spawning PM2 daemon with pm2_home=/home/alex/.pm2
[PM2] PM2 Successfully daemonized
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ mode β”‚ pid β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem β”‚ watching β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Use `pm2 show <id|name>` to get more details about an app



md5-26d3be4d1e7f17173fad5f036db3e465



pm2 resurrect



md5-26d3be4d1e7f17173fad5f036db3e465



[PM2] Resurrecting
[PM2] Restoring processes located in /home/alex/.pm2/dump.pm2
[PM2] Process /home/alex/Develop/node-vk-spamer/index.js restored
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ mode β”‚ pid  β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem       β”‚ watching β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ spamer   β”‚ 0  β”‚ fork β”‚ 2755 β”‚ online β”‚ 0       β”‚ 0s     β”‚ 9%  β”‚ 21.7 MB   β”‚ disabled β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Use `pm2 show <id|name>` to get more details about an app



md5-7ac8ad787b8011d1c306c926c20a57c9



OS         : Ubuntu 16.04
node.js    : v7.7.3
PM2        : 2.4.2



md5-ccf71d61e45e3e4cf60a0f5333a3e8b4



tail --lines 50 ~/.pm2/pm2.log



md5-26d3be4d1e7f17173fad5f036db3e465



2017-03-17 12:16:15: ===============================================================================
2017-03-17 12:16:15: --- New PM2 Daemon started ----------------------------------------------------
2017-03-17 12:16:15: Time                 : Fri Mar 17 2017 12:16:15 GMT+0200 (EET)
2017-03-17 12:16:15: PM2 version          : 2.4.2
2017-03-17 12:16:15: Node.js version      : 7.7.3
2017-03-17 12:16:15: Current arch         : x64
2017-03-17 12:16:15: PM2 home             : /home/alex/.pm2
2017-03-17 12:16:15: PM2 PID file         : /home/alex/.pm2/pm2.pid
2017-03-17 12:16:15: RPC socket file      : /home/alex/.pm2/rpc.sock
2017-03-17 12:16:15: BUS socket file      : /home/alex/.pm2/pub.sock
2017-03-17 12:16:15: Application log path : /home/alex/.pm2/logs
2017-03-17 12:16:15: Process dump file    : /home/alex/.pm2/dump.pm2
2017-03-17 12:16:15: Concurrent actions   : 2
2017-03-17 12:16:15: SIGTERM timeout      : 1600
2017-03-17 12:16:15: ===============================================================================
2017-03-17 12:18:20: Starting execution sequence in -fork mode- for app name:spamer id:0
2017-03-17 12:18:20: App name:spamer id:0 online
2017-03-17 12:21:37: Stopping app:spamer id:0
2017-03-17 12:21:37: App [spamer] with id [0] and pid [3652], exited with code [0] via signal [SIGINT]
2017-03-17 12:21:37: [HandleExit] PM2 is being killed, stopping restart procedure...
2017-03-17 12:21:37: pid=3652 msg=process killed
2017-03-17 12:21:37: ===============================================================================
2017-03-17 12:21:37: --- Stopping PM2 --------------------------------------------------------------
2017-03-17 12:21:37: Time                 : Fri Mar 17 2017 12:21:37 GMT+0200 (EET)
2017-03-17 12:21:37: ===============================================================================
2017-03-17 12:21:37: RPC closed
2017-03-17 12:21:37: PUB closed
2017-03-17 12:21:37: PM2 successfully stopped
2017-03-17 12:24:50: ===============================================================================
2017-03-17 12:24:50: --- New PM2 Daemon started ----------------------------------------------------
2017-03-17 12:24:50: Time                 : Fri Mar 17 2017 12:24:50 GMT+0200 (EET)
2017-03-17 12:24:50: PM2 version          : 2.4.2
2017-03-17 12:24:50: Node.js version      : 7.7.3
2017-03-17 12:24:50: Current arch         : x64
2017-03-17 12:24:50: PM2 home             : /home/alex/.pm2
2017-03-17 12:24:50: PM2 PID file         : /home/alex/.pm2/pm2.pid
2017-03-17 12:24:50: RPC socket file      : /home/alex/.pm2/rpc.sock
2017-03-17 12:24:50: BUS socket file      : /home/alex/.pm2/pub.sock
2017-03-17 12:24:50: Application log path : /home/alex/.pm2/logs
2017-03-17 12:24:50: Process dump file    : /home/alex/.pm2/dump.pm2
2017-03-17 12:24:50: Concurrent actions   : 2
2017-03-17 12:24:50: SIGTERM timeout      : 1600
2017-03-17 12:24:50: ===============================================================================
2017-03-17 12:28:23: Starting execution sequence in -fork mode- for app name:spamer id:0
2017-03-17 12:28:23: App name:spamer id:0 online

Most helpful comment

Turns out I was trying to create a startup script without doing pm2 save first.

Here's what eventually work, assuming only 1 user on the system is using pm2 in the example:

# stop and delete all previous pm2 processes for www user
  sudo su - www -c "pm2 stop all || true";
  sudo su - www -c "pm2 delete all || true";

# remove startup script and kill any lingering pm2 processes
  sudo pm2 unstartup || true;
  pkill -f pm2 || true;

# start pm2 processes for the 'www' user
  sudo su - www -c "pm2 start /home/www/ecosystem.config.js";

  # save process list and create startup script
  sudo su - www -c "pm2 save;";
  sudo pm2 startup -u www --hp /home/www;

However it may still be possible to get this error https://github.com/Unitech/pm2/issues/3274

All 21 comments

Hi

That's seems to be the same problem here: https://github.com/Unitech/pm2/issues/2765

That will be fixed in the next release ;)

Not sure it is, pm2 should boot faster (so under the timeout) and so resurrect applications.

For the moment I back on the version 2.4.0 which didn't have this problem of resurrect. You can try this workaround if you are in a hurry :)
I will wait the next release to try the fix because under the V2.4.2 (last version) I get the same problem as you

Can you try the fix ? npm install -g Unitech/pm2#development && pm2 update and then retry the startup flow

@vmarchaud, Yes, After reinstall from Unitech/pm2#development app startup after reboot. Thanks

I am having this issue on version 2.4.5. What is the resolution?

2.4.6 still an issue Ubuntu 16.04

i am facing the same issue in 2.5.0.

@smohankarthik resolved ? if so how ? :)

Same problem in a RasberryPi with ArchLinux on it and pm2 at version 2.6.1.
Is this could be a bug or a (my fault) config issue?

solved for me on my rPi by doing sudo pm2 startup again

@revolunet do you run pm2 as root user? In my case I run it by my own user, and if I run sudo pm2 startup I get this:

ul 25 13:52:39 tresPi pm2[1240]: [PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
Jul 25 13:52:44 tresPi pm2[1240]: [PM2] PM2 Successfully daemonized
Jul 25 13:52:44 tresPi pm2[1240]: [PM2] Resurrecting
Jul 25 13:52:44 tresPi pm2[1240]: [PM2] Restoring processes located in /root/.pm2/dump.pm2
Jul 25 13:52:44 tresPi pm2[1240]: [PM2][ERROR] No processes saved; DUMP file doesn't exist
Jul 25 13:52:44 tresPi pm2[1240]: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
Jul 25 13:52:44 tresPi pm2[1240]: β”‚ App name β”‚ id β”‚ mode β”‚ pid β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem β”‚ user β”‚ watching β”‚
Jul 25 13:52:44 tresPi pm2[1240]: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Jul 25 13:52:44 tresPi pm2[1240]:  Use `pm2 show <id|name>` to get more details about an app
Jul 25 13:52:44 tresPi systemd[1]: Started PM2 process manager.

My dump file location is not in the root dir.

When I reboot I don't have any proccess startup, and is I run pm2 list i get:

[PM2] Spawning PM2 daemon with pm2_home=/home/tres/.pm2
[PM2] PM2 Successfully daemonized
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ mode β”‚ pid β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem β”‚ user β”‚ watching β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 Use `pm2 show <id|name>` to get more details about an app

yes in my case i need to run it as root

If you launch it as root, then each call to pm2 must use sudo too

@revolunet yes, your right its was working only when your a root user. Non-Root user didnt work for me. I followed the steps which are mentioned in the following link , there a comment made by cdaringe i just followed that.

https://github.com/Unitech/pm2/issues/1055

Hi, I got this problem too in v 2.72, i am login as root user, tried to run pm2 save before running "sudo pm2 startup systemd", but error still here:

pm2[8527]: [PM2] Restoring processes located in /root/.pm2/dump.pm2
pm2[8527]: [PM2][ERROR] Failed to read dump file in /root/.pm2/dump.pm2.bak
pm2[8527]: [PM2][ERROR] No processes saved; DUMP file doesn't exist

OS: RHEL 7.2

Anyone facing this too?

I had to do:
sudo su
pm2 save
pm2 startup

This is because I was starting pm2 using a node script: sudo npm start which doesn't start the pm2 process as root. It was not saving the dump file to the correct user folder (root)

This was a no go for me. https://github.com/Unitech/pm2/issues/2775#issuecomment-362645805

pm2 v2.9.3

www@awsre574186:~$ pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/www/.pm2/dump.pm2

www@awsre574186:~$ pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u www --hp /home/www

www@awsre574186:~$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u www --hp /home/www
[PM2] Init System found: systemd
Platform systemd
Template
[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=www
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/www/.pm2
PIDFile=/home/www/.pm2/pm2.pid

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

Target path
/etc/systemd/system/pm2-www.service
Command list
[ 'systemctl enable pm2-www',
  'systemctl start pm2-www',
  'systemctl daemon-reload',
  'systemctl status pm2-www' ]
[PM2] Writing init configuration in /etc/systemd/system/pm2-www.service
[PM2] Making script booting at startup...
>>> Executing systemctl enable pm2-www
[DONE] 
>>> Executing systemctl start pm2-www
Job for pm2-www.service failed because a configured resource limit was exceeded. See "systemctl status pm2-www.service" and "journalctl -xe" for details.
[ERROR] Exit code : 1
[PM2][ERROR] systemctl start pm2-www failed, see error above.

www@awsre574186:~$ 

what I get from sudo journalctl -xe

-- The start-up result is done.
Mar 15 04:04:47 ip-172-31-95-70 systemd[1]: Starting PM2 process manager...
-- Subject: Unit pm2-www.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit pm2-www.service has begun starting up.
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: [PM2] Resurrecting
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: [PM2] Restoring processes located in /home/www/.pm2/dump.pm2
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ App name           β”‚ id β”‚ mode β”‚ pid   β”‚ status  β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem       β”‚ user β”‚ watching β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ lsae_cron          β”‚ 7  β”‚ fork β”‚ 19753 β”‚ stopped β”‚ 5       β”‚ 0      β”‚ 0%  β”‚ 0 B       β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ lsae_queue_worker1 β”‚ 8  β”‚ fork β”‚ 16964 β”‚ online  β”‚ 0       β”‚ 5m     β”‚ 0%  β”‚ 42.7 MB   β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ lsae_queue_worker2 β”‚ 9  β”‚ fork β”‚ 16966 β”‚ online  β”‚ 0       β”‚ 5m     β”‚ 0%  β”‚ 42.4 MB   β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ node_logwatch      β”‚ 12 β”‚ fork β”‚ 17012 β”‚ online  β”‚ 0       β”‚ 5m     β”‚ 0%  β”‚ 47.3 MB   β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ node_services      β”‚ 10 β”‚ fork β”‚ 16974 β”‚ online  β”‚ 0       β”‚ 5m     β”‚ 0%  β”‚ 54.0 MB   β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ node_websockets    β”‚ 11 β”‚ fork β”‚ 16976 β”‚ online  β”‚ 0       β”‚ 5m     β”‚ 0%  β”‚ 51.7 MB   β”‚ www  β”‚ disabled β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]:  Module activated
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ Module        β”‚ version β”‚ target PID β”‚ status β”‚ restart β”‚ cpu β”‚ memory      β”‚ user β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β”‚ pm2-logrotate β”‚ 2.4.0   β”‚ N/A        β”‚ online β”‚ 1       β”‚ 0%  β”‚ 56.516 MB   β”‚ www  β”‚
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜
Mar 15 04:04:48 ip-172-31-95-70 pm2[20099]:  Use `pm2 show <id|name>` to get more details about an app
Mar 15 04:04:48 ip-172-31-95-70 systemd[1]: pm2-www.service: PID file /home/www/.pm2/pm2.pid not readable (yet?) after start: No such file or directory
Mar 15 04:04:48 ip-172-31-95-70 systemd[1]: Failed to start PM2 process manager.
-- Subject: Unit pm2-www.service has failed
-- Defined-By: systemd

the line: Mar 15 04:04:48 ip-172-31-95-70 systemd[1]: pm2-www.service: PID file /home/www/.pm2/pm2.pid not readable (yet?) after start: No such file or directory is of interested.
Not sure what I need to do to ensure that /home/www/.pm2/pm2.pid is available and readable at the time pm2 startup is ran

Turns out I was trying to create a startup script without doing pm2 save first.

Here's what eventually work, assuming only 1 user on the system is using pm2 in the example:

# stop and delete all previous pm2 processes for www user
  sudo su - www -c "pm2 stop all || true";
  sudo su - www -c "pm2 delete all || true";

# remove startup script and kill any lingering pm2 processes
  sudo pm2 unstartup || true;
  pkill -f pm2 || true;

# start pm2 processes for the 'www' user
  sudo su - www -c "pm2 start /home/www/ecosystem.config.js";

  # save process list and create startup script
  sudo su - www -c "pm2 save;";
  sudo pm2 startup -u www --hp /home/www;

However it may still be possible to get this error https://github.com/Unitech/pm2/issues/3274

no me refiero adaptar al que tenemos sino ir empezando algo con este nuevo que puedes ser el futuro

Una disculpa por comentar en espaΓ±ol en un foro en InglΓ©s pero encontrΓ© la soluciΓ³n al problema.
Ami me funcionΓ³ ejecutando el siguiente mΓ©todo:

1.- pm2 start "ejemplo.js"
2.- pm2 save
3.- pm2 startup
4.- sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

DespuΓ©s de ejecutar lo anterior hacer un "sudo reboot" y con eso el problema queda resuelto. Saludos.

No se de que me hablas amigo jajaja

Enviado desde mi iPhone

El 19 ago 2020, a las 17:05, RicardoZap notifications@github.com escribiΓ³:

ο»Ώ
Una disculpa por comentar en espaΓ±ol en un foro en InglΓ©s pero encontrΓ© la soluciΓ³n al problema.
Ami me funcionΓ³ ejecutando el siguiente mΓ©todo:

1.- pm2 start "ejemplo.js"
2.- pm2 save
3.- pm2 startup
4.- sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi

DespuΓ©s de ejecutar lo anterior hacer un "sudo reboot" y con eso el problema queda resuelto. Saludos.

β€”
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cchan picture cchan  Β·  3Comments

getvega picture getvega  Β·  3Comments

rangercyh picture rangercyh  Β·  4Comments

FujiHaruka picture FujiHaruka  Β·  3Comments

lefam picture lefam  Β·  3Comments