通过Capistrano 3安装和启动守护程序脚本

时间:2016-01-31 04:47:19

标签: ruby-on-rails ruby capistrano3

我已经尝试了几天但现在没有成功。我正在使用Capistrano 3在我的生产服务器上部署我的Ruby on Rails 4代码。

在部署过程结束时,我想重启我的守护程序脚本,我将通过此命令手动执行:

RAILS_ENV=production bundle exec ruby script/my_daemon restart

在我的Capistrano 3食谱(config/deploy.rb)上,我尝试了一些不同的设置,但没有一个有效。

namespace :deploy do
  desc 'Restart application'

  task :restart do
invoke 'unicorn:restart'
  end
  after :publishing, :restart

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do

      within release_path do
        execute :rake, 'tmp:cache:clear'

        # Daemons
        # This ends up with an error
        execute :bundle, :exec, :ruby, "RAILS_ENV=production /var/www/MY_APP/current/script/my_daemon restart;"

        # This starts the daemon, but in development environment
        execute :bundle, :exec, :ruby, "/var/www/MY_APP/current/script/my_daemon restart RAILS_ENV=production;"

        # This also starts the daemon, but in development environment
        execute :bundle, :exec, :ruby, "/var/www/MY_APP/current/script/my_daemon restart;"
      end
    end
  end
end

有人可以帮我写一个正确的配方来重启生产环境中的守护进程吗?感谢。

1 个答案:

答案 0 :(得分:1)

尝试通过capistrano dsl设置env

within release_path do
  with rails_env: :production do
    execute :bundle, :exec, :ruby, "#{current_path}/script/my_daemon restart"
  end
end