【问题标题】:Capistrano, Debian 8 systemctlCapistrano,Debian 8 systemctl
【发布时间】:2016-04-05 13:06:09
【问题描述】:

我想使用 capistrano 3 在我的 vps 上部署我的网络应用程序。不幸的是,我遇到了一些错误:

DEBUG [6de1d411] Running [ -L /var/www/myapp/releases/20160405125654/log ] as user@example.com
DEBUG [6de1d411] Command: [ -L /var/www/myapp/releases/20160405125654/log ]
DEBUG [6de1d411] Finished in 0.005 seconds with exit status 0 (successful).
DEBUG [cf28b01d] Running [ -L /var/www/myapp/releases/20160405125654/tmp/pids ] as user@example.com
DEBUG [cf28b01d] Command: [ -L /var/www/myapp/releases/20160405125654/tmp/pids ]
DEBUG [cf28b01d] Finished in 0.005 seconds with exit status 1 (failed).
DEBUG [c7f0b156] Running [ -d /var/www/myapp/releases/20160405125654/tmp/pids ] as user@example.com
DEBUG [c7f0b156] Command: [ -d /var/www/myapp/releases/20160405125654/tmp/pids ]
DEBUG [c7f0b156] Finished in 0.005 seconds with exit status 1 (failed).

据我所知,这些失败的测试是可以的,因为它只检查符号链接和目录的存在。但以下内容以某种方式破坏了游戏规则:

INFO [c1b0c10e] Finished in 0.007 seconds with exit status 0 (successful).
INFO [e895fd13] Running /usr/bin/env sudo /etc/init.d/nginx reload as user@example.com
DEBUG [e895fd13] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.2.3" ; /usr/bin/env sudo /etc/init.d/nginx reload )
DEBUG [e895fd13]  Reloading nginx configuration (via systemctl): nginx.service
DEBUG [e895fd13]  .
INFO [e895fd13] Finished in 0.037 seconds with exit status 0 (successful).
INFO [1a822f12] Running /usr/bin/env service unicorn_myapp_production restart as user@example.com
DEBUG [1a822f12] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.2.3" ; /usr/bin/env service unicorn_myapp_production restart )
DEBUG [1a822f12]  /usr/bin/env: service
DEBUG [1a822f12]  : No such file or directory
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@example.com: service exit status: 127
service stdout: Nothing written
service stderr: /usr/bin/env: service: No such file or directory

显然,Debian jessie 依赖 systemctl 而不是 service,因为

/usr/bin/env service

确实不存在。不,我想通过添加

来覆盖默认行为
namespace :unicorn do

  task :defaults do
    on roles :app do
      set :unicorn_user, fetch(:unicorn_user, deploy_user)
    end
  end

  desc 'Setup Unicorn initializer'
  task :setup_initializer do
    on roles :app do
      next if file_exists? unicorn_initd_file
      sudo_upload! template('unicorn_init.erb'), unicorn_initd_file
      execute :chmod, '+x', unicorn_initd_file
      sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults'
    end
  end

  desc 'Setup Unicorn app configuration'
  task :setup_app_config do
    on roles :app do
      next if file_exists? fetch(:unicorn_config)
      execute :mkdir, '-pv', File.dirname(fetch(:unicorn_config))
      upload! template('unicorn.rb.erb'), fetch(:unicorn_config)
    end
  end

  %w[start stop restart].each do |command|
    desc "#{command} unicorn"
    task command do
      on roles :app do
        # execute :service, fetch(:unicorn_service), command
        # run "#{sudo} systemctl #{command} unicorn_#{application}"
        sudo "/etc/init.d/unicorn_#{fetch(:unicorn_service)} #{command}"
      end
    end
  end

  before :setup_initializer, :defaults

end

/myapp/config/deploy.rb。但是 capistrano 忽略了这个设置。那么如何确保加载了特定于 Debian-8 的配置。

【问题讨论】:

    标签: ruby capistrano unicorn


    【解决方案1】:

    我不熟悉独角兽,但我假设您正在使用定义上限任务的东西,然后您试图覆盖?如果是这种情况,使用 Capistrano 3,您需要在重新定义之前清除原始任务。您当前正在做的事情扩展了任务。你需要使用 Rake::Task["task_name"].clear 类似这样的东西:

    namespace :unicorn do
      %w[start stop restart].each do |command|
        Rake::Task["unicorn:#{command}"].clear
    
        desc "#{command} unicorn"
        task command do
          on roles :app do
            # execute :service, fetch(:unicorn_service), command
            # run "#{sudo} systemctl #{command} unicorn_#{application}"
            sudo "/etc/init.d/unicorn_#{fetch(:unicorn_service)} #{command}"
          end
        end
      end
    end
    

    【讨论】:

    • 这回答了问题,但没有解决问题。这个解决方案似乎很简单:再见 Debian,你好 Ubuntu。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    • 2020-02-05
    • 2018-01-07
    • 1970-01-01
    • 2018-01-21
    • 2015-08-29
    • 1970-01-01
    相关资源
    最近更新 更多