def start(config_file, options = {})
options[:background] ||= false
options[:environment] ||= "development"
$rbg_env = options[:environment].dup
self.config_file = config_file
self.load_config
if self.config.pid_path and File.exists?(self.config.pid_path)
oldpid = File.read(self.config.pid_path)
begin
Process.getpgid( oldpid.to_i )
raise Error, "Process already running! PID #{oldpid}"
rescue Errno::ESRCH
false
end
end
self.child_processes = Hash.new
if options[:background]
master_pid = fork do
STDIN.reopen('/dev/null')
if self.config.log_path
STDOUT.reopen(self.config.log_path, 'a')
STDOUT.sync = true
STDERR.reopen(self.config.log_path, 'a')
STDERR.sync = true
else
raise Error, "Log location not specified in '#{config_file}'"
end
self.master_process
end
Process.detach(master_pid)
if self.config.pid_path
File.open(self.config.pid_path, 'w') {|f| f.write(master_pid) }
end
logger.info "Master started as PID #{master_pid}"
else
self.config.logger = MonoLogger.new(STDOUT)
self.master_process
end
end