How to restart Rails from within Rails?

后端 未结 3 1619
轻奢々
轻奢々 2021-02-09 13:53

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

3条回答
  •  庸人自扰
    2021-02-09 14:30

    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.

提交回复
热议问题