Project

forking

0.0
No commit activity in last 3 years
No release in over 3 years
Simple processes forking, and restarting. Master process starts as daemon.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

Forking

Simple processes forking, and restarting. Master process starts as daemon.

$ gem install forking

Example 1.rb (run 5 child processes and capturing logs):

#!/usr/bin/env ruby
require 'rubygems'
require 'forking'

f = Forking.new(:name => 'test', :working_dir => File.dirname(__FILE__),
    :log_file => "spawner.log", :pid_file => "spawner.pid", :sync_log => true)

f.before_fork do
  puts "load env"
end

f.after_fork do
  puts "restart connects"
end

2.times do |i|
  f.spawn(:name => "test1", :log_file => "test1.log") do
    loop do
      puts "test1 #{i}"
      sleep 1
    end
  end
end

3.times do |i|
  f.spawn(:log_file => "test2.log", :sync_log => true) do
    exec 'ruby', '2.rb', '--test'
  end
end

f.run!

Usage:

$ ./1.rb start
$ ./1.rb status
$ ./1.rb stop
$ ./1.rb restart

Respawn childs:

$ kill -HUP master_pid