Sha256: 7fd840f74f857d4c2ae03562975529a5bcf7d5ec43cf0c1cd3c07b32f9d9b6cb

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))

require 'fake_sqs'
require 'optparse'

options = { :port => 4568, :host => "0.0.0.0", :verbose => false, :daemonize => false }

parser = OptionParser.new do |o|

  o.on "-p", "--port PORT", Integer, "Port to use (default: #{options[:port]})" do |port|
    options[:port] = port
  end

  o.on "-o", "--bind HOST", "Host to bind to (default: 0.0.0.0)" do |host|
    options[:host] = host
  end

  o.on "-s", "--server SERVER", ['thin', 'mongrel', 'webrick'], "Server to use: thin, mongrel or webrick (by default Sinatra chooses the best available)" do |server|
    options[:server] = server
  end

  o.on "-P", "--pid PIDFILE", "Where to write the pid" do |pid|
    options[:pid] = pid
  end

  o.on "-d", "--[no-]daemonize", "Detaches the process" do |daemonize|
    options[:daemonize] = daemonize
  end

  o.on "-v", "--[no]-verbose", "Shows input parameters and output XML" do |verbose|
    options[:verbose] = verbose
  end

  o.on_tail "--version", "Shows the version" do
    puts "fake_sqs version #{FakeSQS::VERSION}"
    exit
  end

  o.on_tail "-h", "--help", "Shows this help page" do
    puts o
    exit
  end

end

parser.parse!

app = FakeSQS::WebInterface

if options[:verbose]
  require 'fake_sqs/show_output'
  app.use FakeSQS::ShowOutput
end

if options[:daemonize]
  Process.daemon(true, true)
end

if (pid = options[:pid])
  if File.exist?(pid)
    existing_pid = File.open(pid, 'r').read.chomp.to_i
    running = Process.getpgid(existing_pid) rescue false
    if running
      warn "Error, Process #{existing_pid} already running"
      exit 1
    else
      warn "Cleaning up stale pid at #{pid}"
    end
  end
  File.open(pid, 'w') { |f| f.write(Process.pid) }
end

app.set :port, options[:port]
app.set :bind, options[:host]
app.set :server, options[:server] if options[:server]
server = FakeSQS.server(port: options[:port], host: options[:host])
app.set :api, FakeSQS.api(server: server)
app.run!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fake_sqs-0.0.8 bin/fake_sqs