Class: TokyoCacheCow::Runner
- Inherits:
-
Object
- Object
- TokyoCacheCow::Runner
- Defined in:
- lib/tokyo_cache_cow/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #parse! ⇒ Object
- #parser ⇒ Object
- #start! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tokyo_cache_cow/runner.rb', line 9 def initialize(argv) @argv = argv # Default options values @options = { :chdir => Dir.pwd, :address => '0.0.0.0', :port => Server::DefaultPort, :class => 'TokyoCacheCow::Cache::TokyoCabinetMemcache', :require => [], :file => '/tmp/tcc-cache', :pid => '/tmp/tcc.pid', :special_delete_prefix => nil, :daemonize => false, :marshalling => true } parse! end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/tokyo_cache_cow/runner.rb', line 7 def @options end |
Instance Method Details
#parse! ⇒ Object
76 77 78 |
# File 'lib/tokyo_cache_cow/runner.rb', line 76 def parse! parser.parse!(@argv) end |
#parser ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/tokyo_cache_cow/runner.rb', line 28 def parser OptionParser.new do |opts| opts. = "Usage: tokyo_cache_cow [options]" opts.separator "" opts.separator "Options:" opts.on("-p[OPTIONAL]", "--port", "Port (default: #{[:port]})") do |v| [:port] = v end opts.on("-a[OPTIONAL]", "--address", "Address (default: #{[:address]})") do |v| [:address] = v end opts.on("-c[OPTIONAL]", "--class", "Cache provider class (default: #{[:class]})") do |v| [:class] = v end opts.on("-r[OPTIONAL]", "--require", "require") do |v| [:require] << v end opts.on("-f[OPTIONAL]", "--file", "File (default: #{[:file]})") do |v| [:file] = v end opts.on("-d[OPTIONAL]", "--daemonize", "Daemonize (default: #{[:daemonize]})") do |v| [:daemonize] = true end opts.on("-P[OPTIONAL]", "--pid", "Pid file (default: #{[:pid]})") do |v| [:pid] = v end opts.on("-m[OPTIONAL]", "--matcher", "Special flag for doing matched deletes and gets (not enabled by default)") do |v| [:special_match_char] = v end opts.on("-M[=OPTIONAL]", "--marshalling", "Disable marshalling of values") do |v| [:marshalling] = false end opts.on_tail("-h", "--help", "Show this help message.") { puts opts; exit } end end |
#start! ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/tokyo_cache_cow/runner.rb', line 80 def start! @options[:require].each {|r| require r} clazz = @options[:class].to_s.split('::').inject(Kernel) do |parent, mod| parent.const_get(mod) end address = @options[:address] port = @options[:port] special_match_char = @options[:special_match_char] puts "Starting the tokyo cache cow #{address} #{port}" pid = EM.fork_reactor do cache = clazz.new(:file => @options[:file]) cache.marshalling_enabled = [:marshalling] trap("INT") { EM.stop; puts "\nmoooooooo ya later"; exit(0)} EM.run do EM.start_server(address, port, TokyoCacheCow::Server) do |c| c.cache = cache c.special_match_char = special_match_char if special_match_char end end end if @options[:daemonize] File.open([:pid], 'w') {|f| f << pid} Process.detach(pid) Process.exit!(0) else trap("INT") { } Process.wait(pid) end pid end |