In a Redmine container based on an official image on Docker Hub, I am trying to set up a cron job to send reminder e-mails periodically.
As instructed here, typing bundle exec rake redmine:send_reminders RAILS_ENV=production
as root
inside the container works fine. However, setting the same command using crontab -e
does not work and outputs various error messages. I suspect that they have something to do with setting correct PATH
for Bundler or rake, but not being familiar with Ruby apps I am totally lost right now. I even tried adding (seemingly) relevant environment variables to crontab
such that:
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
but so far to no avail.
The followings are what I've tried adding on crontab -e
so far. Each commands are (of course) preceded by cron's date time string format, and trailed by > /var/log/myjob.log 2>&1
to log whatever it outputs.
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
(The following script)
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>'
Here is what is inside /usr/src/redmine
. A file named Gemfile
exists.
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
What is the correct command ?