Pm2: Startup is not starting pm2 daemon and saved process

Created on 27 Feb 2015  路  42Comments  路  Source: Unitech/pm2

i installed pm2 as global package on ubuntu (aws instance).
Created startup, ran a nodejs process, did pm2 save. Rebooted my instance, logged in and did pm2 list
but process was not in, instead it show msg like

[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized

i tried many times, tried on Amazon Linux instance also, but no luck. Is there some existing issue ?
am i missing something(i guess i did steps needed) ?

Any help to get it working smoothly?

Most helpful comment

I had this issue too, wanting to run pm2 as root. Here's what I did (warning: know what you're doing while root! insert root precautions here!!):

  1. sudo su
  2. as root, rm /etc/init.d/pm2-init.sh
  3. as root, run pm2 startup. it still complains that /etc/init.d/pm2-init.sh _links_ already exists, despite just removing it
  4. as root, pm2 start (my processes, eg ecosystem.json), pm2 start ecosystem.json
  5. as root, pm2 save
  6. reboot (if ubuntu)

that resolved it. i definitely ran the pm2 startup originally as my normal user, not my pm2 user (root). this fubared the init file. ill submit a PR to warn of that in the docs if its missing already

All 42 comments

How have you generated your startup script (command)?
What is the user running pm2?

root user,
$ pm2 startup amazon

tried the following also.
$ sudo env PATH=$PATH:/usr/bin pm2 startup amazon -u ec2-user

Are you sure that the user that should run pm2 is not ec2-user instead?

yes this user is supposed to to run the process, iits default sudoer on AWS ec2 instance, there is not other user i have created.

Can you tell me the value of the PM2_HOME value in the /etc/init.d/pm2-init.sh ? (https://github.com/Unitech/PM2/blob/master/lib/scripts/pm2-init-amazon.sh#L27)

its showing

export PM2_HOME="/root/.pm2"

its not in HOME dir of ec2-user, but in root user (i setup pm2 as user-data script on ec2 launch)

I also have this problem although with ubuntu (aws instance) with user ubuntu. This the generated /etc/init.d/pm2-init.sh

# snip
NAME=pm2
PM2=/usr/lib/node_modules/pm2/bin/pm2
USER=root

export PATH=$PATH:/usr/bin
export PM2_HOME="/home/ubuntu/.pm2"

super() {
    su - $USER -c "PATH=$PATH; $*"
}

start() {
    echo "Starting $NAME"
    super $PM2 resurrect
}

#snip

somehow running sudo service pm2-init.sh start always search for dump file in /root/.pm2 directory, not in /home/ubuntu/.pm2, while the actual dump file that's generated when running sudo pm2 save gets saved in /home/ubuntu/.pm2. Editing the script like this fix the problem:

# snip
NAME=pm2
PM2=/usr/lib/node_modules/pm2/bin/pm2
USER=root

export PATH=$PATH:/usr/bin
export PM2_HOME="/home/ubuntu/.pm2"

super() {
    su - $USER -c "PATH=$PATH; $*"
}

start() {
    echo "Starting $NAME"
    export PM2_HOME="/home/ubuntu/.pm2" # <== fix
    super $PM2 resurrect
}

#snip

I had this issue too, wanting to run pm2 as root. Here's what I did (warning: know what you're doing while root! insert root precautions here!!):

  1. sudo su
  2. as root, rm /etc/init.d/pm2-init.sh
  3. as root, run pm2 startup. it still complains that /etc/init.d/pm2-init.sh _links_ already exists, despite just removing it
  4. as root, pm2 start (my processes, eg ecosystem.json), pm2 start ecosystem.json
  5. as root, pm2 save
  6. reboot (if ubuntu)

that resolved it. i definitely ran the pm2 startup originally as my normal user, not my pm2 user (root). this fubared the init file. ill submit a PR to warn of that in the docs if its missing already

If you would change USER=root to USER=ubuntu it should work as expected even launched during startup.

what about the

# /etc/init.d/pm2-init.sh
lockfile="/var/lock/subsys/pm2-init.sh"

lockfile that only root has access ?

this issue and #889 are same.

I encounter the same problem.
Our servers have two root account(root and root1), we use root1 account for everyday use, when we do "pm2 save", the USER is root, but PM2_HOME is /home/root1/.pm2, after reboot, processes not run automaticly, we receive a error message: [PM2] No processes saved; DUMP file doesn't exist.
For fix the problem, you must login exactly with "root" user, start you app with pm2, do pm2 save and make pm2-init.sh as service.

Same here.

I have a worker user. I install nvm as this user so the node command is available per user and not globally. Running the command generated by the pm2 startup (on ubuntu 14.04) generates an invalid startup script. I had to manually edit the /etc/init.d/pm2-init.sh file and changed the PATH and PM2_HOME variables like this:

export PATH=/home/worker/.nvm/versions/node/v4.1.1/bin:$PATH
export PM2_HOME="/home/worker/.pm2"

Ow... Note that this worker user doesn't have sudo so I had to run the generated command (returned by the pm2 startup executed as worker user) as ubuntu root user. Now it works. This is a bug and should be fixed. Thanks.

I also had this issue, @rbudiharso fix worked for me. Thanks!

pm2 0.15.7
Ubuntu 12.04

any updates on this?

@rbudiharso that did work for me too!
pm2 0.15.7
node 4.2.3
Ubuntu 15.04

It doesn't work on Centos 7.
On restarting, the dump.pm2 file is being overwritten and the content is being deleted due to which the process is not resurrected!

I get the same on ubuntu as root:

pm2 startup ubuntu
pm2 start app.js
pm2 save
reboot

pm2 list shows no apps when the server returns.

try to:

pm2 startup ubuntu -u ubuntu --hp /home/ubuntu 

Same issue here. I ended up using a simple start bash script and an extra line in the crontab as a temporary fix.

For me it worked when doing sudo pm2 save

I had the same problem on ubuntu 14.04. Fixed it by running "sudo pm2 startup -u myusername". Then "sudo pm2 save". And "sudo shutdown -r now" - of course.

Hi,
Still facing the issue even after implementing @DeveloperAlex steps

sudo pm2 startup "matt212"
sudo pm2 start app.js
sudo pm2 save

sudo shutdown -r now
are there any other alternative to pm2 could be great ! if there is no solution available

I modified init.d script not to dump processes while stopping and it works for me:

stop() {
#super $PM2 dump
super $PM2 delete all
super $PM2 kill
}

great it worked like charmed ! @artursudnik

duplicate #1035

I have this issue when i reboot my server pm2 starts but with no processes I must run pm2 resurrect every time I reboot the server

@benishak make sure you do pm2 dump before shutting down the server.

@soyuka but people here suggested to comment the pm2 dump in the init script and the newest pm2 seams to adopt this solution

I thought about commenting pm2 delete all or replacing it with pm2 stop all

Indeed, but if there is no dump, pm2 resurrect will launch no processes. Btw the dump file is located at ~/.pm2/dump.pm2.

The change here is a breaking a normal server reboot. Really bad "fix"

the init script is overwriting my dump.pm2 at shutdown, setting it to []. To prevent this, you can make the dump file immutable by running chattr +i $HOME/.pm2/dump.pm2. Of course, this fix will only work if you do not intend to add or remove apps from pm2 once they are setup. In my case, I don't, so this fix works for me.

i think if you use ubuntu and you installed pm2 as a normal user not a root user, it will fail

I did install pm2 on ubuntu as the vagrant user (not root). I will try to install as root and see if that works.

@jar349 Did installing as root work? How does one uninstall pm2? How does one install pm2 as root? Thanks.

pm2 kill
npm remove pm2
sudo npm install pm2 -g
pm2 start yourapp.js

For those running with systemd, note that the fix in this commit was not applied to the pm2.service file: https://github.com/Unitech/pm2/commit/f2714c7385681c7592cf4c5629a6a75efc7db4d9

To fix, comment out the following line:

ExecStop=%PM2_PATH% dump
https://github.com/Unitech/pm2/blob/30239e142928ae04fa19733e186df4c9288f3949/lib/scripts/pm2.service#L13

Hello, so what is the best way to solve the issue because i am facing this problem and find yours comments ?? please help me

I confirm the solution of @DeveloperAlex in his comment for MacOS.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chaos-git picture chaos-git  路  3Comments

rajendar38 picture rajendar38  路  3Comments

morfies picture morfies  路  3Comments

psparago picture psparago  路  3Comments

cchan picture cchan  路  3Comments