Sha256: e94f463c147b78b4df960173a2822826937325ab8afd842fdad667ab4baf86a6

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 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
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oria-0.0.2 bin/oria