boned 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,5 +1,13 @@
1
1
  BONED, CHANGES
2
2
 
3
+ #### 0.2.1 (2010-01-08) ###############################
4
+
5
+ * FIXED: Missing config.ru error
6
+ * FIXED: Redis available check
7
+ * CHANGE: Use BONED_REDIS variable instead of redis.yml file
8
+ * CHANGE: Start redis server if not running
9
+
10
+
3
11
  #### 0.1.0 (2009-12-13) ###############################
4
12
 
5
13
  Initial release
data/README.md CHANGED
@@ -1,32 +1,35 @@
1
- ## Bone - 0.2 ##
1
+ ## Boned - 0.2 ##
2
2
 
3
3
  **Bones it!**
4
4
 
5
5
 
6
- == Running
6
+ ## Running
7
7
 
8
8
  $ redis-server config/redis-server.conf
9
+ $ export BONED_REDIS=redis://localhost:4111/1
9
10
  $ boned start
10
11
 
11
12
 
12
- == Installation
13
+ ## Installation
13
14
 
14
15
  $ sudo gem install boned
15
-
16
16
 
17
- == More Information
17
+ You also need to install [redis](http://code.google.com/p/redis/).
18
+
19
+
20
+ ## More Information
18
21
 
19
22
 
20
- == Credits
23
+ ## Credits
21
24
 
22
25
  * Delano Mandelbaum (http://solutious.com)
23
26
 
24
27
 
25
- == Thanks
28
+ ## Thanks
26
29
 
27
30
  * Kalin Harvey for the early feedback.
28
31
 
29
32
 
30
- == License
33
+ ## License
31
34
 
32
35
  See LICENSE.txt
File without changes
File without changes
data/boned.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "boned"
3
3
  s.rubyforge_project = 'boned'
4
- s.version = "0.2.0"
5
- s.summary = "Get Bones"
4
+ s.version = "0.2.1"
5
+ s.summary = "The bone daemon"
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
8
8
  s.email = "delano@solutious.com"
@@ -10,7 +10,7 @@
10
10
 
11
11
  s.extra_rdoc_files = %w[README.md LICENSE.txt CHANGES.txt]
12
12
  s.has_rdoc = true
13
- s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.rdoc"]
13
+ s.rdoc_options = ["--line-numbers", "--title", s.summary, "--main", "README.md"]
14
14
  s.require_paths = %w[lib]
15
15
 
16
16
  s.executables = %w[boned]
@@ -18,15 +18,15 @@
18
18
  # = MANIFEST =
19
19
  # git ls-files
20
20
  s.files = %w(
21
+ CHANGES.txt
21
22
  LICENSE.txt
22
23
  README.md
23
24
  Rakefile
25
+ api/api-set.rb
26
+ api/api.rb
24
27
  bin/boned
25
28
  boned.gemspec
26
- config/redis-default.yml
27
- config/redis-server-default.conf
28
- config/stella/api-set.rb
29
- config/stella/api.rb
29
+ config.ru
30
30
  lib/boned.rb
31
31
  lib/boned/api.rb
32
32
  lib/boned/api/debug.rb
data/config.ru ADDED
@@ -0,0 +1,31 @@
1
+ # Rackup - GetBones.com
2
+ # 2009-12-11
3
+
4
+ ENV['RACK_ENV'] ||= 'production'
5
+ ENV['APP_ROOT'] = ::File.expand_path(::File.join(::File.dirname(__FILE__)))
6
+ $:.unshift(::File.join(ENV['APP_ROOT'], 'lib'))
7
+
8
+ require 'sinatra'
9
+
10
+ require 'boned/api'
11
+
12
+ disable :run # disable sinatra's auto-application starting
13
+
14
+ configure :production do
15
+ Boned.debug = false
16
+
17
+ map("/#{Boned::APIVERSION}/") { run Boned::API::Service }
18
+
19
+ end
20
+
21
+ configure :development do
22
+ use Rack::ShowExceptions
23
+
24
+ require 'boned/api/debug'
25
+ require 'boned/api/redis'
26
+
27
+ map("/#{Boned::APIVERSION}/") { run Boned::API::Service }
28
+ map("/debug") { run Boned::API::Debug }
29
+ map("/redis") { run Boned::API::RedisViewer }
30
+
31
+ end
data/lib/boned.rb CHANGED
@@ -7,17 +7,23 @@ require 'attic'
7
7
  require 'gibbler/aliases'
8
8
  require 'sysinfo'
9
9
  require 'socket'
10
+ require 'uri'
11
+ require 'rye'
10
12
 
11
13
  unless defined?(BONED_HOME)
12
14
  BONED_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..') )
13
15
  end
14
16
 
15
- module Boned
16
- APIVERSION = 'v1'.freeze unless defined?(APIVERSION)
17
+ module Boned
18
+ unless defined?(APIVERSION)
19
+ APIVERSION = 'v1'.freeze
20
+ BONED_REDIS = "redis://127.0.0.1:8045/1".freeze
21
+ end
22
+
17
23
  module VERSION
18
24
  MAJOR = 0
19
25
  MINOR = 2
20
- TINY = 0
26
+ TINY = 1
21
27
  PATCH = '001'
22
28
  def self.inspect; [to_s, PATCH].join('.'); end
23
29
  def self.to_s; [MAJOR, MINOR, TINY].join('.'); end
@@ -33,6 +39,7 @@ module Boned
33
39
  @debug = false
34
40
  @conf = nil
35
41
  @redis = nil
42
+ @redis_thread = nil
36
43
  @sysinfo = nil
37
44
  class << self
38
45
  attr_accessor :debug
@@ -46,24 +53,30 @@ module Boned
46
53
  @sysinfo
47
54
  end
48
55
  end
49
-
56
+
50
57
  # Connect to Redis and Mongo.
51
- def self.connect(conf=@conf)
52
- @redis = Redis.new conf[:redis]
58
+ def self.connect
59
+ update_redis_client_config
60
+ start_redis unless redis_available?
61
+ abort "No Redis" unless redis_available?
62
+ @redis = Redis.new @conf[:redis]
53
63
  end
54
64
 
55
- # Loads the yaml config files from config/
56
- # * +base+ path where config dir lives
57
- # * +env one of: :development, :production
58
- # Returns a Hash: conf[:mongo][:host], ...
59
- def self.load_config(base=Dir.pwd, env=:development)
60
- @conf = {}
61
- [:redis].each do |n|
62
- Boned.ld "LOADING CONFIG: #{n}"
63
- tmp = YAML.load_file(File.join(base, "config", "#{n}.yml"))
64
- @conf[n] = tmp[ env.to_sym ]
65
+ def self.start_redis
66
+ return Problem, "Redis already running" if redis_available?
67
+ conf_path = File.join(BONED_HOME, 'config', 'redis-server.conf')
68
+ ld "REDIS SERVER CONF: #{conf_path}"
69
+ @redis_thread = Thread.new do
70
+ Rye.shell 'redis-server', conf_path
65
71
  end
66
- @conf
72
+ sleep 2 # Give redis time to start.
73
+ end
74
+
75
+ def self.stop_redis
76
+ ld "SHUTDOWN REDIS"
77
+ @redis.shutdown if redis_available?
78
+ return if @redis_thread.nil? || !@redis_thread.alive?
79
+ @redis_thread.join
67
80
  end
68
81
 
69
82
  # <tt>require</tt> a library from the vendor directory.
@@ -102,6 +115,9 @@ module Boned
102
115
  # Errno::EAFNOSUPPORT, Errno::ECONNREFUSED, SocketError, Timeout::Error
103
116
  #
104
117
  def self.service_available?(host, port, wait=3)
118
+ a = Socket.getaddrinfo @conf[:redis][:host], @conf[:redis][:port]
119
+ ip_addr = a[0][3]
120
+ ld "SERVICE: #{host} (#{ip_addr}) #{port}"
105
121
  if Boned.sysinfo.vm == :java
106
122
  begin
107
123
  iadd = Java::InetSocketAddress.new host, port
@@ -127,6 +143,22 @@ module Boned
127
143
  end
128
144
  end
129
145
 
146
+ def self.redis_available?
147
+ service_available? @conf[:redis][:host], @conf[:redis][:port]
148
+ end
149
+
150
+ def self.update_redis_client_config(uri=nil)
151
+ uri ||= ENV['BONED_REDIS'] || BONED_REDIS
152
+ uri = URI.parse(uri)
153
+ @conf ||= {}
154
+ @conf[:redis] = {
155
+ :host => uri.host,
156
+ :port => uri.port || 8045,
157
+ :database => uri.path.sub(/\D/, "").to_i || 1,
158
+ :password => uri.user || nil
159
+ }
160
+ ld "REDIS: #{@conf[:redis].inspect}"
161
+ end
130
162
 
131
163
  def self.ld(*msg)
132
164
  return unless Boned.debug
@@ -134,6 +166,7 @@ module Boned
134
166
  puts "#{prefix}" << msg.join("#{$/}#{prefix}")
135
167
  end
136
168
 
169
+ update_redis_client_config # parse ENV['BONED_REDIS']
137
170
  end
138
171
 
139
172
  require 'boned/models'
data/lib/boned/cli.rb CHANGED
@@ -5,7 +5,6 @@ class Boned::CLI < Drydock::Command
5
5
  attr_accessor :exit_code
6
6
 
7
7
  def init
8
- Boned.load_config Dir.pwd, :development
9
8
  Boned.connect
10
9
  end
11
10
 
@@ -17,6 +16,7 @@ class Boned::CLI < Drydock::Command
17
16
  end
18
17
 
19
18
  def stop
19
+ Boned.stop_redis
20
20
  if not Boned.service_available?('127.0.0.1', server_opts[:port])
21
21
  raise Boned::Server::ServerNotRunning, server_opts[:port]
22
22
  end
@@ -37,7 +37,7 @@ class Boned::CLI < Drydock::Command
37
37
 
38
38
  def server_opts
39
39
  port = @global.port || Boned::Server::DEFAULT_PORT
40
- config = @global.rackup || File.join(Dir.pwd, "config.ru")
40
+ config = @global.rackup || File.join(BONED_HOME, "config.ru")
41
41
  @server_opts ||= {
42
42
  :chdir => Dir.pwd,
43
43
  :environment => @global.environment || 'development',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boned
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-13 00:00:00 -05:00
12
+ date: 2010-01-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: Get Bones
16
+ description: The bone daemon
17
17
  email: delano@solutious.com
18
18
  executables:
19
19
  - boned
@@ -24,15 +24,15 @@ extra_rdoc_files:
24
24
  - LICENSE.txt
25
25
  - CHANGES.txt
26
26
  files:
27
+ - CHANGES.txt
27
28
  - LICENSE.txt
28
29
  - README.md
29
30
  - Rakefile
31
+ - api/api-set.rb
32
+ - api/api.rb
30
33
  - bin/boned
31
34
  - boned.gemspec
32
- - config/redis-default.yml
33
- - config/redis-server-default.conf
34
- - config/stella/api-set.rb
35
- - config/stella/api.rb
35
+ - config.ru
36
36
  - lib/boned.rb
37
37
  - lib/boned/api.rb
38
38
  - lib/boned/api/debug.rb
@@ -45,7 +45,6 @@ files:
45
45
  - public/index.html
46
46
  - try/10_bone_model.rb
47
47
  - views/redisviewer/keys.erb
48
- - CHANGES.txt
49
48
  has_rdoc: true
50
49
  homepage: ""
51
50
  licenses: []
@@ -54,9 +53,9 @@ post_install_message:
54
53
  rdoc_options:
55
54
  - --line-numbers
56
55
  - --title
57
- - Get Bones
56
+ - The bone daemon
58
57
  - --main
59
- - README.rdoc
58
+ - README.md
60
59
  require_paths:
61
60
  - lib
62
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -77,6 +76,6 @@ rubyforge_project: boned
77
76
  rubygems_version: 1.3.5
78
77
  signing_key:
79
78
  specification_version: 3
80
- summary: Get Bones
79
+ summary: The bone daemon
81
80
  test_files: []
82
81
 
@@ -1,14 +0,0 @@
1
- :development:
2
- # :password: e89da64b29cf622e7c0fa545b537d7
3
- :host: localhost
4
- :port: "6379"
5
- :db: 1
6
- :timeout: 5
7
- :thread_safe: true
8
- :production:
9
- # :password: e89da64b29cf622e7c0fa545b537d7
10
- :host: localhost
11
- :port: "6379"
12
- :db: 0
13
- :timeout: 5
14
- :thread_safe: true
@@ -1,171 +0,0 @@
1
- # Redis configuration file example
2
-
3
- # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
- # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
- daemonize no
6
-
7
- # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
- # You can specify a custom pid file location here.
9
- pidfile /var/run/redis.pid
10
-
11
- # Accept connections on the specified port, default is 6379
12
- port 6379
13
-
14
- # If you want you can bind a single interface, if the bind option is not
15
- # specified all the interfaces will listen for connections.
16
- #
17
- # bind 127.0.0.1
18
-
19
- # Close the connection after a client is idle for N seconds (0 to disable)
20
- timeout 300
21
-
22
- # Save the DB on disk:
23
- #
24
- # save <seconds> <changes>
25
- #
26
- # Will save the DB if both the given number of seconds and the given
27
- # number of write operations against the DB occurred.
28
- #
29
- # In the example below the behaviour will be to save:
30
- # after 900 sec (15 min) if at least 1 key changed
31
- # after 300 sec (5 min) if at least 10 keys changed
32
- # after 60 sec if at least 10000 keys changed
33
- save 900 1
34
- save 300 10
35
- save 60 10000
36
-
37
- # The filename where to dump the DB
38
- dbfilename dump.rdb
39
-
40
- # For default save/load DB in/from the working directory
41
- # Note that you must specify a directory not a file name.
42
- dir ./
43
-
44
- # Set server verbosity to 'debug'
45
- # it can be one of:
46
- # debug (a lot of information, useful for development/testing)
47
- # notice (moderately verbose, what you want in production probably)
48
- # warning (only very important / critical messages are logged)
49
- loglevel debug
50
-
51
- # Specify the log file name. Also 'stdout' can be used to force
52
- # the demon to log on the standard output. Note that if you use standard
53
- # output for logging but daemonize, logs will be sent to /dev/null
54
- logfile stdout
55
-
56
- # Set the number of databases. The default database is DB 0, you can select
57
- # a different one on a per-connection basis using SELECT <dbid> where
58
- # dbid is a number between 0 and 'databases'-1
59
- databases 16
60
-
61
- ################################# REPLICATION #################################
62
-
63
- # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
- # another Redis server. Note that the configuration is local to the slave
65
- # so for example it is possible to configure the slave to save the DB with a
66
- # different interval, or to listen to another port, and so on.
67
-
68
- # slaveof <masterip> <masterport>
69
-
70
- ################################## SECURITY ###################################
71
-
72
- # Require clients to issue AUTH <PASSWORD> before processing any other
73
- # commands. This might be useful in environments in which you do not trust
74
- # others with access to the host running redis-server.
75
- #
76
- # This should stay commented out for backward compatibility and because most
77
- # people do not need auth (e.g. they run their own servers).
78
-
79
- # requirepass foobared
80
-
81
- ################################### LIMITS ####################################
82
-
83
- # Set the max number of connected clients at the same time. By default there
84
- # is no limit, and it's up to the number of file descriptors the Redis process
85
- # is able to open. The special value '0' means no limts.
86
- # Once the limit is reached Redis will close all the new connections sending
87
- # an error 'max number of clients reached'.
88
-
89
- # maxclients 128
90
-
91
- # Don't use more memory than the specified amount of bytes.
92
- # When the memory limit is reached Redis will try to remove keys with an
93
- # EXPIRE set. It will try to start freeing keys that are going to expire
94
- # in little time and preserve keys with a longer time to live.
95
- # Redis will also try to remove objects from free lists if possible.
96
- #
97
- # If all this fails, Redis will start to reply with errors to commands
98
- # that will use more memory, like SET, LPUSH, and so on, and will continue
99
- # to reply to most read-only commands like GET.
100
- #
101
- # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
- # 'state' server or cache, not as a real DB. When Redis is used as a real
103
- # database the memory usage will grow over the weeks, it will be obvious if
104
- # it is going to use too much memory in the long run, and you'll have the time
105
- # to upgrade. With maxmemory after the limit is reached you'll start to get
106
- # errors for write operations, and this may even lead to DB inconsistency.
107
-
108
- # maxmemory <bytes>
109
-
110
- ############################## APPEND ONLY MODE ###############################
111
-
112
- # By default Redis asynchronously dumps the dataset on disk. If you can live
113
- # with the idea that the latest records will be lost if something like a crash
114
- # happens this is the preferred way to run Redis. If instead you care a lot
115
- # about your data and don't want to that a single record can get lost you should
116
- # enable the append only mode: when this mode is enabled Redis will append
117
- # every write operation received in the file appendonly.log. This file will
118
- # be read on startup in order to rebuild the full dataset in memory.
119
- #
120
- # Note that you can have both the async dumps and the append only file if you
121
- # like (you have to comment the "save" statements above to disable the dumps).
122
- # Still if append only mode is enabled Redis will load the data from the
123
- # log file at startup ignoring the dump.rdb file.
124
- #
125
- # The name of the append only file is "appendonly.log"
126
-
127
- appendonly no
128
-
129
- # The fsync() call tells the Operating System to actually write data on disk
130
- # instead to wait for more data in the output buffer. Some OS will really flush
131
- # data on disk, some other OS will just try to do it ASAP.
132
- #
133
- # Redis supports three different modes:
134
- #
135
- # no: don't fsync, just let the OS flush the data when it wants. Faster.
136
- # always: fsync after every write to the append only log . Slow, Safest.
137
- # everysec: fsync only if one second passed since the last fsync. Compromise.
138
- #
139
- # The default is "always" that's the safer of the options. It's up to you to
140
- # understand if you can relax this to "everysec" that will fsync every second
141
- # or to "no" that will let the operating system flush the output buffer when
142
- # it want, for better performances (but if you can live with the idea of
143
- # some data loss consider the default persistence mode that's snapshotting).
144
-
145
- appendfsync always
146
- # appendfsync everysec
147
- # appendfsync no
148
-
149
- ############################### ADVANCED CONFIG ###############################
150
-
151
- # Glue small output buffers together in order to send small replies in a
152
- # single TCP packet. Uses a bit more CPU but most of the times it is a win
153
- # in terms of number of queries per second. Use 'yes' if unsure.
154
- glueoutputbuf yes
155
-
156
- # Use object sharing. Can save a lot of memory if you have many common
157
- # string in your dataset, but performs lookups against the shared objects
158
- # pool so it uses more CPU and can be a bit slower. Usually it's a good
159
- # idea.
160
- #
161
- # When object sharing is enabled (shareobjects yes) you can use
162
- # shareobjectspoolsize to control the size of the pool used in order to try
163
- # object sharing. A bigger pool size will lead to better sharing capabilities.
164
- # In general you want this value to be at least the double of the number of
165
- # very common strings you have in your dataset.
166
- #
167
- # WARNING: object sharing is experimental, don't enable this feature
168
- # in production before of Redis 1.0-stable. Still please try this feature in
169
- # your development environment so that we can test it better.
170
- shareobjects no
171
- shareobjectspoolsize 1024