这是我的 deployment.rb 文件。
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git@github.com:narhamah/gobgob-ror.git'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
现在我做了bundle exec cap production deploy
。巨大的日志后我得到了以下错误。
DEBUG [cced60a1] bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
SSHKit::Command::Failed: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host <ip-snipped>: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart exit status: 127
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stdout: bash: bundle: command not found
cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart stderr: Nothing written
[arup@gobgob-ror (master)]$
答案 0 :(得分:1)
以下是我现在解决问题的方法。我得到了Rustam A. Gasanov的帮助以使其正常运行。非常感谢!!
<强> deploy.rb 强>
# config valid only for current version of Capistrano
lock '3.4.0'
set :stage, 'production'
set :application, "gobgob-ror"
set :repo_url, 'git@github.com:narhamah/gobgob-ror.git'
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.2@gobgob'
set :rvm_binary, '~/.rvm/bin/rvm'
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/home/ubuntu/gobgob-ror'
# Default value for :scm is :git
set :scm, :git
set :branch, "master"
#set :user, "ubuntu"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :remote_cache
set :ssh_options, { user: 'ubuntu', :forward_agent => true, :port => 22, keys: ["#{ENV['HOME']}/.ssh/id_rsa"]}
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
set :pty, true
server "xx.xx.xxx.xxx", roles: [:app, :web, :db], :primary => true
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for :linked_files is []
set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
# Default value for keep_releases is 5
set :keep_releases, 5
namespace :deploy do
desc "Start the application"
task :start do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &", :pty => false
end
end
desc "Stop the application"
task :stop do
on roles => :app do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stop"
end
end
desc "Restart the application"
task :restart do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state restart"
end
end
desc "Status of the application"
task :status do
on roles(:app) do
execute "cd #{current_path} && RAILS_ENV=#{fetch(:stage)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do bundle exec pumactl -S #{shared_path}/pids/puma.state stats"
end
end
end
after "deploy", "deploy:restart"
after "deploy", "deploy:cleanup"
确认其有效的最后输出..
INFO [12d4a428] Running /usr/bin/env cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart on xx.xx.xxx.xxx
DEBUG [12d4a428] Command: cd /home/ubuntu/gobgob-ror/current && RAILS_ENV=production ~/.rvm/bin/rvm ruby-2.2.2@gobgob do bundle exec pumactl -S /home/ubuntu/gobgob-ror/shared/pids/puma.state restart
DEBUG [12d4a428] Command restart sent success
DEBUG [12d4a428]
INFO [12d4a428] Finished in 1.379 seconds with exit status 0 (successful).
[arup@gobgob-ror (master)]$
答案 1 :(得分:0)
看起来您的服务器上未安装bundler
gem。应该安装它,bundle
可以使用$PATH
可执行文件。
尝试直接在服务器上执行bundle --version
,以确定bundler
实际上已丢失。
如果是这种情况,请安装bundler
宝石,你应该好好去。或者为了实际保持自动化,您可以定义capistrano任务以检查bundle
可执行文件是否可用,并安装bundler
gem(如果它不可用)。您可以在bundler:install
任务之前执行此任务。
更新:如果您使用的是某些ruby管理器,例如rvm
或chruby
或类似的东西,则bundle
可执行文件可能无法供您的Capistrano使用部署任务。在这种情况下,您必须确保您的部署任务获得登录shell,以便执行所有这些shell脚本。