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

Installing and starting daemon script via Capistrano 3

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

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

RAILS_ENV=production bundle exec ruby script/my_daemon restart

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

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

有人可以帮助我编写正确的方法以在生产环境中重启我的守护进程吗?谢谢

尝试通过 capistrano dsl 设置环境

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