public
Last active

Reboot example with forever

  • Download Gist
forever_crontab_reboot_example.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
crontab.load(function(err, tab) {
require('npm').load(function (err, npm) {
if (err) { console.log(err); process.exit(1); }
var path = require('path');
var util = require('util');
var uuid = '322ed3d0-6869-11e1-b86c-0800200c9a66';
var npmPrefix = npm.config.get('prefix');
var npmBinRoot = path.join(npmPrefix, 'bin');
var nodePath = process.execPath.split('/').slice(0, -1).join('/');
var exportCommand = 'export PATH=' + nodePath + ':$PATH';
var foreverCommand = path.join(npmBinRoot, 'forever');
var thisCommand = __filename;
var sysCommand = util.format('%s && %s start %s', exportCommand, foreverCommand, thisCommand);
tab.remove(tab.findComment(uuid));
if (install == true) {
tab.create(sysCommand, uuid).everyReboot();
}
tab.save();
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.