# How to load the database.yml file again during runtime?

**URL:** <https://www.ruby-forum.com/t/how-to-load-the-database-yml-file-again-during-runtime/139834>\
**Category:** Rails\
**Created:** [June 7, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/how-to-load-the-database-yml-file-again-during-runtime/139834 "2008-06-07T22:33:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juantar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@juantar](https://www.ruby-forum.com/u/juantar)\
**Post date:** [June 7, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/how-to-load-the-database-yml-file-again-during-runtime/139834/1 "2008-06-07T22:33:01Z")

</div>

Hi, I have an application that allows the user to make changes to the  
database.yml file so that he can connect to another database. However I  
have to manually restart the application to make the changes in  
database.yml effective. My question is: is there any way of making the  
changes in database.yml effective from the application code? or at  
least, is there any way of restarting the application from the  
application code?

Thanks

---

<div class="post-metadata">

**Author:** ![juantar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@juantar](https://www.ruby-forum.com/u/juantar)\
**Post date:** [June 7, 2008, 10:46pm UTC](https://www.ruby-forum.com/t/how-to-load-the-database-yml-file-again-during-runtime/139834/2 "2008-06-07T22:46:41Z")

</div>

On Jun 7, 9:33 pm, Juan T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi, I have an application that allows the user to make changes to the  
> database.yml file so that he can connect to another database. However I  
> have to manually restart the application to make the changes in  
> database.yml effective. My question is: is there any way of making the  
> changes in database.yml effective from the application code? or at  
> least, is there any way of restarting the application from the  
> application code?

Don’t know about restarting the app (I suspect not) but  
ActiveRecord::Base.establish\_connection might help you. Propagating  
that change to all of your mongrels might be interesting.

Fred

---

<div class="post-metadata">

**Author:** ![juantar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/919ad9/32.png) [@juantar](https://www.ruby-forum.com/u/juantar)\
**Post date:** [June 7, 2008, 11:24pm UTC](https://www.ruby-forum.com/t/how-to-load-the-database-yml-file-again-during-runtime/139834/3 "2008-06-07T23:24:15Z")

</div>

On Jun 7, 2008, at 1:46 PM, Frederick C. wrote:

> > application code?  
> > Don’t know about restarting the app (I suspect not)

I would think you could ping a URL which runs a shell script that  
would make the mongrel\_cluster calls (or equiv) to restart the app.  
Use HTTP authentication for that URL of course, and it’s recommended  
to run that URL as https (unless it’s all on a LAN where you’re not  
worried about snooping).

I’ve done this on another platform for a special application case.

I have a local script I use during dev to “restart” rails:

echo “stopping rails…”  
mongrel\_rails stop /Users/greg/Sites/{path\_to\_application}/log

echo “starting rails…”  
cd /Users/greg/Sites/{path\_to\_application}  
mongrel\_rails start -d -p 3001  
echo “done”  
echo “”

So, something like that with the mongrel\_cluster commands and without  
the echo feedback.

– gw
