From acc9016d39c5024fb2c48f4e1b8726cc973664dc Mon Sep 17 00:00:00 2001 From: Corey Gaspard Date: Wed, 19 Jul 2017 10:00:17 -0500 Subject: [PATCH] Using the /etc/crontabs/root file --- Dockerfile | 4 ++-- crontab.js | 8 ++++++-- supervisord.conf | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 332beaa..6f8030b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # docker run -d -p 8000:8000 alseambusher/crontab-ui FROM alpine:3.5 -RUN mkdir /crontab-ui +RUN mkdir /crontab-ui; touch /etc/crontabs/root; chmod +x /etc/crontabs/root WORKDIR /crontab-ui @@ -23,7 +23,7 @@ ENV HOST 0.0.0.0 ENV PORT 8000 -ENV CRON_PATH /crontab-ui/crontabs/ +ENV CRON_PATH /etc/crontabs ENV CRON_IN_DOCKER true EXPOSE $PORT diff --git a/crontab.js b/crontab.js index 1712cf5..4ac3640 100644 --- a/crontab.js +++ b/crontab.js @@ -115,8 +115,12 @@ exports.set_crontab = function(env_vars, callback){ fs.writeFile(exports.env_file, env_vars, function(err) { if (err) callback(err); - - fs.writeFile(path.join(cronPath, "crontab"), crontab_string, function(err) { + // In docker we're running as the root user, so we need to write the file as root and not crontab + var fileName = "crontab" + if(process.env.CRON_IN_DOCKER !== undefined) { + fileName = "root" + } + fs.writeFile(path.join(cronPath, fileName), crontab_string, function(err) { if (err) return callback(err); /// In docker we're running crond using busybox implementation of crond /// It is launched as part of the container startup process, so no need to run it again diff --git a/supervisord.conf b/supervisord.conf index 9612d17..4a34530 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -2,7 +2,7 @@ nodaemon=true [program:crontab] -command=crond -l 2 -f -c %(CRON_PATH)s +command=crond -l 2 -f -c %(ENV_CRON_PATH)s stderr_logfile = /var/log/crontab-stderr.log stdout_logfile = /var/log/crontab-stdout.log