Better docker support
parent
00103f46c6
commit
39b6b99f4d
|
@ -0,0 +1,2 @@
|
||||||
|
node_modules
|
||||||
|
.git
|
|
@ -18,6 +18,9 @@ ENV HOST 0.0.0.0
|
||||||
|
|
||||||
ENV PORT 8000
|
ENV PORT 8000
|
||||||
|
|
||||||
|
ENV CRON_PATH /tmp
|
||||||
|
ENV CRON_IN_DOCKER true
|
||||||
|
|
||||||
EXPOSE $PORT
|
EXPOSE $PORT
|
||||||
|
|
||||||
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
|
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
|
||||||
|
|
24
crontab.js
24
crontab.js
|
@ -1,7 +1,14 @@
|
||||||
/*jshint esversion: 6*/
|
/*jshint esversion: 6*/
|
||||||
//load database
|
//load database
|
||||||
var Datastore = require('nedb');
|
var Datastore = require('nedb');
|
||||||
|
var path = require("path");
|
||||||
var db = new Datastore({ filename: __dirname + '/crontabs/crontab.db' });
|
var db = new Datastore({ filename: __dirname + '/crontabs/crontab.db' });
|
||||||
|
var cronPath = "/tmp";
|
||||||
|
|
||||||
|
if(process.env.CRON_PATH !== undefined) {
|
||||||
|
console.log(`Path to crond files set using env variables ${process.env.CRON_PATH}`);
|
||||||
|
cronPath = process.env.CRON_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
db.loadDatabase(function (err) {
|
db.loadDatabase(function (err) {
|
||||||
if (err) throw err; // no hope, just terminate
|
if (err) throw err; // no hope, just terminate
|
||||||
|
@ -76,9 +83,9 @@ exports.set_crontab = function(env_vars, callback){
|
||||||
}
|
}
|
||||||
tabs.forEach(function(tab){
|
tabs.forEach(function(tab){
|
||||||
if(!tab.stopped) {
|
if(!tab.stopped) {
|
||||||
let stderr = "/tmp/" + tab._id + ".stderr";
|
let stderr = path.join(cronPath, tab._id + ".stderr");
|
||||||
let stdout = "/tmp/" + tab._id + ".stdout";
|
let stdout = path.join(cronPath, tab._id + ".stdout");
|
||||||
let log_file = exports.log_folder + "/" + tab._id + ".log";
|
let log_file = path.join(exports.log_folder, tab._id + ".log");
|
||||||
|
|
||||||
if(tab.command[tab.command.length-1] != ";") // add semicolon
|
if(tab.command[tab.command.length-1] != ";") // add semicolon
|
||||||
tab.command +=";";
|
tab.command +=";";
|
||||||
|
@ -99,7 +106,7 @@ exports.set_crontab = function(env_vars, callback){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tab.mailing && JSON.stringify(tab.mailing) != "{}"){
|
if (tab.mailing && JSON.stringify(tab.mailing) != "{}"){
|
||||||
crontab_string += "; /usr/local/bin/node " + __dirname + "/bin/crontab-ui-mailer.js " + tab._id + " " + stdout + " " + stderr;
|
crontab_string += "; " + __dirname + "/bin/crontab-ui-mailer.js " + tab._id + " " + stdout + " " + stderr;
|
||||||
}
|
}
|
||||||
|
|
||||||
crontab_string += "\n";
|
crontab_string += "\n";
|
||||||
|
@ -109,13 +116,16 @@ exports.set_crontab = function(env_vars, callback){
|
||||||
fs.writeFile(exports.env_file, env_vars, function(err) {
|
fs.writeFile(exports.env_file, env_vars, function(err) {
|
||||||
if (err) callback(err);
|
if (err) callback(err);
|
||||||
|
|
||||||
fs.writeFile("/tmp/crontab", crontab_string, function(err) {
|
fs.writeFile(path.join(cronPath, "crontab"), crontab_string, function(err) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
|
/// In docker we're running crond using busybox implementation of crond
|
||||||
exec("crontab /tmp/crontab", function(err) {
|
/// It is launched as part of the container startup process, so no need to run it again
|
||||||
|
if(process.env.CRON_IN_DOCKER === undefined) {
|
||||||
|
exec("crontab " + path.join(cronPath, "crontab"), function(err) {
|
||||||
if (err) return callback(err);
|
if (err) return callback(err);
|
||||||
else callback();
|
else callback();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
nodaemon=true
|
nodaemon=true
|
||||||
|
|
||||||
[program:crontab]
|
[program:crontab]
|
||||||
command=crond -l 2 -f
|
command=crond -l 2 -f -c %(CRON_PATH)s
|
||||||
stderr_logfile = /var/log/crontab-stderr.log
|
stderr_logfile = /var/log/crontab-stderr.log
|
||||||
stdout_logfile = /var/log/crontab-stdout.log
|
stdout_logfile = /var/log/crontab-stdout.log
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue