-
Notifications
You must be signed in to change notification settings - Fork 728
rbenv and capistrano Notes
Elthariel edited this page Jan 23, 2017
·
8 revisions
Here are a few notes on how to get whenever to work correctly with rbenv deployed server-wide in /opt/rbenv
. This is using Capistrano 3 with capistrano rbenv integration.
Add this line in your Capfile:
require 'capistrano/rbenv'
require 'whenever/capistrano'
Add those lines to your deploy.rb
##
# Rbenv Setup
set :rbenv_custom_path, '/opt/rbenv'
set :rbenv_type, :system
set :rbenv_ruby, '2.3.2'
rbenv_prefix = [
"RBENV_ROOT=#{fetch(:rbenv_path)}",
"RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
]
set :rbenv_prefix, rbenv_prefix.join(' ')
set :rbenv_map_bins, %w(rake gem bundle ruby rails)
set :bundle_binstubs, -> { shared_path.join('bin') }
# Configure 'whenever'
vars = lambda do
"'environment=#{fetch :whenever_environment}" \
"&rbenv_root=#{fetch :rbenv_custom_path}" \
"&rbenv_version=#{fetch :rbenv_ruby}'"
end
set :whenever_variables, vars
Finally, add those lines into your schedule.rb:
set :rbenv_root, '/opt/rbenv'
set :rbenv_version, '2.3.3'
env 'RBENV_ROOT', rbenv_root
env 'RBENV_VERSION', rbenv_version
This way, whenever
will be executed with the right ruby in capistrano, and your scheduled actions will run with the right ruby version from rbenv, as specified in your capistrano config