#!/usr/bin/env ruby require 'rubygems' require 'main' URI_MATCH = /(mongo|memcache):\/\/(.+?)\:(\d+)\/(\w+)\/{0,1}(\w*)/ Main { option( 'pool=[pool]', 'p' ) { validate { |pool| pool =~ URI_MATCH } description "specify session server uri. Must be of the form {[mongo|memcache]}://{host}:{port}/{[database_name|namespace]}[/{collection_name}]. Defaults to local memcached on default port" } option( 'environment', 'e' ) { argument :required default 'production' description 'Specifies the env to run wackamole in' } @@options = {} # Enter main loop def run puts params[:pool].inspect puts params[:environment].inspect require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib wackamole])) @@options = parse_args( params[:pool].value ) ENV['RACK_ENV'] = params[:environment].value Thread.new do puts "-"*100 puts "Initializing Wackamole -- Version #{Wackamole::VERSION} -- Landscape #{params[:environment].value}" puts "-"*100 puts "\n"*2 puts ">>> Waiting for Franky to warm up..." puts "\n"*2 sleep( sleep_time ) puts "\n"*2 puts ">>> Opening console..." puts "\n"*2 open( "http://localhost:#{default_port}" ) end # Clearing args for franky! ARGV.clear require 'sinatra' require File.join(File.dirname(__FILE__), %w[.. lib app.rb]) begin Sinatra::Application.run! :port => default_port, :environment => params['environment'].value rescue => boom $stderr.puts "Oh snap! - Wackamole crapped out -- #{boom}" boom.backtrace.each { |l| $stderr.puts l } end end # default wackamole port def default_port() 7777; end # sleepy time... def sleep_time() 3; end # open console... def open(path) case RUBY_PLATFORM when /darwin/ system 'open', path when /mswin(?!ce)|mingw|cygwin|bccwin/ system 'start', path else system 'firefox', path end end # parse uri into sub components def parse_args( server_uri ) return unless server_uri tokens = server_uri.match( URI_MATCH ).captures opts = { :protocol => tokens.first, :host => tokens[1], :port => tokens[2] } if opts[:protocol] == "mongo" opts[:db_name] = tokens[3] opts[:cltn_name] = tokens[4] else opts[:namespace] = tokens[3] end opts end }