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

Startup is not starting pm2 daemon and saved process #1055

Closed
ankitpatial opened this issue Feb 27, 2015 · 42 comments
Closed

Startup is not starting pm2 daemon and saved process #1055

ankitpatial opened this issue Feb 27, 2015 · 42 comments

Comments

@ankitpatial
Copy link

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?

@Unitech
Copy link
Owner

Unitech commented Feb 28, 2015

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

@ankitpatial
Copy link
Author

root user,
$ pm2 startup amazon

@ankitpatial
Copy link
Author

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

@Unitech
Copy link
Owner

Unitech commented Feb 28, 2015

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

@ankitpatial
Copy link
Author

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.

@Unitech
Copy link
Owner

Unitech commented Feb 28, 2015

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)

@ankitpatial
Copy link
Author

its showing

export PM2_HOME="/root/.pm2"

@ankitpatial
Copy link
Author

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

@rbudiharso
Copy link

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

@cdaringe
Copy link
Contributor

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

@cdaringe
Copy link
Contributor

@mstefaniuk
Copy link

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

@ankitpatial
Copy link
Author

what about the

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

lockfile that only root has access ?

@ankitpatial
Copy link
Author

this issue and #889 are same.

@tangxinfa
Copy link

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.

@xpepermint
Copy link

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.

@rdjs
Copy link

rdjs commented Oct 28, 2015

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

pm2 0.15.7
Ubuntu 12.04

@scaryguy
Copy link

any updates on this?

@viniciusbo
Copy link

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

@rishabhmhjn
Copy link

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!

@thomasgallagher
Copy link

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.

@AlexTiTanium
Copy link

try to:

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

@jhiver
Copy link

jhiver commented Feb 8, 2016

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

@danielgindi
Copy link

For me it worked when doing sudo pm2 save

@DeveloperAlex
Copy link

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.

@matt212
Copy link

matt212 commented Feb 24, 2016

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

@artursudnik
Copy link

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
}

@matt212
Copy link

matt212 commented Feb 25, 2016

great it worked like charmed ! @artursudnik

Unitech added a commit that referenced this issue Feb 29, 2016
@Unitech
Copy link
Owner

Unitech commented Feb 29, 2016

duplicate #1035

@Unitech Unitech closed this as completed Feb 29, 2016
@benishak
Copy link

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

@soyuka
Copy link
Collaborator

soyuka commented May 25, 2016

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

@benishak
Copy link

@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

@soyuka
Copy link
Collaborator

soyuka commented May 25, 2016

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

@mvdwalle
Copy link

mvdwalle commented Jun 6, 2016

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

@jar349
Copy link

jar349 commented Jun 10, 2016

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.

@benishak
Copy link

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

@jar349
Copy link

jar349 commented Jun 17, 2016

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

@tjayrush
Copy link

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

@benishak
Copy link

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

@david-resnick
Copy link

For those running with systemd, note that the fix in this commit was not applied to the pm2.service file: f2714c7

To fix, comment out the following line:

ExecStop=%PM2_PATH% dump

ExecStop=%PM2_PATH% dump

@MilanMahata
Copy link

MilanMahata commented Feb 16, 2017

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

@kkoomen
Copy link

kkoomen commented Jul 21, 2020

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

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