【问题标题】:Capistrano deploy with thin serversCapistrano 部署与瘦服务器
【发布时间】:2011-08-26 11:47:02
【问题描述】:

一直在使用 Capistrano 在我的服务器和我的开发机器之间进行自动部署。我几乎已经配置好了,只是 Capistrano 似乎无法使用 bundle exec 命令启动我的服务器。我总是收到以下错误:

编辑:配置文件现在位于 /var/www/apps/current/thin.yml

... * 执行“sudo -p 'sudo 密码:' bundle exec thin start -C /var/www/thin.config.yml” 服务器:[“85.255.206.157”] [85.255.206.157] 执行命令 ** [out :: 85.255.206.157] 找不到 Gemfile 命令在 216 毫秒内完成 失败:“sh -c 'sudo -p '\\''sudo 密码:'\\'' bundle exec thin start -C /var/www/thin.config.yml'” on 85.255.206.157

只复制了最后一个相关的部分。文件等的整个复制工作正常。它只是启动似乎失败的集群。 这是我处理所有 Capistrano 内容的 deploy.rb 文件:

编辑:文件已修改为以下内容:

require "bundler/capistrano"

# define the application and Version Control settings
set :application, "ESCO Matching Demo"
set :repository,  "svn://192.168.33.70/RubyOnRails/ESCO"
set :deploy_via, :copy

# Set the login credentials for Capistrano
set :user, "kurt"

# Tell Capistrano where to deploy
set :deploy_to, "/var/www/apps"

# Tell Capistrano the servers it can play with
server "85.255.206.157", :app, :web, :db, :primary => true

# Generate an additional task to fire up the thin clusters
namespace :deploy do
  desc "Start the Thin processes"
  task :start do
    sudo "bundle exec thin start -C thin.yml"
  end

  desc "Stop the Thin processes"
  task :stop do
    sudo "bundle exec thin stop -C thin.yml"
  end

  desc "Restart the Thin processes"
  task :restart do
    sudo "bundle exec thin restart -C thin.yml"
  end

  desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder"
  task :update_cv_assets, :except => {:no_release => true} do
    run "ln -s #{shared_path}/cvs #{latest_release}/public/cvs"
  end
end

# Define all the tasks that need to be running manually after Capistrano is finished.
after "deploy:finalize_update", "deploy:update_cv_assets"
after "deploy", "deploy:migrate"

编辑:这是我的 thin.yml 文件

---
pid: tmp/pids/thin.pid
address: 0.0.0.0
timeout: 30
wait: 30
port: 4000
log: log/thin.log
max_conns: 1024
require: []

environment: production
max_persistent_conns: 512
server: 4
daemonize: true
chdir: /var/www/apps/current

编辑: 现在出现以下问题:

  1. 在最后一步从我的系统运行 cap deploy 命令时,我收到了找不到 GemFile 错误:启动服务器

  2. 不执行迁移

  3. 我似乎也无法手动启动集群了。只有一个 Thin 实例正在启动。

更新: 这是我要部署到的服务器的 gem env 设置。此信息是通过使用 cap shell 然后运行命令获得的:

==================================================== =================== 欢迎使用交互式 Capistrano shell!这是一个实验 功能,并且可能会在未来的版本中更改。输入“帮助” 关于如何使用 shell 的总结。 -------------------------------------------------- ------------------ 帽>回声$ PATH [建立到 85.255.206.157 的连接] 密码: ** [out :: 85.255.206.157] /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 帽>宝石环境 ** [out :: 85.255.206.157] RubyGems 环境: ** [out :: 85.255.206.157] - RUBYGEMS 版本:1.3.6 ** [out :: 85.255.206.157] - RUBY 版本:1.8.7(2010-01-10 补丁级别 249)[x86_64-linux] ** [out :: 85.255.206.157] - 安装目录:/usr/lib/ruby/gems/1.8 ** [out :: 85.255.206.157] - RUBY 可执行文件:/usr/bin/ruby1.8 ** [out :: 85.255.206.157] - 可执行目录:/usr/bin ** [out :: 85.255.206.157] - RUBYGEMS 平台: ** [out :: 85.255.206.157] - 红宝石 ** [out :: 85.255.206.157] - x86_64-linux ** [out :: 85.255.206.157] - 宝石路径: ** [out :: 85.255.206.157] - /usr/lib/ruby/gems/1.8 ** [out :: 85.255.206.157] - /home/kurt/.gem/ruby/1.8 ** [out :: 85.255.206.157] - GEM 配置: ** [out :: 85.255.206.157] - :update_sources => true ** [out :: 85.255.206.157] - :verbose => true ** [out :: 85.255.206.157] - :benchmark => false ** [out :: 85.255.206.157] - :backtrace => false ** [out :: 85.255.206.157] - :bulk_threshold => 1000 ** [out :: 85.255.206.157] - 远程源: ** [out :: 85.255.206.157] - http://rubygems.org/

【问题讨论】:

    标签: ruby-on-rails deployment capistrano bundler thin


    【解决方案1】:

    伙计,找出 GEM_HOME 或 GEM_PATH 指向的位置。一定是的。

    【讨论】:

    • 定义了变量,但还是遇到同样的问题
    【解决方案2】:

    终于解决了问题... 首先,为了让 bundle 应用程序与环境服务器很好地配合,下面的脚本做了它应该做的事情:

    require "bundler/capistrano"
    default_run_options[:pty] = true
    
    # define the application and Version Control settings
    set :application, "ESCO Matching Demo"
    set :repository,  "svn://192.168.33.70/RubyOnRails/ESCO"
    set :deploy_via, :copy
    set :user, "kurt"
    set :deploy_to, "/var/www/apps"
    
    # Tell Capistrano the servers it can play with
    
    server "85.255.206.157", :app, :web, :db, :primary => true
    
    # Generate an additional task to fire up the thin clusters
    namespace :deploy do
      desc "Start the Thin processes"
      task :start do
        run  <<-CMD
          cd /var/www/apps/current; bundle exec thin start -C config/thin.yml
        CMD
      end
    
      desc "Stop the Thin processes"
      task :stop do
        run <<-CMD
          cd /var/www/apps/current; bundle exec thin stop -C config/thin.yml
        CMD
      end
    
      desc "Restart the Thin processes"
      task :restart do
        run <<-CMD
          cd /var/www/apps/current; bundle exec thin restart -C config/thin.yml
        CMD
      end
    
      desc "Create a symlink from the public/cvs folder to the shared/system/cvs folder"
      task :update_cv_assets, :except => {:no_release => true} do
        run <<-CMD
          ln -s /var/www/shared/cvs /var/www/apps/current/public
        CMD
      end
    end
    
    # Define all the tasks that need to be running manually after Capistrano is finished.
    after "deploy:finalize_update", "deploy:update_cv_assets"
    after "deploy", "deploy:migrate"
    

    此脚本可以很好地导航到所需的部署结构并执行控制精简过程所需的命令。 问题是 cd 命令在以 sudo 运行时没有完成。这背后的原因是 cv 仅存在于 shell 中,而不是 sudo 的已知命令。

    第二个问题是精简配置。由于thin.yml 上有一个小类型,瘦服务器无法启动。下面的脚本会启动一个由 4 台瘦服务器组成的集群,该集群在端口 4000 -> 4003 上运行。

    ---
    pid: tmp/pids/thin.pid
    address: 0.0.0.0
    timeout: 30
    wait: 30
    port: 4000
    log: log/thin.log
    max_conns: 1024
    require: []
    
    environment: production
    max_persistent_conns: 512
    servers: 4
    daemonize: true
    chdir: /var/www/apps/current
    

    【讨论】:

    • 也许没关系,像这样run "cd #{current_path} &amp;&amp; bundle exec thin start -C thin.yml"
    • 可以让它在下一个项目中发挥作用,可能会使命令更具可读性。
    猜你喜欢
    • 1970-01-01
    • 2017-12-27
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-20
    • 2017-12-02
    相关资源
    最近更新 更多