From 42e677d8d26d11dfc0ade2fade80fbca8c120fd5 Mon Sep 17 00:00:00 2001 From: alse Date: Mon, 8 Jun 2020 22:34:42 +0530 Subject: [PATCH] Fixing cron not updating inside docker --- Dockerfile | 5 +++-- Makefile | 2 +- crontab.js | 22 ++++++++-------------- package.json | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a08dba..76f271c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ # docker run -d -p 8000:8000 alseambusher/crontab-ui FROM alpine:3.10 -RUN mkdir /crontab-ui; touch /etc/crontabs/root; chmod +x /etc/crontabs/root +ENV CRON_PATH /etc/crontabs + +RUN mkdir /crontab-ui; touch $CRON_PATH/root; chmod +x $CRON_PATH/root WORKDIR /crontab-ui @@ -24,7 +26,6 @@ ENV HOST 0.0.0.0 ENV PORT 8000 -ENV CRON_PATH /etc/crontabs ENV CRON_IN_DOCKER true EXPOSE $PORT diff --git a/Makefile b/Makefile index fa2e750..7ac3636 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VER=0.3.9 +VER=0.3.12 release: sed -i '' "s/version\": \".*/version\": \"$(VER)\",/" package.json diff --git a/crontab.js b/crontab.js index d5c941f..5c0c1de 100644 --- a/crontab.js +++ b/crontab.js @@ -131,22 +131,16 @@ exports.set_crontab = function(env_vars, callback){ fs.writeFile(exports.env_file, env_vars, function(err) { if (err) callback(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" - } + var fileName = process.env.CRON_IN_DOCKER !== undefined ? "root" : "crontab"; 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 - if(process.env.CRON_IN_DOCKER === undefined) { - exec("crontab " + path.join(cronPath, "crontab"), function(err) { - if (err) return callback(err); - else callback(); - }); - } else { - callback(); - } + exec("crontab " + path.join(cronPath, fileName), function(err) { + if (err) { + console.error(err); + return callback(err); + } + else callback(); + }); }); }); }); diff --git a/package.json b/package.json index 2ca5f3e..36849a1 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crontab-ui", - "version": "0.3.11", + "version": "0.3.12", "description": "Easy and safe way to manage your crontab file", "main": "index.js", "scripts": {