You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
//load database
|
|
|
|
var Datastore = require('nedb');
|
|
|
|
var db = new Datastore({ filename: __dirname + '/crontabs/crontab.db' });
|
|
|
|
db.loadDatabase(function (err) {
|
|
|
|
});
|
|
|
|
var exec = require('child_process').exec;
|
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
crontab = function(command, schedule, stopped){
|
|
|
|
var data = {};
|
|
|
|
data.command = command;
|
|
|
|
data.schedule = schedule;
|
|
|
|
data.stopped = stopped;
|
|
|
|
data.timestamp = (new Date()).toString();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.create_new = function(command, schedule){
|
|
|
|
var tab = crontab(command, schedule, false);
|
|
|
|
db.insert(tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.crontabs = function(callback){
|
|
|
|
db.find({}, function(err, docs){
|
|
|
|
callback(docs);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.set_crontab = function(){
|
|
|
|
exports.crontabs( function(tabs){
|
|
|
|
var crontab_string = "";
|
|
|
|
tabs.forEach(function(tab){
|
|
|
|
if(!tab.stopped){
|
|
|
|
crontab_string += tab.schedule + " " + tab.command + "\n";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
fs.writeFile("/tmp/crontab", crontab_string, function(err) {
|
|
|
|
//couldnt write
|
|
|
|
});
|
|
|
|
|
|
|
|
exec("crontab /tmp/crontab");
|
|
|
|
});
|
|
|
|
}
|