Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicate fetch commits cronjobs #50

Closed
b-a-t opened this issue Oct 16, 2014 · 1 comment
Closed

Avoid duplicate fetch commits cronjobs #50

b-a-t opened this issue Oct 16, 2014 · 1 comment

Comments

@b-a-t
Copy link

b-a-t commented Oct 16, 2014

I've make some changes to the docker-redmine container and commited changes to the new image to save my work under new tag. After starting this altered image I've noticed, that REDMINE_FETCH_COMMITS was duplicated in the crontab. And after second commit I actually got three same commands in the crontab...

I think it's reasonable to grep current crontab for the presence of the line which is going to be (re)added. Here is the way I've implemented it:

--- a/assets/init
+++ b/assets/init
@@ -428,14 +428,18 @@ if [ -d ${DATA_DIR}/themes ]; then
 fi

 # create a cronjob to periodically fetch commits
+REDMINE_CRONJOB_FILE=/tmp/cron.redmine
 case "${REDMINE_FETCH_COMMITS}" in
   hourly|daily|monthly)
     set +e
-    crontab -u redmine -l 2>/dev/null >/tmp/cron.redmine
+    crontab -u redmine -l 2>/dev/null >${REDMINE_CRONJOB_FILE}
     set -e
-    echo "@${REDMINE_FETCH_COMMITS} cd /home/redmine/redmine && ./script/rails runner \"Repository.fetch_changesets\" -e production >> log/cron_rake.log 2>&1" >>/tmp/cron.redmine
-    crontab -u redmine /tmp/cron.redmine 2>/dev/null
-    rm -rf /tmp/cron.redmine
+    REDMINE_FETCH_CRONJOB="@${REDMINE_FETCH_COMMITS} cd /home/redmine/redmine && ./script/rails runner \"Repository.fetch_changesets\" -e production >> log/cron_rake.log 2>&1"
+    if ! fgrep "${REDMINE_FETCH_CRONJOB}" ${REDMINE_CRONJOB_FILE} >/dev/null; then
+       echo "${REDMINE_FETCH_CRONJOB}" >>${REDMINE_CRONJOB_FILE}
+       crontab -u redmine ${REDMINE_CRONJOB_FILE} 2>/dev/null
+    fi
+    rm -f ${REDMINE_CRONJOB_FILE}
     ;;
 esac


That should fix the problem.

@sameersbn
Copy link
Owner

@b-a-t yep.. As you have rightly pointer out this need to be fixed.

edit: just need to move that codeblock before the plugins install block and we should be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants