Pm2: Start PM2 process as another user

Created on 31 Dec 2016  路  2Comments  路  Source: Unitech/pm2

I've already made a startup scripts as following:

$ sudo mkdir /home/www-data
$聽sudo pm2 startup -u www-data --hp /home/www-data

The reasoning behind using the user www-data is that Nginx is already using that user and I need Nginx and PM2 to use the same user because when my nodejs script start listening on a UNIX socket, it creates the socket under the ownership that runs the PM2 process.

Until this point everything is fine, but the problem is, how can I start my nodejs script via PM2 under www-data user which is not even a real user?

Let's say I have the PM2 config file located at /home/www-data/pm2/site.pm2.json. I'd like to run it similar to:

$ pm2 startOrReload /home/www-data/pm2/site.pm2.json

but only under the user of www-data.

Question

Most helpful comment

It did the trick, thanks!

All 2 comments

In your case www-data should an unix user to use setguid, anyway if you start the daemon under a user, all process will have the same user.
So the startup part is good, what you need to do now is to export PM2_HOME env var to /home/www-data/.pm2 and chmod the dir to allow other users to connect to the PM2 daemon

It did the trick, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

waygee picture waygee  路  4Comments

FujiHaruka picture FujiHaruka  路  3Comments

ldarren picture ldarren  路  3Comments

liujb picture liujb  路  3Comments

mario-mui picture mario-mui  路  3Comments