I'm running some node.js scripts with forever
.
I started them as www-data
user (i.e. via ssh logging as www-data@server and typing forever start myapp.js
, etc.).
Ok, everything goes like a charm; my application works as expected, and typing forever list
shows me the processes running.
Then, I wrote a (very simple) script named foreverList.sh
and placed in folder /var/www/scripts/
:
#!/bin/bash
echo "checking running node.js scripts:"
forever list
When I execute the script from shell as www-data
user, it works. Nothing fancy here. But, this script is to be used with PHP 5.6 through Apache 2.4, with :
<?php
// ....
$resp_script = shell_exec("/var/www/scripts/foreverList.sh 2>&1");
echo "<pre>$resp_script</pre>";
And when I execute it via my web browser (so with the PHP code above), it doesn't work!! I get this forever
error message (nodejs, not php):
/usr/lib/node_modules/forever/lib/forever.js:674
procs.forEach(function (proc) {
^
TypeError: Object Error: EACCES, permission denied '/root/.forever/sock' has no method 'forEach'
...
... #(stack trace follows)
I really don't understand why it deals with /root folder, as I'm running all this stuff from /var/www/ folder and as www-data
user (added a whoami
in the script to check it was the case, and it does).
Do I miss something? Is it a forever bug?
Any help will be much appreciated.
UPDATE : I tried to add echo $HOME
in the bash script, and it returns nothing. Does PHP itself erase the home path environment variable of www-data
user?
~/.forever/
. Maybe (wild guess here) www-data doesn't have a homedir configured so it reverts to root's homedir? What's the homedir for your www-data user (try:getent passwd www-data | cut -d: -f6
)? Do you use a config.json and are there some clues to this behaviour?/var/www
. It also has a.forever
dir in there, with aconfig.json
file and all logs files of the running processes.