Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM2 not start after system reboot #2775

Closed
cawa-93 opened this issue Mar 17, 2017 · 22 comments
Closed

PM2 not start after system reboot #2775

cawa-93 opened this issue Mar 17, 2017 · 22 comments

Comments

@cawa-93
Copy link

cawa-93 commented Mar 17, 2017

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
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u alex --hp /home/alex
[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
pm2 start /home/alex/Develop/node-vk-spamer/index.js -n spamer
[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
pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/alex/.pm2/dump.pm2
reboot

After reboot

pm2 list
[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
pm2 resurrect
[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

Software versions used

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

PM2 Log output

tail --lines 50 ~/.pm2/pm2.log
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
@kevincaradant
Copy link

Hi

That's seems to be the same problem here: #2765

That will be fixed in the next release ;)

@vmarchaud
Copy link
Contributor

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

@kevincaradant
Copy link

kevincaradant commented Mar 17, 2017

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

@vmarchaud
Copy link
Contributor

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

@cawa-93
Copy link
Author

cawa-93 commented Mar 17, 2017

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

@cawa-93 cawa-93 closed this as completed Mar 17, 2017
@dknell
Copy link

dknell commented Apr 18, 2017

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

@pr1ntr
Copy link

pr1ntr commented May 9, 2017

2.4.6 still an issue Ubuntu 16.04

@smohankarthik
Copy link

i am facing the same issue in 2.5.0.

@revolunet
Copy link

@smohankarthik resolved ? if so how ? :)

@RikyTres
Copy link

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?

@revolunet
Copy link

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

@RikyTres
Copy link

@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

@revolunet
Copy link

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

@smohankarthik
Copy link

smohankarthik commented Jul 26, 2017

@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.

#1055

@applelok
Copy link

applelok commented Oct 31, 2017

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?

@ghost
Copy link

ghost commented Feb 2, 2018

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)

@lmj0011
Copy link

lmj0011 commented Mar 15, 2018

This was a no go for me. #2775 (comment)

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

@lmj0011
Copy link

lmj0011 commented Mar 16, 2018

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 #3274

@ibanana
Copy link

ibanana commented Jun 18, 2019

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

@RicardoZap
Copy link

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.

@ibanana
Copy link

ibanana commented Aug 19, 2020 via email

@Zeni241
Copy link

Zeni241 commented Nov 5, 2021

Solution is:‎
• Move to folder where you installed the PM2 (such as /home/ubuntu or home/faraz). There will be ‎a folder ‘.pm2 ‎.‎
• Run ‘PM2 startup’ to generate an active startup script.‎
• Run ‘PM2 save’ to freeze a process list for automatic respawn.’.‎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests