#!/usr/bin/env ruby $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'daemons' require 'fileutils' require 'flapjack/cli/notifier_manager' require 'flapjack/patches' # for Daemons # reassign ARGV so we don't mess with it directly args = ARGV args << '--help' if args.size == 0 options = Flapjack::NotifierManagerOptions.parse(args) worker_path = File.join(File.dirname(__FILE__), 'flapjack-notifier') # set up pid dir pid_dir = "/var/run/flapjack/" unless File.exists?(pid_dir) puts "#{pid_dir} doesn't exist." exit 2 end unless File.writable?(pid_dir) puts "Can't write to #{pid_dir} - check permissions?" exit 2 end daemon_args = (args + ['--', '--beanstalk', options.host, '--port', options.port.to_s, '--recipients', options.recipients]) Daemons.run(worker_path, :ARGV => daemon_args, :multiple => false, :dir_mode => :normal, :dir => pid_dir)