Skip to content
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

[bug] EACCES: permission denied, mkdir '/etc/.pm2/logs' #367

Closed
ahoiroman opened this issue Feb 17, 2022 · 8 comments
Closed

[bug] EACCES: permission denied, mkdir '/etc/.pm2/logs' #367

ahoiroman opened this issue Feb 17, 2022 · 8 comments

Comments

@ahoiroman
Copy link

Hello,

I got a little problem using soketi on Laravel Forge.

I followed this article (https://blog.laravel.com/deploying-soketi-to-laravel-forge) to configure a daemon that makes sure that soketi is always up and running.

This is the resulting daemon:

Bildschirmfoto 2022-02-17 um 09 37 15@2x

And this is the generated supervisord-config:

[program:daemon-674304]
command=soketi start --config=/home/forge/soketi.json

process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
user=forge
numprocs=1
startsecs=1
redirect_stderr=true
stdout_logfile=/home/forge/.forge/daemon-674304.log
stopwaitsecs=60
stopsignal=SIGINT
stopasgroup=true
killasgroup=true

Now I am getting this error on startup:

[PM2][Initialization] Environment variable HOME (Linux) or HOMEPATH (Windows) are not set!
[PM2][Initialization] Defaulting to /etc/.pm2
Error: EACCES: permission denied, mkdir '/etc/.pm2/logs'
    at Object.mkdirSync (fs.js:1013:3)
    at mkdirpNativeSync (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/lib/mkdirp-native.js:29:10)
    at Function.mkdirpSync [as sync] (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/index.js:21:7)
    at module.exports.Client.initFileStructure (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:133:25)
    at new module.exports (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:38:8)
    at new API (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/API.js:108:19)
    at Object.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
Error: EACCES: permission denied, mkdir '/etc/.pm2/pids'
    at Object.mkdirSync (fs.js:1013:3)
    at mkdirpNativeSync (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/lib/mkdirp-native.js:29:10)
    at Function.mkdirpSync [as sync] (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/index.js:21:7)
    at module.exports.Client.initFileStructure (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:141:25)
    at new module.exports (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:38:8)
    at new API (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/API.js:108:19)
    at Object.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
Error: ENOENT: no such file or directory, open '/etc/.pm2/module_conf.json'
    at Object.openSync (fs.js:497:3)
    at Object.writeFileSync (fs.js:1528:35)
    at module.exports.Client.initFileStructure (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:149:10)
    at new module.exports (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:38:8)
    at new API (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/API.js:108:19)
    at Object.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
Error: EACCES: permission denied, mkdir '/etc/.pm2/modules'
    at Object.mkdirSync (fs.js:1013:3)
    at mkdirpNativeSync (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/lib/mkdirp-native.js:29:10)
    at Function.mkdirpSync [as sync] (/usr/lib/node_modules/@soketi/soketi/node_modules/mkdirp/index.js:21:7)
    at module.exports.Client.initFileStructure (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:157:25)
    at new module.exports (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Client.js:38:8)
    at new API (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/API.js:108:19)
    at Object.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
Error: ENOENT: no such file or directory, open '/etc/.pm2/module_conf.json'
    at Object.openSync (fs.js:497:3)
    at Object.readFileSync (fs.js:393:35)
    at Object.Configuration.getAllSync (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Configuration.js:299:26)
    at Object.Configuration.getSync (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/Configuration.js:270:30)
    at new API (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/lib/API.js:117:44)
    at Object.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/pm2/index.js:11:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)

Any help or hint is highly appreciated :-)

@rennokki
Copy link
Member

You may want to run it as root or see this fix: Unitech/pm2#487

@rennokki rennokki changed the title Problem on Laravel Forge: Environment variable HOME (Linux) or HOMEPATH (Windows) are not set [bug] Environment variable HOME (Linux) or HOMEPATH (Windows) are not set Feb 17, 2022
@rennokki rennokki pinned this issue Feb 17, 2022
@rennokki rennokki changed the title [bug] Environment variable HOME (Linux) or HOMEPATH (Windows) are not set [bug] EACCES: permission denied, mkdir '/etc/.pm2/logs' Feb 17, 2022
@Christophvh
Copy link

I got the same issue and I solved it by specifying the forge directory to an actual site directory.

@ahoiroman
Copy link
Author

Hi Christoph,

thanks for your update. I got a question about that: What do you mean with "specifying the forge director to an actual site directory"? The "forge directory" should be /home/forge, right?

So did you set the working directory in Laravel Forge to /home/forge/default, as it's the site-dir for the user?

@Christophvh
Copy link

Hi Christoph,

thanks for your update. I got a question about that: What do you mean with "specifying the forge director to an actual site directory"? The "forge directory" should be /home/forge, right?

So did you set the working directory in Laravel Forge to /home/forge/default, as it's the site-dir for the user?

I run soketi on the same server as my project, so maybe this doesn't work for you but since soketi is global it can run from all the directories, but it seems that somehow subdirectories from 'sites' have different permissions. so for example I have a site: 'example.com', i run this command only for the directory '/home/forge/example.com' . That fixed it for me, but changing it to the 'root' user instead of forge also works!

@mzainzulifqar
Copy link

Try this

sudo -u forge soketi start --config=/home/forge/config.json

@Diz-X
Copy link

Diz-X commented Jul 3, 2022

You may want to run it as root or see this fix: Unitech/pm2#487

Running as root is BAD security practice.

This issue is not a soketi problem, more a pm2 problem.

I use supervisord to monitor and control the soketi processes. To fix the issue with supervisord, you should add the following to you supervisord config:

[program:soketi]
...
environment=HOME="/home/soketi"

In this case I created a user called "soketi" with nologin and with a home directory.

Edit:

Correct me if I am wrong, but you should be able to add the envoirment path in front of the command like:

HOME="/home/soketi" soketi start

@rennokki
Copy link
Member

Gonna close this up. @Diz-X's solution is working to me too.

@MaksOn-dev
Copy link

Thanks @Diz-X's, I finally solved my problem.

Note for others: if you do not get rid of this errors Soketi can work unstable. From time-to-time my events haven't been received by frontend thought it was sent from backend. I didn't understand why it happening until fixed this issues

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

No branches or pull requests

6 participants