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 is created with root as the owner and completely breaks pm2 #831

Closed
neonstalwart opened this issue Nov 21, 2014 · 7 comments
Closed
Labels

Comments

@neonstalwart
Copy link

start with a server that has never had pm2 installed (the important part is that there is no ~/.pm2)

npm install pm2 -g
sudo env PATH=$PATH:`dirname $(which pm2)` pm2 startup ubuntu -u vagrant

at that point, ~/.pm2 has a root owner and if you try to do anything with pm2 after that (e.g. pm2 ls) you'll get an EACCES error.

my workaround is

npm install pm2 -g
# prevent pm2 from creating ~/.pm2 as the root user
pm2 ls
sudo env PATH=$PATH:`dirname $(which pm2)` pm2 startup ubuntu -u vagrant

this is possibly related to #789

@soyuka
Copy link
Collaborator

soyuka commented Nov 21, 2014

Also related to #712 where pm2 init itself (https://github.com/Unitech/PM2/blob/master/lib/CLI.js#L31).

I think this should be called at the npm install stage, so that pm2 already has the $PM2_HOME directory when installation is finished.
It'd be the best way to prevent EACCESS error because if you run the startup as sudo it'll indeed create the directory as root if you haven't called the CLI at least once.

A similar use case will be that pm2 is a dependency and that you call pm2.connect() before invoking pm2 -v or in your case pm2 ls.

soyuka pushed a commit to soyuka/pm2 that referenced this issue Nov 21, 2014
soyuka pushed a commit that referenced this issue Nov 21, 2014
@soyuka
Copy link
Collaborator

soyuka commented Nov 23, 2014

#837 read this too about startup and pm2 user owner ;)

@soyuka
Copy link
Collaborator

soyuka commented Dec 8, 2014

#872

@soyuka
Copy link
Collaborator

soyuka commented Dec 9, 2014

An easy solution is to add pm2 -v (or any pm2 command) in the postinstall script so that PM2 sets it's home directory after the npm install command.

@meticulo3366
Copy link

Hello,

I ran into this issue as well and had to perform a hack to make it work for me.

sudo -i pm2 dump
sudo -i pm2 startup ubuntu

if the start up file exists already it must be manually removed as follows:

sudo rm /etc/init.d/pm2-init.sh
sudo update-rc.d pm2-init.sh remove

now clear the contents of /root/ pm2 configuration and copy the user configuration over

sudo rm -Rf /root/.pm2
sudo cp -Rf .pm2 /root/.pm2

than i needed to modify the init script as follows to get it to work

sudo nano /etc/init.d/pm2-init.sh

cat /etc/init.d/pm2-init.sh

NAME=pm2
PM2=/usr/local/lib/node_modules/pm2/bin/pm2
USER=root
HOME=/user/ubuntu
PM2_HOME=/user/ubuntu/.pm2
export PATH=$PATH:/usr/bin
export PM2_HOME="/user/ubuntu/.pm2"

please notice this fix above which resolved the issue

PM2_HOME=/user/ubuntu/.pm2
export PM2_HOME="/user/ubuntu/.pm2"

@Synchro
Copy link

Synchro commented Jan 9, 2015

I've run into the same thing. I found that this created the init script correctly, and is more elegant than editing the init script:

PM2_HOME=/home/myuser/.pm2 pm2 startup ubuntu -u myuser

Unfortunately this command starts a pm2 God daemon before the init script is created, so I'm left with a running pm2 daemon with the wrong settings owned by root that breaks everything because it points at /root/.pm2, as above.

The next problem is that it's hard to stop this daemon nicely because it looks in the wrong place for its config because the init script is now in effect (i.e. service pm2-init.sh stop doesn't work), so I have to aggressively pkill -f PM2 to get rid of it before a simple service pm2-init.sh start starts it with the correct user, pointing at the correct .pm2 folder. Phew.

A minor issue - why not rename the init script to just pm2 when installing it, like nearly all other services do?

@Unitech
Copy link
Owner

Unitech commented Dec 6, 2016

sudo stuff fixed

#2559

@Unitech Unitech closed this as completed Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants