here is my node program
var fs = require('fs'); fs.writeFileSync('./data.txt', 'test');
it is in /home/test/ and the test directory ‘s privilege is rwxrwxrwx. when i run node test.js with the tomcat account, the data.txt could be created.
but when i run a service to execute su tomcat -c ‘node /home/test/test.js’, the data.txt could not be created and there is a permission denied hint in the stdout.
sudo service test
here is my service in /etc/init.d
su tomcat -c 'node /home/test/test.js'
can anyone tell me why
Advertisement
Answer
It could be several things. For example, the current directory isn’t /home/test when running from init.d.
I recommend piping the output of stderr and stdout to a log file to a specific (not relative) area that allows writing (e.g. /var/log).