by Tim Pease http://codeforpeople.rubyforge.org/spawner
Spawn multiple child processes from Ruby and re-spawn those processes if they die.
Spawner works on Mac OS X, Linux, Windows, Solaris, AIX – anywhere that Ruby can run. It is useful for load testing other applications or just keeping things alive. The Spawner class allows the number of child processes to be changed dynamiclly so they can be brought up and down as needed without restarting the spawner.
There is also a handy command line spawner app that's really useful for load testing services – spawn twenty clients and see how things hold up.
Start three 'foo' processes and re-spawn immediately when one dies.
spawner = Spawner.new( 'foo', :spawn => 3 ) spawner.start
Start two 'bar' processes, pause for 10 seconds before re-spawning, and capture output to a file.
spawner = Spawner.new( 'bar', :spawn = 2, :pause => 10, :stdout => 'stdout.txt' ) spawner.start
Start 10 'baz' process and kill off one process each minute until none are left running.
spawner = Spawner.new( 'baz', :spawn => 10 ) spawner.start until (spawner.spawn == 0) sleep 60 spawner.spawn -= 1 end
sudo gem install spawner
The MIT License
Copyright © 2008
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.