Sha256: 19e0fc26b0023155e441342c53cf9ea1f820c723898c11505294d7672d6767fe
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
#!/usr/bin/env ruby require 'optparse' require 'rubygems' # require 'oria' require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'oria')) module OriaCommand def self.go case ARGV.shift when 'start' start when 'stop' stop when 'restart' stop sleep 0.5 start else puts parser end end def self.parser OptionParser.new do |opts| opts.banner = 'Usage: oria <start|stop|restart> [options]' opts.separator '' opts.on('-p', '--port [NUM]', 'The port Oria should listen on.') do |port| @options[:port] = port end opts.on('-h', '--host [IP]', 'The hostname or IP Oria should listen on.') do |host| @options[:host] = host end opts.on('-d', '--daemonize', 'Daemonize the Oria process') do |daemonize| @options[:daemonize] = true end opts.on('-D', '--debug', 'Log output to /tmp/oria.log') do |debug| @options[:debug] ||= true end end end def self.parse_options @options = {:host => '0.0.0.0', :port => Oria.port} parser.parse! end def self.start puts "Starting Oria..." parse_options start_server = lambda { $0 = "oria #{@options[:host]}:#{@options[:port]}#{' -d' if @options[:daemonize]}" Oria::Server.start(@options[:host], @options[:port], @options[:debug], :puts => !@options[:daemonize]) } if @options[:daemonize] pid = fork &start_server Process.detach(pid) else start_server.call end sleep 0.1 if Oria::Server.running? puts "Oria listening on #{@options[:host]}:#{@options[:port]}" end end def self.stop puts "Stopping Oria..." if Oria::Server.stop puts "Stopped!" else puts "Oria does not appear to be running." end end end OriaCommand.go
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oria-0.1.1 | bin/oria |
oria-0.1.0 | bin/oria |