Closed wyardley closed 9 years ago
Thanks for patching this. I just noticed PR #5 which is basically duplicate (sorry for neglecting this repo). Now have to choose which one of these two should prevail.
I think there should be a third option that's even better; just haven't figured out what it is yet. It would be nice to find an option that works without the 'sleep'; in my tests, it didn't seem to.
I've used 'daemonize(1)' with some success in the past, but it doesn't seem to have an option to run as a different user.
The approach of handling it on stop seems Ok to me, but I'm nervous about killing the first matching node process, even if it's owned by the user hubot runs as; obviously, this problem could happen with my approach too.
Well, I think yours is still better than what there is now. Merging it.
Not sure if this is an improvement, but just suggesting some kind of update here (I see another pull request for a similar workaround, but it doesn't seem to have been merged). Also some discussion in https://github.com/spajus/hubot-example/issues/4
I originally tried taking $! into a variable and then doing pgrep -P, but I actually see two levels of processes to get to the node process - the 'runuser -c', which then is the parent of a '-bash -c' process, which in turn is the node process.
The pgrep here could, in theory, get the wrong process if there are other 'node' processes owned by the user that hubot is running as, but it's still better than the other workarounds I've seen. The 2s 'sleep' seems to be necessary just in terms of making sure that the process has forked. Could still use some more testing / refinement, possibly.