Sha256: c91c5c67bb11e255624f31cfc1d324633bb8679ce37c69ffa68d977a67990d7c

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), *%w[.. lib]))
ERNIE_ROOT = File.join(File.dirname(__FILE__), *%w[..])

DEFAULT_ERLANG_CODEPATHS = %w[ebin]

def rel(path)
  File.join(ERNIE_ROOT, path)
end

def code_paths
  DEFAULT_ERLANG_CODEPATHS.map {|n| "-pz #{rel(n)}" }.join(" ") + " \\"
end

require 'optparse'
require 'pp'

help = <<HELP
Ernie is an Erlang/Ruby BERT-RPC Server.

Basic Command Line Usage:
  ernie [options] <path to handler file>

Options:
HELP

options = {}
OptionParser.new do |opts|
  opts.banner = help

  opts.on("-p PORT", "--port PORT", "Port") do |x|
    options[:port] = x
  end

  opts.on("-n NUMBER", "--number NUMBER", "Number of handler instances") do |x|
    options[:number] = x
  end

  opts.on("-d", "--detached", "Run as a daemon") do
    options[:detached] = true
  end

  opts.on("-P", "--pidfile PIDFILE", "Location to write pid file.") do |x|
    options[:pidfile] = x
  end
end.parse!

handler = ARGV[0]

unless handler
  puts "A handler must be specified: ernie /path/to/handler.rb"
  exit(1)
end

port = options[:port] || 8000
number = options[:number] || 1
pidfile = options[:pidfile] ? "-ernie_server_app pidfile \"'#{options[:pidfile]}'\"" : ''
detached = options[:detached] ? '-detached' : ''

cmd = %Q{erl -boot start_sasl \
             #{detached} \
             +Bc \
             +K true \
             -smp enable \
             #{code_paths}
             #{pidfile} \
             -ernie_server_app port #{port} \
             -ernie_server_app handler '"#{handler}"' \
             -ernie_server_app number #{number} \
             -run ernie_server_app boot}.squeeze(' ')
puts cmd
exec(cmd)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mojombo-ernie-0.2.0 bin/ernie