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

Error: connect EACCESS #837

Closed
medatech opened this Issue Nov 22, 2014 · 23 comments

Comments

Projects
None yet
@medatech
Copy link

medatech commented Nov 22, 2014

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 pm2@0.9.6
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!

@Tjatse

This comment has been minimized.

Copy link
Collaborator

Tjatse commented Nov 23, 2014

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.:

  • Login with root user.

  • Flush PM2

    $ pm2 kill
    $ rm -rf ~/.pm2
    
  • Add export

    $ vi /etc/profile  
    
  • And add new line:

    export PM2_HOME=/opt/.pm2
    
  • Save and quit.

  • Chmod

    $ chmod -R 777 /opt/.pm2
    
  • Do your jobs

I am not sure this can help you out, have a try and feedback ;)

@medatech

This comment has been minimized.

Copy link
Author

medatech commented Nov 23, 2014

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.

@soyuka

This comment has been minimized.

Copy link
Collaborator

soyuka commented Nov 23, 2014

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.

@Tjatse

This comment has been minimized.

Copy link
Collaborator

Tjatse commented Nov 23, 2014

@soyuka 👍

@medatech

This comment has been minimized.

Copy link
Author

medatech commented Nov 23, 2014

@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!

@Yinear

This comment has been minimized.

Copy link

Yinear commented Mar 18, 2015

@Tjatse How can I fix this on Mac?
Mac don't have root, and don't have a /opt path.
Thank you!

@Tjatse

This comment has been minimized.

Copy link
Collaborator

Tjatse commented Mar 19, 2015

@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.

@Yinear

This comment has been minimized.

Copy link

Yinear commented Mar 19, 2015

@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!

@struCoder

This comment has been minimized.

Copy link

struCoder commented Apr 6, 2015

what i do:

  • sudo npm uninstall -g pm2
  • cd .npm/ && sudo rm -rf pm2*
  • cd ~ && sudo rm -rf .pm2
  • sudo npm install pm2 -g

lastly. it was success

@no7dw

This comment has been minimized.

Copy link

no7dw commented Apr 22, 2015

thanks @medatech

@ORESoftware

This comment has been minimized.

Copy link

ORESoftware commented May 26, 2015

I get this same error on a Macbook Pro

@59naga

This comment has been minimized.

Copy link

59naga commented Jul 2, 2015

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 pm2@0.14.3

$ npm install pm2 --global
# pm2@0.14.3 /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.

@jhansen-tt

This comment has been minimized.

Copy link

jhansen-tt commented Jul 8, 2015

You can also just do:
sudo chown nobody:nogroup ~/.pm2/*

@tuoxie007

This comment has been minimized.

Copy link

tuoxie007 commented Jul 24, 2015

@struCoder thanks,i resolved with your method.

@creativityjuice

This comment has been minimized.

Copy link

creativityjuice commented Aug 7, 2015

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

@glskiba

This comment has been minimized.

Copy link

glskiba commented Aug 23, 2015

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!

@yar00001

This comment has been minimized.

Copy link

yar00001 commented Jan 2, 2016

had the same problem on Ubuntu Server. As other people mentioned, just run pm2 commands as SU like sudo pm2 list

@MaffooBristol

This comment has been minimized.

Copy link

MaffooBristol commented May 15, 2016

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.

@xx4159

This comment has been minimized.

Copy link

xx4159 commented Sep 12, 2016

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...
@LightGlobal

This comment has been minimized.

Copy link

LightGlobal commented Apr 12, 2017

@struCoder it is work for me, thanks

@ccpacillos

This comment has been minimized.

Copy link

ccpacillos commented Nov 7, 2017

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.

@isrmicha

This comment has been minimized.

Copy link

isrmicha commented Jan 14, 2018

@struCoder Thanks! Solved my problem

@Keyne

This comment has been minimized.

Copy link

Keyne commented Oct 8, 2018

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

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