使用capistrano 3在生产中运行rpush

时间:2015-07-14 07:42:08

标签: ruby-on-rails-4 capistrano3

为了运行Rpush,我在config / deploy.rb

中写了这个
 after :publishing, 'deploy:restart'

  after :finishing, 'deploy:cleanup'

  after :finished, :restart_rpush do

    on roles(:web) do
        within release_path do
            with rails_env: fetch(:rails_env) do
                execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"
                execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
            end
        end
    end
  end
end

在部署时,我收到此错误:

DEBUG [76ef4791]    * Rpush isn't running? 
/home/dev/proteqtor/releases/20150714065629/tmp/rpush.pid does not exist.

Rpush没有运行。可能是造成这个问题的原因是什么?

1 个答案:

答案 0 :(得分:2)

我认为这是因为,由于Rpush没有运行,你将获得execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"未被捕获的例外。即如果它没有运行,为什么要运行rpush stop

相反,首先测试(使用Capistrano 3的test command)pid文件是否存在于给定路径中,并且仅在运行时停止,否则只运行start:

desc 'Restart rpush'
task :restart_rpush do
  on roles(:web) do
    within release_path do
      with rails_env: fetch(:rails_env) do
        if test('[ -f /path/to/my/pid/file ]')
          # Rpush is running
          execute :bundle, :exec, "rpush stop -e #{fetch(:rails_env)}"
          execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
        else
          # Rpush is not running
          execute :bundle, :exec, "rpush start -e #{fetch(:rails_env)}"
        end
      end
    end
  end
end

after :finished, :restart_rpush