12

cap production deployCapistrano 3.0.1 でUnicorn を起動または再起動しようとしています。次のようなものを使用して Capistrano 2.x で作業した例がいくつかあります。

namespace :unicorn do
  desc "Start unicorn for this application"
  task :start do
    run "cd #{current_path} && bundle exec unicorn -c /etc/unicorn/myapp.conf.rb -D"
  end
end

しかし、Capistrano 3.x で使用しようとするとrundeploy.rb未定義のメソッド エラーが発生します。

ここに私が試したことのいくつかがあります:

# within the :deploy I created a task that I called after :finished
namespace :deploy do
...

  task :unicorn do
    run "cd #{current_path} && bundle exec unicorn -c /etc/unicorn/myapp.conf.rb -D"
  end

  after :finished, 'deploy:unicorn'

end

また、実行を :restart タスク内に入れてみました

namespace :deploy do
  desc 'Restart application'
  task :restart do

  on roles(:app), in: :sequence, wait: 5 do
    # Your restart mechanism here, for example:
    # execute :touch, release_path.join('tmp/restart.txt')
    execute :run, "cd #{current_path} && bundle exec unicorn -c /etc/unicorn/deployrails.conf.rb -D"
  end
end    

run "cd ... " then I'll get aローカルシェルで間違った数の引数 (0 に対して 1)`を使用した場合。

unicorn -c /etc/unicorn/deployrails.conf.rb -Dssh された VM シェルからユニコーン プロセスを開始できます。

kill USR2 を使用して VM シェルからマスター Unicorn プロセスを強制終了できますが、プロセスが強制終了されてもエラーが発生します。その後、次を使用してプロセスを再開できますunicorn -c ...

$ kill USR2 58798
bash: kill: USR2: arguments must be process or job IDs

私はRuby、Rails、およびDeployment全般に非常に慣れていません。私は Ubuntu、Nginx、RVM、および Unicorn で VirtualBox をセットアップしています。これまでのところかなり興奮していますが、これは本当に私をいじっています。アドバイスや洞察をいただければ幸いです。

4

5 に答える 5

14

私は次のコードを使用しています:

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
于 2014-01-21T18:57:23.510 に答える
4

私はちょうどこれをリングに投げるつもりです: capistrano 3 unicorn gem

ただし、gem (および init.d スクリプトを使用しないアプローチ) に関する私の問題は、ユニコーン プロセスを管理する方法が 2 つある可能性があることです。1 つはこのキャップ タスクを使用し、もう 1 つは init.d スクリプトを使用します。Monit / God のようなものは混乱し、開始しようとしている 2 つのユニコーン プロセスがある理由をデバッグするのに何時間も費やし、人生が嫌になり始めるかもしれません。

現在、私は capistrano 3 と 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

上記は preload_app: true と @dredozubov によって言及された before_fork および after_fork ステートメントと組み合わされます

init.d/unicorn スクリプトに unicorn_application_name という名前を付けたことに注意してください。

開始された新しいワーカーは、古いワーカーを強制終了する必要があります。ps aux | grep unicorn古いマスターが消える前に数秒間ぶらぶらしていることがわかります。

于 2014-02-28T15:57:46.897 に答える
0

ここに書かれているように、ネイティブのカピストラーノの方法を使用することができます:

preload_app:true で、oldbin pid をクリーンアップするために capistrano が必要な場合:

after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
  task :restart do
    invoke 'unicorn:legacy_restart'
  end
end
于 2015-11-30T15:05:56.693 に答える