user1039304
user1039304

Reputation: 465

permission denied when using su to execute a node program

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

Upvotes: 1

Views: 347

Answers (1)

Jim Rush
Jim Rush

Reputation: 4163

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).

Upvotes: 1

Related Questions