Starting or restarting Unicorn with Capistrano 3.x

前端 未结 5 1026
爱一瞬间的悲伤
爱一瞬间的悲伤 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:44

    I'm just going to throw this in the ring: capistrano 3 unicorn gem

    However, my issue with the gem (and any approach NOT using an init.d script), is that you may now have two methods of managing your unicorn process. One with this cap task and one with init.d scripts. Things like Monit / God will get confused and you may spend hours debugging why you have two unicorn processes trying to start, and then you may start to hate life.

    Currently I'm using the following with capistrano 3 and unicorn:

      namespace :unicorn do
      desc 'Restart application'
        task :restart do
          on roles(:app) do
            puts "restarting unicorn..."
            execute "sudo /etc/init.d/unicorn_#{fetch(:application)} restart"
            sleep 5
            puts "whats running now, eh unicorn?"
            execute "ps aux | grep unicorn"
          end
        end
    end
    

    The above is combined with the preload_app: true and the before_fork and after_fork statements mentioned by @dredozubov

    Note I've named my init.d/unicorn script unicorn_application_name.

    The new worker that is started should kill off the old one. You can see with ps aux | grep unicorn that the old master hangs around for a few seconds before it disappears.

提交回复
热议问题