This is kind of doozy. This problem is most likely server related, and so my first call was AskUbuntu here .
I am trying to run crontab or rc.local or init.d to run the forever script on boot. He attaches the server to a port, which I can ping with some information, and launched the headless browser for me.
However, it seems that I cannot get the answer from Node.js spawn() :
var CASPER_PATH = '/home/ubuntu/dev/casperjs/bin/casperjs'; // actual binary location, not a symlink var SCRIPTS_PATH = '/home/custom_user/endpoints/server.js'; var fileName = req.body.source + '_' + req.body.type + '.coffee'; // looks like: mysource_my_scrape_type.coffee var scrapeId = 'test_scrape'; var user = 'user123'; var pass = 'pass123'; if (fs.existsSync(SCRIPTS_PATH + fileName)) { // If file is in place, spawn casperjs var sP = spawn(CASPER_PATH, [SCRIPTS_PATH + fileName, '--ssl-protocol=any', '--user='+user, '--scrapeId='+scrapeId, '--pass='+pass], { detached: true }, function (err, stdout, stderr) {}); sP.stdout.on('data', function(data) { console.log('stdout', data.toString('utf8')); }); sP.stderr.on('data', function(data) { console.log('stderr', data.toString('utf8')); }); sP.stdout.on('close', function(code) { console.log('close', code); }); res.send({ scheduled: true, key: scrapeId }); } else { res.send({ scheduled: false, error: 'Incorrect source, type or the script is missing.' }); }
Before adding PHANTOMJS_EXECUTABLE env to crontab or rc.local (it doesn't seem to matter, regardless of user level), stdout was useful:
stdout Fatal: [Errno 2] There is no such file or directory; did you install phantomjs?
close false
Now that the var environment exists, there is no output after spawn() .
Remember that Casper starts just fine if a user (of any privilege level) starts node / forever from bash.
How can I understand why spawn() not working?