bin/oria in oria-0.0.3 vs bin/oria in oria-0.1.0
- old
+ new
@@ -1,20 +1,21 @@
#!/usr/bin/env ruby
require 'optparse'
require 'rubygems'
-require 'oria'
-# require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'oria'))
+# 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
@@ -25,43 +26,51 @@
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
+ @options[:host] = host
end
- opts.on('-d', '--debug', 'Log output to /tmp/oria.log') do |debug|
- @options[:debug] = true
+ 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 => 6851, :debug => false}
+ @options = {:host => '0.0.0.0', :port => Oria.port}
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
+ 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
- Process.detach(pid)
- sleep 0.5
- puts "Oria started successfull on proccess ##{pid}"
+ sleep 0.1
+ if Oria::Server.running?
+ puts "Oria listening on #{@options[:host]}:#{@options[:port]}"
+ end
end
def self.stop
puts "Stopping Oria..."
- puts "Stopped!" if Oria::Server.stop
- rescue Errno::ESRCH
- puts "Oria does not appear to be running"
+ if Oria::Server.stop
+ puts "Stopped!"
+ else
+ puts "Oria does not appear to be running."
+ end
end
end
OriaCommand.go
\ No newline at end of file