Closed jason-o-matic closed 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?
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.
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.