bin/oria in oria-0.0.1 vs bin/oria in oria-0.0.2

- old
+ new

@@ -1,4 +1,64 @@ #!/usr/bin/env ruby +require 'optparse' +# require 'rubygems' # require 'oria' +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'oria')) -# Oria.run! +module OriaCommand + def self.go + case ARGV.shift + when 'start' + start + when 'stop' + stop + when 'restart' + stop + start + else + puts parser #"Usage: oria start|stop|restart" + 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] = port + end + end + end + + def self.parse_options + @options = {:host => '0.0.0.0', :port => 6851, :debug => false} + parser.parse! + end + + def self.start + puts "Starting Oria..." + parse_options + pid = fork do + begin + Oria::Server.start(@options[:host], @options[:port], nil, @options[:debug]) + rescue RuntimeError + puts "\nOria cannot attach to port #{@options[:port]}. Maybe it's already running?" + exit + end + end + Process.detach(pid) + sleep 0.5 + puts "Oria started successfull on proccess ##{pid}" + end + + def self.stop + puts "Stopping Oria..." + puts "Stopped!" if Oria::Server.stop + rescue Errno::ESRCH + puts "Oria does not appear to be running" + end +end + +OriaCommand.go \ No newline at end of file