pgte / fugue

Unicorn for node.js
MIT License
396 stars 14 forks source link

Daemonizing doesn't background #2

Closed armyofevilrobots closed 13 years ago

armyofevilrobots commented 13 years ago

Loving the fugue idea, however, there is a behavior that isn't quite what I would expect. When daemonizing, the process doesn't actually background and close out the IO.

The following gist doesn't background: http://gist.github.com/641782 Fugue states that it is backgrounding: daemonizing 12830 daemonized

It looks like the code to setsid is called, but the fork and the closeIO never are.

This is on fugue 0.0.34 installed via npm

pgte commented 13 years ago

The daemonizing feature has regressed since there have not been any tests for it - it's kind of difficult to test them. I will be adding tests and correcting this issue soon. Thanks for your input!

armyofevilrobots commented 13 years ago

Thank you! Great library. Doing some playing around with xmpp bots with it :)

armyofevilrobots commented 13 years ago

Did a quick check, btw. Swapping the setSid line as follows seems to fix the problem:

// daemonize?
if (is_master && options.daemonize) {
  log('daemonizing ' + process.pid);
  daemon = require(__dirname + '/../build/default/daemon');
  daemon.start();
  //daemon.setSid();
  log('daemonized');
}

Sorry for no patch; so small it seemed pointless.

pgte commented 13 years ago

Great, thanks, but unfortunately this doesn't work for me (MacOS), because libenv gets borked: (libev) kevent: Bad file descriptor BTW, what is your OS?

armyofevilrobots commented 13 years ago

Ah; sorry. I am on Linux x86_64. Sadly, I have no experience with debugging this kind of thing on OSX.

I would guess that closing stderr is the problem though; I wonder if you could require the logging option to daemonize, then dup2 the logging descriptor and replace stderr with it.

I am going to do some experimenting, because when I look at the code in the daemon.cc code, I don't think it is doing what we would expect anyhow.

armyofevilrobots commented 13 years ago

Sorry; Hit comment and close by mistake.

pgte commented 13 years ago

Hi, no problem, thanks. Yes, daemonizing has gone through some changes, and forking was interrupted because of MacOS. And thanks for the advise, I'm also going to test some things. Cheers.

pgte commented 13 years ago

Testing on linux, some changes for daemonizing are on the way, hopefully before the end of the week.

armyofevilrobots commented 13 years ago

Awesome. In my testing I was able to get daemonizing working with redirection of stderr to the logfile using dup2, but I ran into breakage when sending USR2 (endless restart loop). Not sure if that was due to my code changes or if it was pre-existing. If I get some time this week, I'll test that too and see if I can get a root cause.

pgte commented 13 years ago

Just release version 0.0.35 of Fugue, with a lot of fixes on daemonizing. Still couldn't get it working in MacOS - there seams to be a general problem in kqueue after forking - but I guess this is not a big deal. Maybe FreeBSD doesn't work too :/

Anyway, I just published 0.0.35 to npm. If you could give me some feedback I would appreciate it. Thanks for your input!

armyofevilrobots commented 13 years ago

I'll try and test tonight. Thanks, and I'll let you know!

pgte commented 13 years ago

I'll close this issue for now, since it's working on my Linux install. Please reopen if it's not your case. Thanks.