# Is using script/runner to run a daemon a good idea?

**URL:** <https://www.ruby-forum.com/t/is-using-script-runner-to-run-a-daemon-a-good-idea/173266>\
**Category:** Rails\
**Created:** [August 5, 2009, 11:01pm UTC](https://www.ruby-forum.com/t/is-using-script-runner-to-run-a-daemon-a-good-idea/173266 "2009-08-05T23:01:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [August 5, 2009, 11:01pm UTC](https://www.ruby-forum.com/t/is-using-script-runner-to-run-a-daemon-a-good-idea/173266/1 "2009-08-05T23:01:51Z")

</div>

Suppose I have a daemon and I run it like this:

ruby script/runner script/my\_daemon.rb

This gives my daemon full access to the rails environment, and it may  
run for days, months, many months or longer. I realized this could be  
risky if there is some caching or other issues, in which case I would  
launch some other external exec from the daemon instead perhaps to get  
access to the environment, or possibly I could launch it the same way  
and just do a fork and then do the DB operations in the child. Right  
now I am just running it as shown with no such strategy.

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [August 6, 2009, 5:18am UTC](https://www.ruby-forum.com/t/is-using-script-runner-to-run-a-daemon-a-good-idea/173266/2 "2009-08-06T05:18:02Z")

</div>

Jedrin wrote:

> Suppose I have a daemon and I run it like this:
> 
> ruby script/runner script/my\_daemon.rb
> 
> This gives my daemon full access to the rails environment, and it may  
> run for days, months, many months or longer. I realized this could be  
> risky if there is some caching or other issues, in which case I would  
> launch some other external exec from the daemon instead perhaps to get  
> access to the environment, or possibly I could launch it the same way  
> and just do a fork and then do the DB operations in the child. Right  
> now I am just running it as shown with no such strategy.

You may want to look into the daemons gem. I’ve used it before and it  
allows you to start, stop and restart daemon processes.

[http://daemons.rubyforge.org/](http://daemons.rubyforge.org/)

I think daemon-kit might be another option too but I haven’t used it  
yet.

> **[GitHub - kennethkalmer/daemon-kit: Daemon Kit aims to simplify creating Ruby...](https://github.com/kennethkalmer/daemon-kit/tree/master)**
>
> master

Best,  
Michael G.
