Skip to content

Instantly share code, notes, and snippets.

@dachev
Created January 3, 2011 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dachev/763076 to your computer and use it in GitHub Desktop.
Save dachev/763076 to your computer and use it in GitHub Desktop.
Reboot example with forever
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();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment