Instrumental / instrumentald

Instrumental System and Service Daemon
MIT License
14 stars 3 forks source link

Fixed issue where stating the daemon twice resulted in printing an exception. #17

Closed jason-o-matic closed 8 years ago

jason-o-matic commented 8 years ago

This fixes #12 by switching away from Process.waitpid which raises if the pid isn't a child of the current process. The goal here was to quickly abort if the process didn't start. Unfortunately if you had already started instrumentald it would have daemonized and wouldn't be a child if the current process, meaning waitpid would fail. Sleeping for 1 second seems simpler overall.

janxious commented 8 years ago

I'm guessing you tested this, but could you add the test steps to reproduce you did for this? Looks like: start daemonized, then start daemonized in another console?

jason-o-matic commented 8 years ago

They're in #12, but basically it would fail when you started the daemon using the init script and then tried to start it again using the init script:

deploy@smoke-smoke-666 ~ $ sudo /etc/init.d/instrumentald status
"instrumentald" is running (PID: 3240)
deploy@smoke-smoke-666 ~ $ sudo /etc/init.d/instrumentald start
"instrumentald" is already running (PID: 3240)
/opt/instrumentald/lib/app/bin/instrumentald:231:in `waitpid': No child processes (Errno::ECHILD)
    from /opt/instrumentald/lib/app/bin/instrumentald:231:in `block in <main>'
    from /opt/instrumentald/lib/ruby/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
    from /opt/instrumentald/lib/ruby/lib/ruby/2.1.0/timeout.rb:35:in `block in catch'
    from /opt/instrumentald/lib/ruby/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /opt/instrumentald/lib/ruby/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /opt/instrumentald/lib/ruby/lib/ruby/2.1.0/timeout.rb:106:in `timeout'
    from /opt/instrumentald/lib/app/bin/instrumentald:230:in `<main>'

I imagine it would get an error if you daemonized without the init script, but I didn't try that. Using a separate console should reproduce it, but I think you could repro in the same console as well.