redmine
redmine copied to clipboard
RedmineReceivingEmails and the cronjob
Following the guide here: http://www.redmine.org/projects/redmine/wiki/RedmineReceivingEmails Using the approach 'fetching emails from an IMAP server' and that is working great. My project is here: https://github.com/DINA-Web/redmine-docker/tree/task760 I have created a script with the 'rake'-command to harvest my mailbox : receive_imap.sh with the following content
#!/bin/bash
source .env
echo "Mail $(date)" >>/var/log/cron-mail.log 2>&1 && rake -f /usr/src/redmine/Rakefile redmine:email:receive_imap RAILS_ENV=production host=imap.gmail.com port=993 ssl=1 username=$user password=$psw project=myproject tracker=Support
The user and the psw are in the .env-file running the script manually works fine and an issue is created in my project 'myproject'.
The entry in the crontab (root account ) is like this >
* * * * * /usr/src/redmine/mail-script/receive_imap.sh
For the sake of testing I am running it right now every minute. The only thing that I am seeing is the /var/log/cron-mail.log - no 'harvesting of my mailbox'.
Summary Being new to Ruby. One thing I see is that the crontab cannot find the environment for Ruby, it says it cannot find rake version 12. As I understand this, this question boils down to 'the environment variables are not present with me when running crontab' - I tried to copy every environmental variable for root to a file and running source on that file when starting the script, but this does not help.
regards, Ingimar
@yosifkit Hello, this docker does not have a planned mission environment, so http://www.redmine.org/projects/redmine/wiki/RedmineReminderEmails can not be done , I need your help, thank you very much .
I have the same issue, any progress on this?
Yep, need some nice way to add cron jobs! E-mail fetfer and regular notifications...
Hi
I have just done this using the rufus-scheduler method and it appears to work fine.
It requires that you create your own Docker image, but really this is required if you are adding any plugins or to configure your outbound email settings.
My Dockerfile looks like this:
FROM redmine:3.4
ENV TZ=Europe/Dublin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /usr/src/redmine
COPY plugins plugins/
COPY configuration.yml config/configuration.yml
RUN gem install rufus-scheduler
COPY getmail.rb config/initializers/getmail.rb
RUN echo "gem 'rufus-scheduler'" >> Gemfile
RUN bundle install --without development test
The getmail.rb then configures rufus-scheduler:
require 'rubygems'
require 'rake'
require 'rufus-scheduler'
load File.join(Rails.root, 'Rakefile')
ENV['host']='imap.gmail.com'
ENV['port']='993'
ENV['ssl']='SSL'
ENV['username']='[email protected]'
ENV['password']='mypassword'
ENV['project']='support'
scheduler = Rufus::Scheduler.new
# Check emails every 10 mins
scheduler.interval '10m' do
task = Rake.application['redmine:email:receive_imap']
task.reenable
task.invoke
end
In the getmail.rb, you can set any of the receive email parameters using ENV , like default-group and project_from_subaddress, etc.
Hope this helps.
-Barry Flanagan
Hi everybody, finally I decided to handle all cron jobs via another external container, here is something interesting: http://deck-chores.readthedocs.io/en/stable/index.html
Why? Coz our production server is getting more and more containers I need one centralized place for managing cron jobs. One, place, easy to read and configure, no need to manually adjust each of the containers.
I used @flantel 's approach with the rufus-scheduler using the docker image for redmine 4.0. I had the issue that Redmine:IMAP was not found and I got following ruby error:
rufus-scheduler intercepted an error:
redmine_1 | 47305684005800 job:
redmine_1 | 47305684005800 Rufus::Scheduler::EveryJob "30s" {}
redmine_1 | 47305684005800 error:
redmine_1 | 47305684005800 47305684005800
redmine_1 | 47305684005800 NameError
redmine_1 | 47305684005800 uninitialized constant Redmine::IMAP
Same with POP3.
I solved this by an additional import in the rufus-scheduler script (getmail.rb in the example above):
require 'redmine/imap.rb'
If you do not want to create your own Docker image you could also add a cronjob on the host.
Create the script /home/user/docker/redmine/receive_imap.sh
with the content below:
#!/bin/bash
docker container exec -i docker_redmine_1 rake -f /usr/src/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" host=imap.yourmail.org [email protected] password=secret starttls=1 >> /tmp/receive_imap.log 2>&1
Where docker_redmine_1
is your container's name which you can retrieve using docker container ls
Make the script executable:
chmod u+x /home/user/docker/redmine/receive_imap.sh
Edit the crontab of the user which is running the container:
crontab -e
...and add this line to execute your script
* * * * * /home/user/docker/redmine/receive_imap.sh >> /tmp/cron.log 2>&1
This will execute every minute.
Hi there! Im having an issue in this line I think. Im getting pretty crazy currently. Got the feeling that I miss something really simple :D Would be very thankful for any help. Maybe I should add rufus to a Dockerfile like its done above?
Currently wanted to setup with cron. But Im constantly getting this error:
rake aborted! OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
Opened this issue on this subject: https://github.com/docker-library/redmine/issues/232
https://github.com/docker-library/redmine/issues/64#issuecomment-636474108
If you do not want to create your own Docker image you could also add a cronjob on the host.
I am unsure this would work if the container is inside a Kubernetes cluster which could change machine in each restart or, mostly, if the cluster is managed in the cloud such as ECS by AWS.
I have some proposals of changes to fix the issue permanently:
- install
cron
,logrotate
andsupervisor
- create a
supervisor
task for cron (cron -f
) running asroot
andrails
running asredmine
- current
docker-entrypoint.sh
would be removed from the Dockerfile and be put as command of execution inrails
task atsupervisor
- the old
docker-entrypoint.sh
could be modified changing its name and either:- replacing
isLikelyRedmine
to check onsupervisor
task filenames (for rails, rake, etc) - or just passing the correct parameter to run Redmine itself
- in both cases, the function to re-execute as
redmine
user would be removed as it would be already being executed as that by thesupervisor
task configuration
- replacing
- create
logrotate
configuration forsupervisor
logs - optionally install
rsyslog
and create its correspondingsupervisor
task to checkcron
jobs execution logs
I have the following questions:
- where are you installing extra dependencies after changing to
redmine
user? The fact that is not atGEM_HOME
makes it more difficult to runcron
jobs unless I create a 1-time not-autostarted not-restartedsupervisor
task forredmine
user and calls it fromcron
- is there a way to setup a global place to install the dependencies or is this a Redmine requirement? Just a mix of global (fixed place) and local dependencies (somewhere but knowing by execution model and
.bundle
cache that it is done atredmine
user seems very messy
Unfortunately, an image using "supervisor" (or a similar multi-process init replacement) is not going to be acceptable as part of the Docker Official Images program that this image is part of.
I am unsure to understand. supervisor
, in contrast to the average init
system, is focused in a custom control from user/administrator side as it is thought to even be running on top of a real init
system but which works perfectly in Docker images for tasks like this.
@tianon Recently, I have seen that Nextcloud allows 3 options for scheduled tasks at their side.
The first being AJAX requests while loading the frontend and the second being using an external scheduled request call a PHP script which performs the tasks internally.
This last option could be something that Redmine could implement I guess. Given that this is more important for get it working properly on Docker, I guess this should be performed at this side?
A little endpoint in RubyOnRails to make the tasks after getting a scheduled curl request?
I submitted an issue at https://www.redmine.org/issues/38226 anyways to cover both sides in the case is preferable to be implemented by upstream.
I too am opposed to the inclusion of cron, logrotate, and supervisor. The latest version finally got rid of all the detritus involved in using passenger.
The inclusion of an in-Rails scheduler fits more with Docker's "single-process-per-container" design pattern. Would love to see rufus-scheduler or something similar included as part of the base image so we can still run the stock official image.
@petiepooo the proposal I made to the Redmine team is quite different already.
Maybe you could appreciate it since it is what Nextcloud uses optionally.
@EchedeyLR If I am reading #38226 correctly, your solution would still require an external app (like curl or cron) to launch the RAKE task. I would prefer puma launch periodic tasks directly per flantel's solution using rufus-scheduler.
As for an AJAX or REST interface to create/manage/launch tasks, I am not opposed, but don't need that functionality myself. What I am opposed to is running multiple processes within a single docker container. Requiring supervisor or tini in an image should be avoided, IMHO.
The problem with Rufus scheduler is that would likely behave the same as the cron proposal (basically, every single node of the instance would have its own scheduler being called and sending a notification for each node) in HA setups, which may be a big problem.