Starting or restarting Unicorn with Capistrano 3.x

前端 未结 5 1018
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 09:31

I\'m trying to start or restart Unicorn when I do cap production deploy with Capistrano 3.0.1. I have some examples that I got working with Capistrano 2.x using so

5条回答
  •  鱼传尺愫
    2021-02-01 09:40

    I'm using following code:

    namespace :unicorn do
      desc 'Stop Unicorn'
      task :stop do
        on roles(:app) do
          if test("[ -f #{fetch(:unicorn_pid)} ]")
            execute :kill, capture(:cat, fetch(:unicorn_pid))
          end
        end
      end
    
      desc 'Start Unicorn'
      task :start do
        on roles(:app) do
          within current_path do
            with rails_env: fetch(:rails_env) do
              execute :bundle, "exec unicorn -c #{fetch(:unicorn_config)} -D"
            end
          end
        end
      end
    
      desc 'Reload Unicorn without killing master process'
      task :reload do
        on roles(:app) do
          if test("[ -f #{fetch(:unicorn_pid)} ]")
            execute :kill, '-s USR2', capture(:cat, fetch(:unicorn_pid))
          else
            error 'Unicorn process not running'
          end
        end
      end
    
      desc 'Restart Unicorn'
      task :restart
      before :restart, :stop
      before :restart, :start
    end
    

提交回复
热议问题