Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 174903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:36:19+00:00 2026-05-11T13:36:19+00:00

Ok, so I would like to create an action in Rails to restart itself.

  • 0

Ok, so I would like to create an action in Rails to restart itself. I did a little searching and found:

http://snippets.dzone.com/posts/show/5002

Which suggests 2 commands, one to stop and another to restart. The following kills:

ps -a|grep '/usr/local/bin/ruby script/server'|grep -v 'grep /usr'|cut -d ' ' -f1|xargs -n 1 kill -KILL $1 

The -HUP signal doesn’t restart for me, so I tried to mangle the above command (adjusted so the command worked fine with how I was starting the server under Ubuntu):

ps -eaf|grep 'ruby script/server'|grep -v grep|cut -d ' ' -f3|xargs -n 1 kill -KILL $1;script/server 

This works fine in my environment, so I tried to set up an action to execute it:

def restart   fork { exec 'ps -eaf|grep \'ruby script/server\'|grep -v grep|cut -d \' \' -f3|xargs -n 1 kill -KILL $1;script/server' }   redirect_to '/server_maintenance' end 

The action kills the server fine, but doesn’t actually start the server back up:

=> Booting Mongrel => Rails 2.3.2 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in `initialize_without_backlog': Address already in use - bind(2) (Errno::EADDRINUSE)     from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in `initialize'     from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:93:in `new'     from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:93:in `initialize'     from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:10:in `new'     from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb:10:in `run'     from /usr/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/server.rb:111     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'     from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'     from script/server:3 

I’m not quite understanding why the address is already in use when Mongrel seems to have just exited.

I found this question:

How do you restart Rails under Mongrel, without stopping and starting Mongrel

but the signals don’t cause the restart in my environment, they just end up killing the process.

Anyone have any ideas on what may work? For some notes on my environment: I installed Rails from a new version of RubyGems, and Mongrel. I use script/server to start the server, which of course uses Mongrel. I’m on Ubuntu Hardy Heron.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:36:19+00:00Added an answer on May 11, 2026 at 1:36 pm

    Ok I found a fix… I changed how I start rails to:

    mongrel_rails start -d 

    and now the following action will do it:

    def restart   fork { exec 'mongrel_rails restart' }   redirect_to '/server_maintenance' end 

    As a caveat, the redirect_to will cause a failed load because the server will be down… however a reload after a pause will show that the restart was successful. This could be fixed by changing the restart to be done with AJAX, followed by a javascript reload… but I will leave that as an exercise to the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to rails 3 I would like to create a contact form that people
I would like to run for example a synchronizing ruby script (in rails action
Hi I have added active_admin to my rails app. I would like to create
I'd like to set up my Rails controller to only perform a create action
i would like create a array of structure which have a dynamic array :
I would like to create this shape using just css. I am pretty sure
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create a json object to send as a post array,
I would like to create set of strings and below is the only limitation.
I would like to create a class that runs something (a runnable) at regular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.