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.
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!
Most helpful comment
It did the trick, thanks!