oria 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/bin/oria +61 -1
  3. data/lib/oria/server.rb +21 -2
  4. data/oria.gemspec +62 -0
  5. metadata +2 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/bin/oria CHANGED
@@ -1,4 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ # require 'rubygems'
2
4
  # require 'oria'
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'oria'))
3
6
 
4
- # Oria.run!
7
+ module OriaCommand
8
+ def self.go
9
+ case ARGV.shift
10
+ when 'start'
11
+ start
12
+ when 'stop'
13
+ stop
14
+ when 'restart'
15
+ stop
16
+ start
17
+ else
18
+ puts parser #"Usage: oria start|stop|restart"
19
+ end
20
+ end
21
+
22
+ def self.parser
23
+ OptionParser.new do |opts|
24
+ opts.banner = 'Usage: oria <start|stop|restart> [options]'
25
+ opts.separator ''
26
+ opts.on('-p', '--port [NUM]', 'The port Oria should listen on.') do |port|
27
+ @options[:port] = port
28
+ end
29
+ opts.on('-h', '--host [IP]', 'The hostname or IP Oria should listen on.') do |host|
30
+ @options[:host] = port
31
+ end
32
+ end
33
+ end
34
+
35
+ def self.parse_options
36
+ @options = {:host => '0.0.0.0', :port => 6851, :debug => false}
37
+ parser.parse!
38
+ end
39
+
40
+ def self.start
41
+ puts "Starting Oria..."
42
+ parse_options
43
+ pid = fork do
44
+ begin
45
+ Oria::Server.start(@options[:host], @options[:port], nil, @options[:debug])
46
+ rescue RuntimeError
47
+ puts "\nOria cannot attach to port #{@options[:port]}. Maybe it's already running?"
48
+ exit
49
+ end
50
+ end
51
+ Process.detach(pid)
52
+ sleep 0.5
53
+ puts "Oria started successfull on proccess ##{pid}"
54
+ end
55
+
56
+ def self.stop
57
+ puts "Stopping Oria..."
58
+ puts "Stopped!" if Oria::Server.stop
59
+ rescue Errno::ESRCH
60
+ puts "Oria does not appear to be running"
61
+ end
62
+ end
63
+
64
+ OriaCommand.go
data/lib/oria/server.rb CHANGED
@@ -13,7 +13,13 @@ module Oria
13
13
  end
14
14
 
15
15
  def start(server, port, app_key = nil, debug = false)
16
- @@pid = Process.pid
16
+ at_exit do
17
+ Oria::Server.stop
18
+ end
19
+ pid = Process.pid
20
+ File.open(pid_file, 'w') do |file|
21
+ file.puts pid
22
+ end
17
23
  app_key ||= 'default'
18
24
  @@servers ||= if File.exists?(yaml_store)
19
25
  YAML.load_file(yaml_store)
@@ -28,7 +34,12 @@ module Oria
28
34
  end
29
35
 
30
36
  def stop
31
- Process.kill('HUP', @@pid) if defined?(@@pid)
37
+ if File.exists?(pid_file)
38
+ if pid
39
+ Process.kill(9, pid)
40
+ end
41
+ File.unlink(pid_file)
42
+ end
32
43
  end
33
44
 
34
45
  def write_hash
@@ -44,6 +55,14 @@ module Oria
44
55
  @@log_file ||= File.join(Dir.tmpdir, 'oria.log')
45
56
  end
46
57
 
58
+ def pid
59
+ @@pid ||= File.read(pid_file).to_i if File.exists?(pid_file)
60
+ end
61
+
62
+ def pid_file
63
+ @@pid_file ||= File.join(Dir.tmpdir, 'oria.pid')
64
+ end
65
+
47
66
  def yaml_store
48
67
  @@yaml_store ||= File.join(Dir.tmpdir, 'oria.yml')
49
68
  end
data/oria.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{oria}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Flip Sasser"]
12
+ s.date = %q{2009-11-22}
13
+ s.default_executable = %q{oria}
14
+ s.description = %q{}
15
+ s.email = %q{flip@x451.com}
16
+ s.executables = ["oria"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.markdown"
20
+ ]
21
+ s.files = [
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/oria",
27
+ "lib/oria.rb",
28
+ "lib/oria/client.rb",
29
+ "lib/oria/errors.rb",
30
+ "lib/oria/server.rb",
31
+ "spec/oria_spec.rb",
32
+ "spec/rcov.opts",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/flipsasser/oria}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{A Ruby-based, in-memory KVS with one half of the peristence you want}
41
+ s.test_files = [
42
+ "spec/oria_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
52
+ s.add_runtime_dependency(%q<json>, [">= 2.0.0"])
53
+ else
54
+ s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
55
+ s.add_dependency(%q<json>, [">= 2.0.0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
59
+ s.add_dependency(%q<json>, [">= 2.0.0"])
60
+ end
61
+ end
62
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oria
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flip Sasser
@@ -51,6 +51,7 @@ files:
51
51
  - lib/oria/client.rb
52
52
  - lib/oria/errors.rb
53
53
  - lib/oria/server.rb
54
+ - oria.gemspec
54
55
  - spec/oria_spec.rb
55
56
  - spec/rcov.opts
56
57
  - spec/spec.opts