#!/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 start else puts parser end end def self.parser OptionParser.new do |opts| opts.banner = 'Usage: oria [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 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 => 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