All scripts should run as user "ubuntu".
I have installed PM2 via
sudo npm install pm2 -g
After that, I've initialized the startup script
sudo pm2 startup ubuntu -u ubuntu
Now, PM2 starts all of my scripts automatically on every reboot. But there is a problem - everything is still running as user root. If I try to execute pm2 list as user ubuntu, I get the following error message:
ubuntu@1-server:/tmp$ pm2 list
events.js:141
throw er; // Unhandled 'error' event
^
Error: connect EACCES /home/ubuntu/.pm2/rpc.sock
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)
Also all files which have been downloaded via my scripts are owned as root, f.e.:
ubuntu@1-server:/tmp$ ls -l GeoLite2-City.mmdb
-rw-r--r-- 1 root root 76079111 Aug 20 13:14 GeoLite2-City.mmdb
The expected behaviour would be that all scripts are executed as user "ubuntu".
All scripts are still executed as root.
Above
OS : Ubuntu 16.04
node.js : 4.5
PM2 : 1.1.3
Could you try using the RC of v2 : npm install -g pm2@next ?
You have installed PM2 with the wrong user, do not use sudo when doing npm install pm2 -g.
$ sudo pm2 kill
$ npm install pm2 -g
$ pm2 ls
For anyone having the same issue in ubuntu. Try changing the ownership of the pm2 folder in /usr/local/lib/node_modules to the user you are using (in this case 'ubuntu') and reboot.
cd /usr/local/lib/node_modules && sudo chown $USER:$USER -R pm2/
After reboot I am having the same issue. Changing the ownership of this two files to non-privileged userName fixes the problem:
$ sudo chown userName:userName ~/.pm2/rpc.sock
$ sudo chown userName:userName ~/.pm2/pub.sock
But this does not solve the problem after yet another reboot. And yes, I installed pm2 under root user. Installing pm2 locally for each user seems a bit strange for me, but I believe that's normal practice for pm2.
@Unitech the above solution worked well
$ sudo pm2 kill
$ npm install pm2 -g
$ pm2 ls
The thing is i had to restart the production server :(
As of today, using pm2 v3.0.0 the problem still persists. After reboot pm2 starts and creates pub.sock and rpc.sock as root on Ubuntu.
It depends on how you have run pm2 startup
Always run pm2 startup first WITHOUT sudo, then you will get the exact line to copy/paster in your terminal. Else it will generate a wrong startup file.
To clear things up:
$ pm2 unstartup
$ pm2 startup
# COPY/PASTE the line shown by pm2 startup