1
votes

I just got a problem, I'm using the webhook for github ( I wrote one in php ).

The problem, I want to restart my nodejs app with pm2 from my php code something like that :

shell_exec("pm2 restart test");

but my user : www-data (nginx) can't execute it.. When I try it log in as www-data I got this :

Error: EACCES, permission denied '/.pm2' at Error (native) at Object.fs.mkdirSync (fs.js:747:18) at Object.CLI.pm2Init (/usr/local/lib/node_modules/pm2/lib/CLI.js:40:8) at Object. (/usr/local/lib/node_modules/pm2/bin/pm2:21:5) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16)

And I don't want to use "sudo" because it's not really clean, do you have an idea ? Thank you very much by advance :)

2
There are still situations where you want to be able to manipulate the pm2 library from a PHP API. I am dealing with the same situation right now and --watch is not an option.WilliamX

2 Answers

0
votes

Set the right HOME environment variable when running the command

$ HOME=/home/USER pm2 restart test
-1
votes

Well, I got a solution, it's fixed.

I just had to run my app with this line :

pm2 start app.js --watch

Then it's watch when a file is modified and restart it automaticly.