在基于Docker Hub上的官方图像的 Redmine 容器中,我正在尝试设置一个 cron 作业以定期发送提醒电子邮件。
按照此处的说明,在容器内键入bundle exec rake redmine:send_reminders RAILS_ENV=production
as可以正常工作。root
但是,设置相同的命令 usingcrontab -e
不起作用并输出各种错误消息。我怀疑它们与PATH
为 Bundler 或 rake 设置正确有关,但不熟悉 Ruby 应用程序我现在完全迷路了。我什至尝试将(看似)相关的环境变量添加到crontab
:
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
什么是正确的命令?