Sha256: 3cd6f756c97b4f70936beb233e7587a7dfeaa06bab6b62d69bb2335cbd0cd059

Contents?: true

Size: 1.93 KB

Versions: 10

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

ARGV << '--help' if ARGV.empty?

require 'optparse'
require 'rapnd'
require 'daemons'

command = ARGV.shift

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: rapnd [options]"

  opts.on("--cert=MANDATORY", "Location of the cert pem file") do |cert|
    options[:cert] = cert
  end

  opts.on("--password=OPTIONAL", "Password for the cert pem file") do |password|
    options[:password] = password
  end

  opts.on("--redis_host=OPTIONAL", "Redis hostname") do |host|
    options[:redis_host] = host
  end

  opts.on("--redis_port=OPTIONAL", "Redis port") do |port|
    options[:redis_port] = port
  end

  opts.on("--environment=OPTIONAL", "Specify sandbox or production") do |env|
    if env == 'production'
      options[:host] = 'gateway.push.apple.com'
    else
      options[:host] = 'gateway.sandbox.push.apple.com'
    end
  end

  opts.on("--queue=OPTIONAL", "Name of the redis queue") do |queue|
    options[:queue] = queue
  end

  opts.on("--foreground", "Run in the foreground") do |fore|
    options[:foreground] = true
  end

  opts.on("--dir=OPTIONAL", "Directory to start in") do |dir|
    options[:dir] = dir
  end
  
  opts.on("--airbrake=OPTIONAL", "Airbrake API key") do |airbrake|
    options[:airbrake] = airbrake
  end

  opts.on('--help', 'Show help') do |help|
    puts opts
  end
end.parse!

case command
when 'start'
  unless options[:foreground]
    Daemons.daemonize(
      :app_name => options[:queue],
      :dir_mode => :normal,
      :dir => "#{options[:dir]}/tmp",
      :log_dir => "#{options[:dir]}/log",
      :backtrace => true,
      :log_output => true
    )
  end

  Rapnd::Daemon.new(options).run!
when 'stop'
  unless options[:foreground]
    files = Daemons::PidFile.find_files("#{options[:dir]}/tmp", options[:queue])
    files.each do |file|
      pid = File.open(file) {|h| h.read}.to_i
      `kill -9 #{pid}`
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rapnd-0.4.1 bin/rapnd
rapnd-0.4.0 bin/rapnd
rapnd-0.3.1 bin/rapnd
rapnd-0.3.0 bin/rapnd
rapnd-0.2.5 bin/rapnd
rapnd-0.2.4 bin/rapnd
rapnd-0.2.3 bin/rapnd
rapnd-0.2.2 bin/rapnd
rapnd-0.2.1 bin/rapnd
rapnd-0.2.0 bin/rapnd