# Daemons

**URL:** <https://www.ruby-forum.com/t/daemons/151362>\
**Category:** JRuby\
**Created:** [October 20, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/daemons/151362 "2008-10-20T18:01:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/daemons/151362/1 "2008-10-20T18:01:51Z")

</div>

Hello!

I am having issues with daemons (to a process in detached from terminal)  
as in:

/usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:122:in  
`each\_object’: ObjectSpace is disabled; each\_object will only work with  
Class, pass +O to enable (RuntimeError)

I am just trying to use daemons to run a process detached from the tty  
(so that it will continue to run after I logout). I think I am using  
daemons in the most simplistic case:

> cat daemonize.rb  
> #!/usr/bin/env jruby

require ‘rubygems’  
require ‘daemons’

Daemons.run(‘scaleMatrix.rb’)

# end

> 

scaleMatrix itself is a jruby script. Using this under ruby e.g. using  
ruby calling a ruby script, appears to work correctly (simple tests),  
however this is not the case with jruby.

Is there perhaps a better way of detaching from the controlling tty and  
have the process run after I log out?

TIA!  
Phy

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo](https://mail.yahoo.com)**
>
> It's

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/daemons/151362/2 "2008-10-20T18:42:24Z")

</div>

Following up on this a bit, after some experimentation, I am not getting  
a nice message:

> jruby -X+O scaelMatrix.rb start  
> /usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:103:in  
> `safefork’: fork is unsafe and disabled by default on JRuby  
> (NotImplementedError)

So now I am stuck. Either I need to enable an ‘unsafe’ method or I need  
some help in understanding how to create a daemonized process e.g. a  
process that is detached from the parent tty so that I can log out and  
still have the application/process run. Any suggestions?

Thanks for the help!  
Phy

— On Mon, 10/20/08, Phy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> `each\_object’: ObjectSpace is disabled; each\_object will
> 
> correctly (simple tests), however this is not the case with  
> Tired of spam? Yahoo! Mail has the best spam protection  
> around  
> [http://mail.yahoo.com](http://mail.yahoo.com)
> 
> * * *
> 
> To unsubscribe from this list, please visit:
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail | Email with smart features and top-notch security](https://mail.yahoo.com)**
>
> Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/daemons/151362/3 "2008-10-20T19:00:01Z")

</div>

On Mon, Oct 20, 2008 at 12:56 PM, Phy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So now I am truly stuck. Can anyone please educate me on how to create a daemon process with Jruby? I just need to be able to launch this application/process and be able to log out and have the application/process continue to run (for several weeks). Any help is greatly appreciated!
> 
> > To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > how to create a daemonized process e.g. a process that is
> > 
> > > From: Phy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > > /usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:122:in  
> > > case:
> > > 
> > > > 
> > > 
> > > controlling tty and have the process run after I log  
> > > out?
> > > 
> > > TIA!  
> > > Phy

You will likely have more luck with this posting to the JRuby-User list.

Michael G.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 6:57pm UTC](https://www.ruby-forum.com/t/daemons/151362/4 "2008-10-20T18:57:05Z")

</div>

Hello again.

Okay, so further testing shows that indeed, fork system call fails (or  
at least I believe it fails) on my sparc machine:

> jruby -X+O -J-Djruby.fork.enabled=true scaleMatrix.rb start  
> WARNING: fork is highly unlikely to be safe or stable on the JVM. Have  
> fun!  
> /usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:151:in  
> `call_as_daemon'/usr/local/jruby-1.1.4/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/daemonize.rb:151:in `call\_as\_daemon’: No child processes - No child processes: No child  
> processes - No child processes (Errno::ECHILD)  
> (Errno::ECHILD)  
> …

So now I am truly stuck. Can anyone please educate me on how to create  
a daemon process with Jruby? I just need to be able to launch this  
application/process and be able to log out and have the  
application/process continue to run (for several weeks). Any help is  
greatly appreciated!

Cheers,  
Phy

— On Mon, 10/20/08, Phy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> — On Mon, 10/20/08, Phy P.
> 
> > from terminal) as in:  
> > from the tty (so that it will continue to run after I  
> > Daemons.run(‘scaleMatrix.rb’)  
> > jruby.  
> > Tired of spam? Yahoo! Mail has the best spam
> 
> * * *
> 
> Do You Yahoo!?  
> Tired of spam? Yahoo! Mail has the best spam protection  
> around  
> [http://mail.yahoo.com](http://mail.yahoo.com)
> 
> * * *
> 
> To unsubscribe from this list, please visit:
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail | Email with smart features and top-notch security](https://mail.yahoo.com)**
>
> Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/daemons/151362/5 "2008-10-20T19:50:34Z")

</div>

On Mon, Oct 20, 2008 at 1:48 PM, Phy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Micheal,
> 
> Opps, I thought I had posted to that group. Sorry for the junk email and thanks for the correction!
> 
> Cheers,  
> Phy

Actually my mistake. You had initially posted to ruby-talk and then  
to JRuby-User. It was showing up under both labels in my inbox.

Sorry for the interruption, my mistake.

Michael G.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 7:55pm UTC](https://www.ruby-forum.com/t/daemons/151362/6 "2008-10-20T19:55:57Z")

</div>

Well, you did point out that I did indeed post to the wrong mailing  
list. So thanks for forcing me to verify that I had indeed published it  
correctly the second time.

Cheers!  
Phy

— On Mon, 10/20/08, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> Michael G.
> 
> * * *
> 
> To unsubscribe from this list, please visit:
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail | Email with smart features and top-notch security](https://mail.yahoo.com)**
>
> Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 9:01pm UTC](https://www.ruby-forum.com/t/daemons/151362/7 "2008-10-20T21:01:23Z")

</div>

Just a wild guess, but would it be possible to daemonize the Java  
process that you are running in?

Phy P. wrote:

> …
> 
> > `safefork’: fork is unsafe and disabled by default on
> > 
> > > `each\_object’: ObjectSpace is disabled;  
> > > from the tty (so that it will continue to run after I
> > 
> > > Is there perhaps a better way of detaching from the
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/daemons/151362/8 "2008-10-20T19:48:48Z")

</div>

Micheal,

Opps, I thought I had posted to that group. Sorry for the junk email  
and thanks for the correction!

Cheers,  
Phy

— On Mon, 10/20/08, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> sparc machine:  
> (Errno::ECHILD)
> 
> > Phy
> > 
> > > Following up on this a bit, after some  
> > > ‘unsafe’ method or I need some help in
> > > 
> > > > I am having issues with daemons (to a process  
> > > > (RuntimeError)  
> > > > case:
> > > > 
> > > > > 
> > > > 
> > > > jruby.
> 
> You will likely have more luck with this posting to the  
> JRuby-User list.
> 
> Michael G.
> 
> * * *
> 
> To unsubscribe from this list, please visit:
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail | Email with smart features and top-notch security](https://mail.yahoo.com)**
>
> Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![Phy\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Phy\_P](https://www.ruby-forum.com/u/Phy_P)\
**Post date:** [October 20, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/daemons/151362/9 "2008-10-20T22:32:06Z")

</div>

Jacob,

That’s a good idea and in fact, I have tried unsuccessfully to have an  
external jruby wrapper invoke the scaleMatrix jruby script, but I run  
into the same problem.

Perhaps you are suggesting that I use a different language to accomplish  
this? I am on the thought of writing a simple c app to setsid on the  
process, but was hoping this could all be done in ruby/jruby (well ruby  
actually does work).

Any thoughts?

— On Mon, 10/20/08, Jacob K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> to be able to launch this application/process and be able to
> 
> > > >
> 
> that is
> 
> > > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > > 
> > > > 
> > > 
> > > > > cat daemonize.rb  
> > > > > scaleMatrix itself is a jruby script. Using  
> > > > > the case  
> > > > > out?
> > > 
> > > > ```
> > > > http://xircles.codehaus.org/manage_email
> > > > 
> > > > ```
> > > 
> > > To unsubscribe from this list, please visit:
> 
> To unsubscribe from this list, please visit:
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail | Email with smart features and top-notch security](https://mail.yahoo.com)**
>
> Yahoo Mail: Your smarter, faster, free email solution. Organize your inbox, protect your privacy, and tackle tasks efficiently with AI-powered features and robust security tools.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```
