i am running a headless selenium process along a jenkins server on an AMI linux box, all managed by runit.
the problem is that issuing "sv stop selenium" or "sv reload selenium" do not term or kill the old instance along its child processes, but merely detach them from the runsv process, so they continue to run without runit knowing about them, resulting in a failing restart try of the service.
i think my question is kind of related to this:
How to write runit custom stop script
meaning: i should probably try a custom d control script, in order to manually clean up.
I followed this idea:
https://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes
However, cat'ing the pid from /etc/sv/selenium/supervise/pid and forwarding it to the loop didn't do any difference.
Any advice?
sv run script:
#!/bin/sh
exec 2>&1
exec chpst -u jenkins -U jenkins /usr/bin/xvfb-run \
--server-args="-screen 0 1024x768x32" \
/usr/bin/java -jar /usr/local/bin/selenium-server-standalone-2.42.1.jar \
-ensureCleanSession \
-browserSessionReuse
Best Answer
If you add -P to the chpst command line, chpst will create a new process group for your service. Then in your custom 'd' script you can read pid and kill -TERM -pid to send the TERM signal to the entire process group.
This should work as long as no child process creates its own process group.
However, it might be cleaner to start your xvfb and java separately (split these into two runit services).
Edit: apparently the
runsv
manpage is misleading;runsv
only actually runs thecontrol/d
script after it already killed its child. You should use acontrol/t
script to clean up. Thanks to @Keith for pointing this out.