【发布时间】:2014-12-09 21:06:32
【问题描述】:
我在 RVM 上使用 jruby 实施 Capistrano 部署时遇到问题。我使用 PUMA 作为应用服务器,这需要我在 Gemfile 中添加 capistrano3-puma。 总而言之,一切似乎都运行良好,我的服务器代码从 git repo 得到了最新的,并且很好地存档了以前版本的代码。 除了,每次我尝试从 Capistrano 任务运行 shell 命令时, 比如“bundle exec pumactl -F config/puma.rb start”,比如Capistrano似乎无法识别bundle命令。
我的真实案例示例如下所示,当我在覆盖的 deploy:start 方法中运行上述命令时,它返回错误“bundle: command not found”。当我通过 SSH 登录到服务器并直接从 app 文件夹启动它时,我已经测试过相同的命令可以正常工作。
jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on OpenJDK 64-Bit Server VM 1.7.0_65-b32 +jit [linux-amd64]
** Invoke deploy:start (first_time)
** Execute deploy:start
INFO[fc57a7d8] Running /usr/bin/env cd /var/appname/current && bundle exec pumactl -F config/puma.rb start on 192.168.2.6
DEBUG[fc57a7d8] Command: cd /var/appname/current && bundle exec pumactl -F config/puma.rb start
bind address:
port: 22
host: 192.168.2.6
options: {:auth_methods=>["none", "publickey", "password", "keyboard-interactive"], :send_env=>[/^LANG$/, /^LC_.*$/], :user=>"root
", :forward_agent=>true, :logger=>#<Logger:0x14c7b324 @logdev=#<Logger::LogDevice:0x42c20b24 @filename=nil, @shift_age=nil, @dev=#
<IO:fd 2>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x51698ab9 @mon_count=0, @mon_mutex=#<Mutex:0x6812a170>, @mon_owner=nil>, @s
hift_size=nil>, @formatter=nil, @progname=nil, @default_formatter=#<Logger::Formatter:0x1f24f571 @datetime_format=nil>, @level=4>}
DEBUG[fc57a7d8] ***bash: bundle: command not found***
cap aborted!
Exception while executing on host 192.168.2.6: cd /var/appname/current && bundle exec pumactl -F config/puma.rb start exi
t status: 127
cd /var/appname/current && bundle exec pumactl -F config/puma.rb start stdout: Nothing written
cd /var/appname/current && bundle exec pumactl -F config/puma.rb start stderr: Nothing written
/Users/dev/.rvm/gems/jruby-1.7.16.1@rails3.2.8/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='
/Users/dev/.rvm/gems/jruby-1.7.16.1@rails3.2.8/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `_execute'
org/jruby/RubyProc.java:271:in `call'
这是我的 Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
部署.rb
server '192.168.2.6', port: 22, roles: [:app], primary: true
set :repo_url, 'git@bitbucket.org:username/appname.git'
set :application, 'appname'
set :user, 'username'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :shared_children, []
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
set :default_shell, '/bin/bash -l'
set :pty, true
set :use_sudo, false
set :stage, :staging
set :deploy_via, :remote_cache
set :deploy_to, "/var/#{fetch(:application)}"
set :linked_dirs, %w{tmp/pids tmp/sockets log}
set :puma_bind, "unix:///#{fetch(:deploy_to)}/tmp/sockets/puma.sock"
set :puma_state, "#{fetch(:deploy_to)}/tmp/pids/puma.state"
set :puma_pid, "#{fetch(:deploy_to)}/tmp/pids/puma.pid"
set :puma_access_log, "#{fetch(:deploy_to)}/log/puma.error.log"
set :puma_error_log, "#{fetch(:deploy_to)}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, false # Change to true if using ActiveRecord
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc "Start the application"
task :start do
on "root@192.168.2.6", in: :sequence, wait: 5 do
with :rails_env => fetch(:rails_env) do
execute "cd #{current_path} && /bin/bash -l bundle exec pumactl -F config/puma.rb start"
end
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
staging.rb
set :stage, :staging
set :branch, 'master'
宝石文件
source 'http://rubygems.org'
gem 'rails', '3.2.8'
gem 'rubyzip', '< 1.0.0'
gem 'roo','1.12.1'
gem 'jdbc-mysql', platform: :jruby
gem 'activerecord-jdbcmysql-adapter', platform: :jruby
gem 'jquery-rails', '2.1.2'
gem 'haml', '3.1.7'
gem 'puma'
gem 'devise', '2.1.2'
gem 'devise-async', '0.5.0'
gem 'cancan', '1.6.8'
gem 'simple_form', '2.0.4'
gem 'cocoon', '1.1.1'
gem 'inherited_resources', '1.3.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.9'
gem 'mechanize', '2.5.1'
gem 'delayed_job', '3.0.4'
gem 'paperclip', '3.4.0'
gem 'spreadsheet', '0.6.4.1'
gem 'geocoder', '1.1.6'
gem 'whenever', '0.8.2'
gem 'american_date', '1.0.0'
gem 'money','5.1.1'
gem 'rets','0.5.1'
gem 'haversine','0.3.0'
group :assets do
gem 'stylus', '0.7.1'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.3.0'
end
group :development do
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: true
gem 'capistrano3-puma', github: 'seuros/capistrano-puma', require: false
end
任何帮助我解决问题的建议都将非常非常感谢。
更新
按照 rubish 的建议编辑代码后, 现在我发出这样的命令 => 执行“cd #{current_path} && /bin/bash -l bundle exec pumactl -F config/puma.rb start” 现在,它开始抱怨全局 rvm 路径下的捆绑程序。确切的新错误如下所示。
DEBUG[df47d6e1] Finished in 0.463 seconds with exit status 0 (successful).
jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on OpenJDK 64-Bit Server VM 1.7.0_65-b32 +jit [linux-amd64]
** Invoke deploy:start (first_time)
** Execute deploy:start
INFO[93744fc5] Running /usr/bin/env cd /var/appname/current && /bin/bash -l bundle exec pumactl -F config/puma.rb start on
192.168.2.6
DEBUG[93744fc5] Command: cd /var/appname/current && /bin/bash -l bundle exec pumactl -F config/puma.rb start
bind address:
port: 22
host: 192.168.2.6
options: {:auth_methods=>["none", "publickey", "password", "keyboard-interactive"], :send_env=>[/^LANG$/, /^LC_.*$/], :user=>"root
", :forward_agent=>true, :logger=>#<Logger:0x4c860e93 @logdev=#<Logger::LogDevice:0x7526fc24 @filename=nil, @shift_age=nil, @dev=#
<IO:fd 2>, @mutex=#<Logger::LogDevice::LogDeviceMutex:0x5273db92 @mon_count=0, @mon_mutex=#<Mutex:0x34547888>, @mon_owner=nil>, @s
hift_size=nil>, @formatter=nil, @progname=nil, @default_formatter=#<Logger::Formatter:0x15b5438f @datetime_format=nil>, @level=4>}
DEBUG[93744fc5] /usr/local/rvm/gems/jruby-1.7.16.1@global/bin/bundle: line 9: require: command not found
DEBUG[93744fc5] /usr/local/rvm/gems/jruby-1.7.16.1@global/bin/bundle: line 11: version: command not found
DEBUG[93744fc5] /usr/local/rvm/gems/jruby-1.7.16.1@global/bin/bundle: bundle: line 15: syntax error near unexpected token
`('
DEBUG[93744fc5] /usr/local/rvm/gems/jruby-1.7.16.1@global/bin/bundle: bundle: line 15: ` str = str.dup.force_encoding("BI
NARY") if str.respond_to? :force_encoding'
cap aborted!
Exception while executing on host 192.168.2.6: cd /var/appname/current && /bin/bash -l bundle exec pumactl -F config/puma.
rb start exit status: 2
cd /var/appname/current && /bin/bash -l bundle exec pumactl -F config/puma.rb start stdout: Nothing written
cd /var/appname/current && /bin/bash -l bundle exec pumactl -F config/puma.rb start stderr: Nothing written
【问题讨论】:
-
对于你的最后一个问题,你需要确保你从你的应用程序目录中调用 bundle exec 以便 RVM 可以获取 ".ruby-gemset" 和 ".ruby-version" 文件,否则它将使用您真正不想要的全局 gemset。
标签: ruby-on-rails-3 capistrano3