Jeremy Harris
Jeremy Harris

Reputation: 24579

Capistrano Restart Apache

I'm using Capistrano to deploy a PHP application. I'm trying to add in the ability to restart Apache once it completes but then my script hangs (I'm guessing because it loses connection from the web server). Is there a way to send the service httpd restart command and return without waiting? Here is what I'm doing (the relevant part)...

namespace :myapp do

   task :restart_webserver do

      #Show Start of Task
      print "Restarting webserver..."

      # Restart Web Server
      run "service httpd restart"

      # Show Green Check Mark on Completion
      puts checkmark.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') }.green

   end

end

after "deploy","myapp:restart_webserver"

It hangs on the restart and then I have to Ctrl+C out of the script to get it to end. Any way to make this non-blocking?

Upvotes: 2

Views: 2459

Answers (1)

Electrawn
Electrawn

Reputation: 2254

Since I can't add a comment, what user is the application running as? If you are logging in as the root user, this command will work fine. Else, you will need to run this via sudo like

run "#{sudo} service httpd restart"

And possibly add NOPASSWD:/sbin/service httpd* to your sudoers file.

You may want to override restart rather than a web hook:

namespace :deploy do

task :restart, :except => { :no_release => true } do
  myapp.restart_webserver
end

end

Also, consider tightening you after hook:

after "deploy:restart", "myapp:restart_webserver"

Upvotes: 3

Related Questions