【问题标题】:How to properly set up Capistrano 3 with Rails 4?如何使用 Rails 4 正确设置 Capistrano 3?
【发布时间】:2015-02-24 10:20:28
【问题描述】:

我尝试为 Rails 4 应用程序安装 Capistrano 3 已经 2 天了,我的头发已经变白了...

问题是我无法将代码部署到服务器(Ubuntu 14,nginx,在 DigitalOcean 上运行)。

这是我的配置: Gemfile:

gem 'capistrano', '~> 3.1.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'capistrano-bundler'
gem 'unicorn'

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'

 require 'capistrano/bundler'
 require 'capistrano/rails/assets'
 require 'capistrano/rails/migrations'

# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }                                                                                                                                      
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }

deploy.rb:

set :application, 'project'
set :deploy_user, 'deployer'

set :scm, :git
set :repo_url, 'git@bitbucket.org:username/project.git"'

set :pty, true
set :use_sudo, false

set :keep_releases, 5
set :linked_files, %w{config/database.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

set(:symlinks, [
  {
    source: "nginx.conf",
    link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
  },
  {
    source: "unicorn_init.sh",
    link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
  },
  {
    source: "log_rotation",
   link: "/etc/logrotate.d/#{fetch(:full_app_name)}"
  },
  {
    source: "monit",
    link: "/etc/monit/conf.d/#{fetch(:full_app_name)}.conf"
  }
])

namespace :deploy do
  before :deploy, "deploy:check_revision"
  before :deploy, "deploy:run_tests"
  #after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
  after :finishing, 'deploy:cleanup'
  before 'deploy:setup_config', 'nginx:remove_default_vhost'
  after 'deploy:setup_config', 'nginx:reload'
  after 'deploy:setup_config', 'monit:restart'
  after 'deploy:publishing', 'deploy:restart'
end

config/deploy/production.rb:

set :stage, :production
set :branch, "master"

set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
set :server_name, "IP"

server 'IP', user: 'deployer', roles: %w{web app db}, primary: true
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"

set :rails_env, :production
set :unicorn_worker_count, 5
set :enable_ssl, false

当我尝试设置 capistrano 并运行 cap production deploy:setup_config 时,我得到以下输出:

/Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.6.5/lib/bundler.rb:301: warning: Insecure world writable dir /usr/local/mysql-5.6.13-osx10.7-x86_64 in PATH, mode 040777
DEBUG [d940e414] Running /usr/bin/env [ -f /etc/nginx/sites-enabled/default ] as deployer@IP
DEBUG [d940e414] Command: [ -f /etc/nginx/sites-enabled/default ]
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
deployer@188.166.53.247's password: # HERE I PUT MY PASSWORD, BUT WHEN I TYPE IT, I SEE WHAT I TYPE (THE PASSWORD IS NOT HIDDEN)
DEBUG [d940e414] Finished in 28.324 seconds with exit status 0 (successful).
INFO [cba64b02] Running /usr/bin/env sudo rm /etc/nginx/sites-enabled/default as deployer@IP
DEBUG [cba64b02] Command: /usr/bin/env sudo rm /etc/nginx/sites-enabled/default
DEBUG [cba64b02]    [sudo] password for deployer:

这里卡住了——什么也没发生。不管我做什么(如果我输入一些东西/密码)——它卡在这里超过 30 分钟。

我可以请你们帮我解决这个问题吗,伙计们?

非常感谢您,我不知道如何在此处继续。

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 nginx capistrano3


    【解决方案1】:

    看来您配置为在deploy:setup_config 尝试使用sudo 执行rm 之前运行的nginx:remove_default_vhost 任务。 Capistrano 3 需要设置无密码 sudo,否则会出现您所描述的症状。参见documentation的授权部分。

    设置deployer 用户以在没有密码的情况下使用sudo 执行rm应该让事情进展顺利,但在你这样做之前,我认为值得一问:你真的想要你的部署者用户能够在没有密码的情况下以 root 身份删除任意文件吗?我不清楚该任务的起源是什么,但恕我直言,它更像是 privisioning 的一部分而不是 deployment 并且还有其他工具比 capistrano 更适合配置(厨师、木偶等)。或者只是 SSH 到您的服务器并将其删除。只需执行一次。

    如果您确实决定让您的部署用户在没有密码的情况下使用 sudo 执行 rm,请记住使用 visudo 并且不要直接编辑 /etc/sudoers

    【讨论】:

      猜你喜欢
      • 2014-11-10
      • 2012-11-09
      • 2014-06-24
      • 2019-06-09
      • 2013-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多