如何在官方 Redmine Docker 镜像中设置 cron 作业来发送提醒电子邮件?

如何在官方 Redmine Docker 镜像中设置 cron 作业来发送提醒电子邮件?

在基于Docker Hub 上的官方镜像,我正在尝试设置一个 cron 作业来定期发送提醒电子邮件。

按照指示这里,在容器内输入bundle exec rake redmine:send_reminders RAILS_ENV=productionas可以正常工作。但是,使用设置相同的命令不起作用并输出各种错误消息。我怀疑它们与Bundler 或 rake 的正确设置有关,但由于不熟悉 Ruby 应用程序,我现在完全不知所措。我甚至尝试添加(看似)相关的环境变量,以便:rootcrontab -ePATHcrontab

PATH=/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUBY_MAJOR=2.6
RUBY_VERSION=2.6.5
RUBY_DOWNLOAD_SHA256=d5d6da717fd48524596f9b78ac5a2eeb9691753da5c06923a6c31190abe01a62
GEM_HOME=/usr/local/bundle
BUNDLE_SILENCE_ROOT_WARNING=1
BUNDLE_APP_CONFIG=/usr/local/bundle
RAILS_ENV=production
HOME=/home/redmine
REDMINE_VERSION=4.1.0

但至今无果。

以下是我crontab -e迄今为止尝试添加的内容。每个命令(当然)前面都有 cron 的日期时间字符串格式,后面跟着用于> /var/log/myjob.log 2>&1记录其输出的内容。

  • root cd /usr/src/redmine; bundle exec rake redmine:send_reminders RAILS_ENV=production
  • root cd /usr/src/redmine; /usr/local/bin/bundle exec /usr/local/bundle/bin/rake redmine:send_reminders RAILS_ENV=production

Could not locate Gemfile or .bundle/ directory

  • cd /usr/src/redmine; /usr/local/bin/bundle exec /usr/local/bundle/bin/rake redmine:send_reminders RAILS_ENV=production
  • /usr/src/redmine/remind.sh(以下脚本)

remind.sh

#!/bin/bash
cd /usr/src/redmine
bundle exec /usr/local/bundle/bin/rake redmine:send_reminders days=7 RAILS_ENV="production"
bundler: failed to load command: /usr/local/bundle/bin/rake
(/usr/local/bundle/bin/rake) Bundler::GemNotFound: Could not find
rake-13.0.1 in any of the sources  
/usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in
materialize'   /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in
`map!'   /usr/local/lib/ruby/2.6.0/bundler/spec_set.rb:85:in
`materialize'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:170:in
`specs'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:237:in
`specs_for'   /usr/local/lib/ruby/2.6.0/bundler/definition.rb:226:in
`requested_specs'  
/usr/local/lib/ruby/2.6.0/bundler/runtime.rb:108:in `block in
definition_method'  
/usr/local/lib/ruby/2.6.0/bundler/runtime.rb:20:in `setup'  
/usr/local/lib/ruby/2.6.0/bundler.rb:107:in `setup'  
/usr/local/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'  
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in
`require'  
/usr/local/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in
`require'
  • root cd /usr/local/bundle/bin/rake; rake --trace redmine:send_reminders RAILS_ENV=production
rake aborted! No Rakefile found (looking for: rakefile, Rakefile,
rakefile.rb, Rakefile.rb)
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:698:in
`raw_load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:104:in
`block in load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in
`standard_exception_handling'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:103:in
`load_rakefile'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:82:in
`block in run'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in
`standard_exception_handling'
/usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:80:in
`run' /usr/local/lib/ruby/gems/2.6.0/gems/rake-12.3.2/exe/rake:27:in
`<top (required)>' /usr/local/bundle/bin/rake:23:in `load'
/usr/local/bundle/bin/rake:23:in `<main>'

里面的内容如下/usr/src/redmine。存在一个名为的文件Gemfile

root@975094a2b06b:/usr/src/redmine# ls -l
total 140
-rw-rw-r--  1 redmine redmine  538 Dec 20  2019 CONTRIBUTING.md
-rw-rw-r--  1 redmine redmine 2937 Dec 20  2019 Gemfile
-rw-rw-rw-  1 redmine redmine 5665 Apr 21  2020 Gemfile.lock
-rw-r--r--  1 root    root    5491 Feb 27  2020 Gemfile.lock.mysql2
-rw-r--r--  1 root    root    5483 Feb 27  2020 Gemfile.lock.postgresql
-rw-r--r--  1 root    root    5493 Feb 27  2020 Gemfile.lock.sqlite3
-rw-r--r--  1 root    root    5645 Feb 27  2020 Gemfile.lock.sqlserver
-rw-rw-r--  1 redmine redmine  205 Dec 20  2019 README.rdoc
-rwxrwxr-x  1 redmine redmine  275 Dec 20  2019 Rakefile
drwxrwxr-x  6 redmine redmine 4096 Dec 20  2019 app
-rw-rw-r--  1 redmine redmine  863 Dec 20  2019 appveyor.yml
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 bin
drwxr-xr-x  1 redmine redmine 4096 Mar 26  2020 config
-rw-r--r--  1 root    root     136 Mar 10  2020 config.ru
drwxrwxrwx  1 redmine redmine 4096 Mar 26  2020 db
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 doc
drwxrwxr-x  5 redmine redmine 4096 Dec 20  2019 extra
drwxr-xr-x  3 redmine redmine 4096 Oct 19 10:16 files
drwxrwxr-x  6 redmine redmine 4096 Dec 20  2019 lib
drwxr-xr-x  2 redmine redmine 4096 Mar 18  2020 log
drwxr-xr-x  5 redmine redmine 4096 Mar 26  2020 plugins
drwxrwxr-x  1 redmine redmine 4096 Dec 20  2019 public
-rwxr-xr-x  1 root    root     125 Dec 17 16:24 remind.sh
drwxrwxrwx  2 redmine redmine 4096 Feb 27  2020 sqlite
drwxrwxr-x 14 redmine redmine 4096 Dec 20  2019 test
drwxr-xr-x  1 redmine redmine 4096 Feb 27  2020 tmp
drwxrwxr-x  2 redmine redmine 4096 Dec 20  2019 vendor

正确的命令是什么?

答案1

事实证明克伦德包括在忙碌盒子bundle exec rake...可以毫无问题地运行命令。也许它处理环境变量的方式与标准 crond 不同?

我所要做的就是

apt-get install busybox-static
busybox crontab -e

然后将以下作业添加到 crontab 的列表中。

0 7 * * 1-5 cd /usr/src/redmine; bundle exec rake redmine:send_reminders RAILS_ENV=production

请注意,目前,这些步骤是在正在运行的 Redmine 容器内手动完成的。我Dockerfile稍后会添加这些内容。

相关内容