When I install PM2 0.12.1 with the following and run pm2 list like this...
sudo npm install -g pm2
sudo pm2 startup ubuntu
pm2 list
I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect EACCES
at errnoException (net.js:904:11)
at Object.afterConnect [as oncomplete] (net.js:895:19)
However, if I go back to an older version which I have been using in production 0.9.6, then running the following:
sudo npm install -g [email protected]
sudo pm2 startup ubuntu
pm2 list
Then it works fine. If it's not a bug, then I'm unsure what I'm doing wrong. The docs indicate this should be pretty straight forward.
Any help would be most appreciated!
It seems to be an Socket Error (reference).
For UNIX domain sockets, which are identified by pathname:
Write permission is denied on the socket file, or search
permission is denied for one of the directories in the path
prefix.
First of all, figure out where is you PM2 home, ~/.pm2 by default, if you are using a root user to spawn PM2 Satan, and using nobody (I mean not a root user) to sudo/su PM2 operations (downgrade permissions later). Just try to change your PM2_HOME environment variable, e.g.:
root user.
$ pm2 kill
$ rm -rf ~/.pm2
$ vi /etc/profile
export PM2_HOME=/opt/.pm2
$ chmod -R 777 /opt/.pm2
I am not sure this can help you out, have a try and feedback ;)
Thank you very much. I have had some success by removing all references to .pm2 then reinstalling, but changing the owner of the ~/.pm2 to being my user.
I no longer get errors, but sadly saving my processes doesn't work after reboot. Seems strange that 0.9.6 works flawlessly, which makes me wonder whether the issues are related to a newer feature.
By saving are you talking about pm2 dump?pm2 save == pm2 dump
The ~/.pm2 directory should have the same user owner as the user that installed pm2. For example, if I'm installing pm2 as root (eg sudo npm i pm2 -g --unsafe-perm) ~/.pm2 will be located in /root/.pm2 by default.
For the pm2 upstart you'll need to run the command as root and specify the pm2 user with the -u argument.
I prefer the use of a random user, I'd install pm2 like this (assuming node has been installed to the user with nvm):
npm i pm2 -g
#if it's an update I'd have to update the in-memory pm2
pm2 updatePM2
#if the app isn't started start it
pm2 start app.js
#dump just in case
pm2 dump
#set the startup script*
sudo env PATH=$PATH:/home/mypm2user/.nvm/v0.10.31/bin pm2 startup ubuntu -u mypm2user
*Note that the startup script is called with sudo or, as root. For ubuntu it'll basically call update-rc.d which need the root permissions. Variables will be populated in the init script and pm2 will be called with su - $USER pm2 resurrect to ensure that we use the good pm2 instance.
@soyuka :+1:
@soyuka, I think you've given me the final piece of the puzzle that I needed.
You're right that I'm installing pm2 as root using sudo. So the reason why my pm2 save wasn't persisting was because I needed to specify the user to run them as.
So running sudo pm2 startup ubuntu -u [username] has fixed my issue. Rebooting and my processes are running.
You guys rock for helping me sort this so quickly. Thank you!
@Tjatse How can I fix this on Mac?
Mac don't have root, and don't have a /opt path.
Thank you!
@Yinear try @soyuka's solution.
If you're doing this on Mac, you need no sudo to upgrade permission.
/opt path is just an example, /path/to is okay too.
@Tjatse , while trying @soyuka's solution, in the first step "npm i pm2 -g", I got EACCES error asking me for root.
So I have to do chmod -R 777 on /Users/xxx/.npm and /usr/local/lib/node_modules.
After that, I still get Error: EACCES, symlink '../lib/node_modules/pm2/bin/pm2' and maybe more EACCES errors.
I'm afraid if I did it right? Thank you!
what i do:
lastly. it was success
thanks @medatech
I get this same error on a Macbook Pro
I'm too.
# app.coffee
http= require 'http'
http.createServer (req,res)->
res.writeHead 200, {'Content-Type':'text/plain'}
res.end 'Hello World\n'
.listen 80,'127.0.0.1'
console.log 'Server running at http://127.0.0.1:1337/'
$ sudo pm2 kill
# [PM2] PM2 stopped
$ rm -rf ~/.npm/pm2
$ rm -rf ~/.pm2
$ sudo npm uninstall pm2 --global
# unbuild [email protected]
$ npm install pm2 --global
# [email protected] /Users/koliseoa/.nodebrew/current/lib/node_modules/pm2
$ sudo pm2 start app.coffee
#β app β 0 β fork β 66353 β online β 0 β 0s β 7.723 MB β disabled β
$ pm2 list
# events.js:85
# throw er; // Unhandled 'error' event
# ^
# Error: connect EACCES
# at exports._errnoException (util.js:746:11)
# at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
But, resolved at the following.
$ sudo chmod -R 777 ~/.pm2
$ pm2 list
#β hoo β 0 β fork β 66353 β online β 0 β 2m β 8.988 MB β disabled β
In this case, permission of the ~/.pm2 was the cause.
You can also just do:
sudo chown nobody:nogroup ~/.pm2/*
@struCoder thanksοΌi resolved with your method.
If you forgot to use the -u argument in pm2 startup ubuntu -u YOURNODEJSUSER, you still can change the user in your /etc/init.d/pm2-init.sh at line 21 : USER=YOURNODEJSUSER
I tried most of the suggestions, but the only one that worked was jhansen-tt's (thanks!). Make sure all the files in ~/user/.pm2 are owned by the user account!
had the same problem on Ubuntu Server. As other people mentioned, just run pm2 commands as SU like sudo pm2 list
I had a really weird issue with EACCES that was unrelated to the above things. I was in my home directory on Centos /home/matt, then did sudo su www, then tried pm2 start /path/to/my/app.js. It threw up an error just because I was currently in a directory that I didn't have permission to access, even though i was trying to run the script that was situated somewhere I did have access to. Changing directory to my own home folder made the command work- kinda odd.
I do not recommend to use chmod 777
you should run pm2 without sudo
$ sudo pm2 start pm2.json
$ ps aux | grep PM2
# user 4318 0.1 0.0 2448152 860 s000 S+ 6:09PM 0:00.00 grep PM2
# root 3515 0.0 0.2 3130616 58836 ?? Ss 5:47PM 0:01.03 PM2 v1.1.2: God Daemon
$ pm2 list
βΌοΈ # Error... (connect EACCES...)
$ sudo pm2 list
π # Working...
$ sudo pm2 kill
$ pm2 start pm2.json
$ ps aux | grep PM2
# user 4318 0.1 0.0 2448152 860 s000 S+ 6:09PM 0:00.00 grep PM2
# user 3515 0.0 0.2 3130616 58836 ?? Ss 5:47PM 0:01.03 PM2 v1.1.2: God Daemon
$ pm2 list
π # Working...
@struCoder it is work for me, thanks
I just had this problem but the cause was a bit tricky.
I installed pm2 as a non-root user so I should be able to run it as non-root without any problems.
But when I started ubuntu from shutdown, I opened a terminal, logged in as root and did a pm2 logs and it daemonized pm2 as root. Now when I run pm2 start or pm2 restart it gave me the error telling me that it requires a root user.
To fix it, I just ran pm2 kill as root and then daemonized it again as a non-root user (like running pm2 logs again).
I hope this helps.
@struCoder Thanks! Solved my problem
I've ran into the sample problem and my situation was that I needed to ran pm2 as non-root and besides the fact that I was starting it with the correct user I wasn't under the user's home dir, instead I was in /root and pm2 was creating the .pm2 file under that directory. Changing to the correct dir solved my problem.
Ps: I've done the installation again just to make sure everything was setup correctly
Most helpful comment
what i do:
lastly. it was success