bash - Why isn't stdout set after executing a child process in a node.js script that's running as a daemon? -
this works expected if run command line (node index.js). when execute node.js (v0.10.4) script daemon init.d script stdout return value in exec callback not set. how fix this?
node.js script:
var exec = require('child_process').exec; setinterval(function() { exec('get_switch_state', function(err, stdout, stderr) { if(stdout == "on") { // something. } }); }, 5000);
init.d script:
#!/bin/bash node=/development/nvm/v0.10.4/bin/node server_js_file=/home/blahname/app/index.js user=root out=/home/pi/nodejs.log case "$1" in start) echo "starting node: $node $server_js_file" sudo -u $user $node $server_js_file > $out 2>$out & ;; stop) killall $node ;; *) echo "usage: $0 (start|stop)" esac exit 0
i ended not using node.js exec child_process. modified init.d script above (/etc/init.d/node-app.sh) follows:
#!/bin/bash node=/home/pi/development/nvm/v0.10.4/bin/node server_js_file=/home/pi/development/mysql_test/index.js user=pi out=/home/pi/development/mysql_test/nodejs.log case "$1" in start) echo "starting node: $node $server_js_file" sudo -u $user tz='pst' $node $server_js_file > $out 2>$out & ;; stop) killall $node ;; *) echo "usage: $0 (start|stop)" esac exit 0
this script launches node.js app "index.js" @ boot , everthing works expected.
Comments
Post a Comment