#!/usr/bin/env ruby $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'getoptlong' require 'rubygems' require 'daemons' require 'racoon' require 'csv' def usage puts "Usage: racoon-firehose [switches]" puts " --pid the path to store the pid" puts " --log the path to store the log" puts " --daemon to daemonize the server" puts " --help this message" end def daemonize Daemonize.daemonize(@log_file, 'racoon-firehose') open(@pid_file,"w") { |f| f.write(Process.pid) } open(@pid_file,"w") do |f| f.write(Process.pid) File.chmod(0644, @pid_file) end end opts = GetoptLong.new( ["--pid", "-i", GetoptLong::REQUIRED_ARGUMENT], ["--log", "-l", GetoptLong::REQUIRED_ARGUMENT], ["--help", "-h", GetoptLong::NO_ARGUMENT], ["--daemon", "-d", GetoptLong::NO_ARGUMENT] ) @pid_file = '/var/run/racoon-firehose.pid' @log_file = '/var/log/racoon-firehose.log' daemon = false opts.each do |opt, arg| case opt when '--help' usage exit 1 when '--pid' @pid_file = arg when '--log' @log_file = arg when '--daemon' daemon = true end end Racoon::Config.logger = Logger.new(@log_file) if daemon daemonize else puts "Starting racoon worker." end Racoon::Firehose.new.start!