2012-02-27 4 views
2

ウェブサーバーにsshingすると、問題なく一日遅れてrestart_jobを再開できます。それは既存のワーカーを引き下げ、新しいワーカーを開始し、tmp/pids/delayed_job.pidにそのプロセスIDを書き込みます。私はカピストラーノcapistranoでdelayed_jobを再起動すると、必ずしもpidファイルを作成しているとは限りません。

[email protected]:~/app-site$ cap passenger:restart 
    triggering start callbacks for `passenger:restart' 
    * executing `multistage:ensure' 
*** Defaulting to `staging' 
    * executing `staging' 
    * executing `passenger:restart' 
    * executing "touch /app/current/tmp/restart.txt" 
    servers: ["staging.app.com"] 
    [staging.app.com] executing command 
    command finished in 242ms 
    * executing "cd /app/current;RAILS_ENV=staging script/delayed_job restart" 
    servers: ["staging.app.com"] 
    [staging.app.com] executing command 
** [out :: staging.app.com] delayed_job: trying to stop process with pid 21646... 
** [out :: staging.app.com] delayed_job: process with pid 21646 successfully stopped. 
    command finished in 11889ms 

を使用して展開するとき

[email protected]:/app/current$ touch tmp/restart.txt; RAILS_ENV=staging script/delayed_job restart 
delayed_job: trying to stop process with pid 22170... 
delayed_job: process with pid 22170 successfully stopped. 
delayed_job: process with pid 22284 started. 
[email protected]:/app/current$ touch tmp/restart.txt; RAILS_ENV=staging script/delayed_job restart 
delayed_job: trying to stop process with pid 22284... 
delayed_job: process with pid 22284 successfully stopped. 
delayed_job: process with pid 22355 started. 
[email protected]:/app/current$ touch tmp/restart.txt; RAILS_ENV=staging script/delayed_job restart 
delayed_job: trying to stop process with pid 22355... 
delayed_job: process with pid 22355 successfully stopped. 
delayed_job: process with pid 22427 started. 
[email protected]:/app/current$ 

(私も、私はカピストラーノをどうしようよ何を模倣するために乗客を再起動しています)しかし、罰金ですか? delayed_jobの最後の行は印刷されませんが(これは改行で終わらないためです)、これは新しいプロセスを正常に作成します。

[email protected]:~/app-site$ cap passenger:restart 
    triggering start callbacks for `passenger:restart' 
    * executing `multistage:ensure' 
*** Defaulting to `staging' 
    * executing `staging' 
    * executing `passenger:restart' 
    * executing "touch /app/current/tmp/restart.txt" 
    servers: ["staging.app.com"] 
    [staging.app.com] executing command 
    command finished in 398ms 
    * executing "cd /app/current;RAILS_ENV=staging script/delayed_job restart" 
    servers: ["staging.app.com"] 
    [staging.app.com] executing command 
** [out :: staging.app.com] Warning: no instances running. Starting... 
** [out :: staging.app.com] delayed_job: process with pid 21950 started. 
    command finished in 6758ms 

これは、既存のプロセスを停止しません:私はもう一度試してみて、再起動したときただし、は、それはそう、を.pidファイルを作成しません。不思議なことに、今度は新しいプロセスを作成します.pidファイルです。

これは、2つのdelayed_jobsプロセスが実行され、.pidファイルに1つのみが残っています。 2回のキャップデプロイごとに、別のdelayed_jobプロセスが追加されます。以前のプロセスでは、古いバージョンのアプリケーションを使用しています。

のconfig/deploy.rb:

namespace :passenger do 
    desc "Restart Application" 
    task :restart do 
    run "touch #{current_path}/tmp/restart.txt" 
    run "cd #{current_path};RAILS_ENV=#{deploy_env} script/delayed_job restart" 
    end 
end 
after :deploy, "passenger:restart" 
  • Ubuntuで、nginxの、乗客
  • デーモン(1.1.4)
  • delayed_job(2.1.4)
  • レール(3.0.9 )

ローカルに

  • カピストラーノ(2.9.0)
  • カピストラーノ-EXT(1.2.1)

更新:

周り読書、内部の競合状態をどうするかもしれないようですデーモン。しかし、私はカピストラーノを使用するときにそれがなぜ(そして一貫して)しか表示されないのか少し混乱します。コマンドを停止、睡眠、そして起動するように変更しようとします。

答えて

7

再起動の代わりにstopとstartを使用して解決しました。おそらくデーモンの宝石によって引き起こされる競合状態のために動作します。

他の誰かがより良い解決策を持っているかどうかを知りたいと思っています。

0

私はこの問題を抱えていたと停止と開始は私のために動作しませんでしたので、私は、次のを思い付いた:

namespace :delayed_job do 
desc 'Restart delayed_job worker' 
    task :restart do 
    on roles(:delayed_job) do 
     within release_path do 
     with rails_env: fetch(:rails_env) do 
      execute :pkill , "-f", "'delayed_job'" 
      execute :bundle, :exec, "bin/delayed_job", :start 
     end 
     end 
    end 
    end 
end 
... 
after :restart, "delayed_job:restart" 

ないpkillコマンドの巨大なファンが、これは私のために一貫して動作します。希望により、

関連する問題