pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

EACCES, permission denied

Open binarykitchen opened this issue 12 years ago • 17 comments

Each time I try to start an app, I get this. No idea what I should adjust in the user permissions.

I am running pm2 with the right user nodejs who owns the home directory.

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES, permission denied '/home/nodejs/.pm2/pids/www.signora.co.nz.pid10.pid'
  at Object.fs.openSync (fs.js:427:18)
  at Object.fs.writeFileSync (fs.js:966:15)
  at ProcessContainer (/opt/node-0.10.28/lib/node_modules/pm2/lib/ProcessContainer.js:30:6)
  at Object.<anonymous> (/opt/node-0.10.28/lib/node_modules/pm2/lib/ProcessContainer.js:44:3)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:906:3

binarykitchen avatar May 27 '14 06:05 binarykitchen

got same problem

return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);                 
^Error: EACCES, permission denied '/home/deploy/.pm2/pids/api.pid16.pid'  
at Object.fs.openSync (fs.js:427:18)  at Object.fs.writeFileSync (fs.js:966:15)
at ProcessContainer (/usr/local/node/lib/node_modules/pm2/lib/ProcessContainer.js:30:6)  
at Object.<anonymous> (/usr/local/node/lib/node_modules/pm2/lib/ProcessContainer.js:44:3)  
at Module._compile (module.js:456:26)  
at Object.Module._extensions..js (module.js:474:10)  
at Module.load (module.js:356:32)  
at Function.Module._load (module.js:312:12)  
at Function.Module.runMain (module.js:497:10)  
at startup (node.js:119:16)  
at node.js:906:3

ghost avatar Jun 04 '14 07:06 ghost

I was experiencing this same problem (on OS X), and the only "solution" was to open up permissions with sudo chmod -R 777 .pm2.

Is there a better solution to this issue?

jczaplew avatar Jun 04 '14 17:06 jczaplew

What about a clean install:

pm2 kill
rm -r /usr/local/lib/node_modules/pm2 #or your pm2 install dir
rm -r ~/.pm2 #or your pm2 user home dir
npm i pm2 -g

Could you check me the ~/.pm2 rights for the running user (also ~/.pm2/pids)?

Thanks!

soyuka avatar Jun 04 '14 17:06 soyuka

All good, I sorted this out myself few days ago. I was starting pm2 with the wrong user.

binarykitchen avatar Jun 05 '14 01:06 binarykitchen

Same issue here - started pm2 as a different user by merely running pm2 l to see if any processes were running.

IMO this is a pm2 issue - it should specifically check the UID of the user running the daemon and complain if it's different from the current UID (or, actually, work).

@binarykitchen, think this should be reopened?

dandv avatar Jul 21 '14 10:07 dandv

yeah, this would improve the usability of pm2

binarykitchen avatar Jul 21 '14 11:07 binarykitchen

+1 Giving a check on the uid might prevent a lot of issues that are user-related (:

soyuka avatar Jul 21 '14 16:07 soyuka

@soyuka 's comment pointed me to the right path.

I had previously installed pm2 globally, and then I was using it locally in an app. Turns out that my ~/.pm2 folder was only accessible to the root user (root created this folder when I was running pm2 globally). So I deleted ~/.pm2 folder, ran my script again, and everything worked perfectly this time.

luciomr avatar Jun 27 '17 18:06 luciomr

Using WinSCP I SFTP logged-in as root, right click the file and changed it s Group & User to my user, then set Permmissions to 777 (666 will do if you only need read & write).

davalapar avatar Feb 20 '19 22:02 davalapar

For me pm2 kill then pm2 start SERVER.JS worked for me.

DevAtCN avatar Mar 19 '21 19:03 DevAtCN

I have the similar problem still pm2 version 4.5.6 on production but I am running as ecosystem.json and this is the code on that file

  {
    "apps": [
      {
        "name": "appname",
        "script": "PORT=3002 node build",
        "instances": 1,
        "exec_mode": "fork"
      }
    ]
  }

rror: EACCES: permission denied, mkdir '/root/.pm2/logs' at Object.mkdirSync (fs.js:1009:3) at mkdirpNativeSync (/usr/lib/node_modules/pm2/node_modules/mkdirp/lib/mkdirp-native.js:29:10) at Function.mkdirpSync [as sync] (/usr/lib/node_modules/pm2/node_modules/mkdirp/index.js:21:7) at module.exports.Client.initFileStructure (/usr/lib/node_modules/pm2/lib/Client.js:133:25) at new module.exports (/usr/lib/node_modules/pm2/lib/Client.js:38:8) at new API (/usr/lib/node_modules/pm2/lib/API.js:108:19) at Object. (/usr/lib/node_modules/pm2/lib/binaries/CLI.js:22:11) at Module._compile (internal/modules/cjs/loader.js:1068:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Module.load (internal/modules/cjs/loader.js:933:32) Error: EACCES: permission denied, mkdir '/root/.pm2/pids'

mylastore avatar May 28 '21 07:05 mylastore

Same problem, someone has solution ? When I run pm2-dev start ./src/server.js no problem, but through npm cross-env NODE_PATH=./src pm2-dev start ./src/server.js doesn't work.

innovaweb-dev avatar Jun 03 '21 14:06 innovaweb-dev

I am STILL HAVING THIS ISSUE on a new ubuntu Debian 11 installation

Error: EACCES: permission denied, mkdir '/root/.pm2/logs' Error: EACCES: permission denied, mkdir '/root/.pm2/pids' Error: EACCES: permission denied, open '/root/.pm2/module_conf.json Error: EACCES: permission denied, mkdir '/root/.pm2/modules'

mylastore avatar Oct 19 '21 06:10 mylastore

I'm doing this within a docker container. While the primary init is running as root, the child process is running as the user node.

/usr/src/app # ps aux
PID   USER     TIME  COMMAND
    1 root      0:00 {docker-entrypoi} /bin/sh /usr/src/app/docker-entrypoint.dev.sh
    7 root      0:00 npm run start:dev
   18 node      0:00 node /usr/src/app/node_modules/.bin/cross-env NODE_PATH=. nodemon cluster.js
   25 node      0:00 node /usr/src/app/node_modules/.bin/nodemon cluster.js
   56 root      0:00 ash
   68 root      0:00 ps aux

To fix this, I configured the environment variable PM2_HOME to something appropriate for my application, based on this comment.

starlocke avatar Nov 26 '21 01:11 starlocke

Does someone know how this error impacts PM2?

mathias22osterhagen22 avatar Jan 25 '22 16:01 mathias22osterhagen22

I am STILL HAVING THIS ISSUE on a new ubuntu Debian 11 installation

Error: EACCES: permission denied, mkdir '/root/.pm2/logs' Error: EACCES: permission denied, mkdir '/root/.pm2/pids' Error: EACCES: permission denied, open '/root/.pm2/module_conf.json Error: EACCES: permission denied, mkdir '/root/.pm2/modules'

If you use sudo prefix, try taking it out

kurateh avatar Mar 14 '22 05:03 kurateh

On windows10 ,pm2 read shared file error ,at first, According to the big guy's description,i resolve the permission error ,meanwhile On certain machines ,new error was found ,i try to fs.stat ,get the error desc is like errno: -4094, code: 'UNKNOWN', syscall: 'stat', who can tell me how to resolve it or the problem is about what,thanks

xiaofenging avatar May 25 '22 09:05 xiaofenging