Sha256: f5ea403c08f5287d7584ea367757be4bcb2bcdc31f0784695d7bedade5ac8e50

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oria-0.0.3 bin/oria