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

Running pm2 as a user other than root #733

Closed
pavelfomin opened this issue Sep 23, 2014 · 4 comments
Closed

Running pm2 as a user other than root #733

pavelfomin opened this issue Sep 23, 2014 · 4 comments

Comments

@pavelfomin
Copy link

An initial attempt was made to generate the pm2-init.sh script with a user other than root:

USER=%USER%

export PATH=$PATH:%NODE_PATH%
export PM2_HOME="%HOME_PATH%"

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

The command pm2 startup -u node centos would generate the following file content:

USER=node

export PATH=$PATH:/usr/local/node/node-v0.10.26/bin
export PM2_HOME="/root"

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

There are two problems with this approach. First, PM2_HOME still points to /root. Second, the lockfile points to the directory only root can write in.

Proposed changes

export PM2_HOME="$(eval echo ~$USER)"
lockfile="$PM2_HOME/.pm2/pm2.lock"
@grees
Copy link

grees commented Sep 23, 2014

👍

@JeromeGill
Copy link

As an aside, it is currently difficult to install pm2 without the --unsafe-perm flag. Some documentation on recommended permissions set-up would be really great.

@soyuka
Copy link
Collaborator

soyuka commented Sep 26, 2014

With the beta version (npm i pm2@rc) socket has been fixed an you can run 1 pm2 instance per user on a same server.
I'd advise using nvm to manage node versions and packages per user:

su - $user
nvm install 0.11.13
npm i pm2@rc -g
pm2 start server.js
#then as root
su -
nvm install 0.11.13
npm i pm2@rc -g --unsafe-perm
pm2 list #should be empty

@bluecurio
Copy link

👍 on documentation about permissions setup.

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

No branches or pull requests

6 participants