cap deployでrestart application

capistranoでdeployするところまではできていたものの、アプリケーションの再読み込みについて調べるのが面倒で、ついついapacheをrestartしてました。 mephistoもpassengerで動かしているので、apacheを再起動せずに何とかならないものかと、調べてみました。 passengerのドキュメントを見ると、deploy後のアプリケーションのrestartについて以下のように記述されています。
1
2
3
4
5
6
7
8
Deploying a new version of a Ruby on Rails application is as simple as re-uploading the application files,
and restarting the application.

There are two ways to restart the application:
 
1.By restarting Apache.
2.By creating or modifying the file tmp/restart.txt in the Rails application’s root folder. Phusion Passenger
will automatically restart the application during the next request.
ということで、deploy.rbに以下の記述を追加。
1
2
3
4
5
6
7
namespace :shrimp do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

after :deploy, "shrimp:restart"
以降、cap deployすると自動的に更新後のアプリケーションが再読み込みされます。

Sorry, comments are closed for this article.