Permalink
Browse files

Updated with example yml and initializer. Also some new settings.

  • Loading branch information...
1 parent dad636b commit e64a2a3ccb7105fcb9e7dde1c230e365660464a9 @jnunemaker jnunemaker committed Jul 15, 2010
Showing with 104 additions and 6 deletions.
  1. +16 −3 README.rdoc
  2. +42 −2 lib/mongodb.rb
  3. +15 −1 templates/mongo.init.erb
  4. +6 −0 templates/mongo.rb
  5. +25 −0 templates/mongo.yml
View
@@ -7,6 +7,19 @@ A plugin for installing and managing mongodb.
=== Instructions
* <tt>script/plugin install git://github.com/orderedlist/moonshine_mongodb.git</tt>
-* Include the plugin and recipe(s) in your Moonshine manifest
- plugin :mongodb
- recipe :mongodb
+* Include the recipe in your Moonshine manifest
+ recipe :mongodb
+* Create a file 'config/mongo.yml' with your settings:
+
+ development: &global_settings
+ database: myapp-development
+ host: 127.0.0.1
+ port: 27017
+
+ production:
+ database: myapp
+ username: username
+ password: password
+ <<: *global_settings
+
+* Copy over the mongo.rb initializer: <tt>cp vendor/plugins/moonshine_mongodb/templates/mongo.rb config/initializers/</tt>
View
@@ -1,4 +1,29 @@
+require 'pathname'
+
module Mongodb
+ def self.included(manifest)
+ manifest.class_eval do
+ extend ClassMethods
+ end
+ end
+
+ module ClassMethods
+ def mongo_yml
+ @mongo_yml ||= Pathname.new(configuration[:deploy_to]) + 'shared/config/mongo.yml'
+ end
+
+ def mongo_rb
+ @mongo_rb ||= Pathname.new(configuration[:deploy_to]) + 'current/config/initializers/mongo.rb'
+ end
+
+ def mongo_configuration
+ configuration[:mongo][rails_env.to_sym]
+ end
+
+ def mongo_template_dir
+ @mongo_template_dir ||= Pathname.new(__FILE__).dirname.dirname.join('templates')
+ end
+ end
# Define options for this plugin via the <tt>configure</tt> method
# in your application manifest:
@@ -10,16 +35,31 @@ module Mongodb
# plugin :mongodb
# recipe :mongodb
def mongodb(hash = {})
+ configure :mongo => YAML::load(template(mongo_template_dir + 'mongo.yml', binding))
+
options = {
- :version => '1.4.0'
+ :version => '1.4.4',
+ :master => false,
+ :auth => false,
+ :slave_enabled => false,
+ :slave => {
+ :auto_resync => false,
+ :source_master => '',
+ :source_port => 27017
+ }
}.merge(hash)
+ # dependencies for install
package 'wget', :ensure => :installed
+ # default dirs for mongo storage
file '/data', :ensure => :directory
file '/data/db', :ensure => :directory
+ # install location
file '/opt/local', :ensure => :directory
+ # logs
file '/var/log/mongodb', :ensure => :directory
+
arch = Facter.architecture
arch = 'i686' if arch == 'i386'
@@ -51,4 +91,4 @@ def mongodb(hash = {})
]
end
-end
+end
View
@@ -73,6 +73,20 @@ DIETIME=10 # Time to wait for the server to die, in seconds
LOGFILE=$LOGDIR/$NAME.log # Server logfile
DAEMON_OPTS="--dbpath $DATA run"
+<% if options[:master] %>
+ DAEMON_OPTS="--master $DAEMON_OPTS"
+<% end %>
+
+<% if options[:auth] %>
+ DAEMON_OPTS="--auth $DAEMON_OPTS"
+<% end %>
+
+<% if options[:slave_enabled] %>
+ <% if options[:slave][:auto_resync] %>
+ DAEMON_OPTS="--autoresync $DAEMON_OPTS"
+ <% end %>
+ DAEMON_OPTS="--source <%= options[:slave][:source_master] %>:<%= options[:slave][:source_port] %>"
+<% end %>
# Include mongodb defaults if available
@@ -292,4 +306,4 @@ case "$1" in
;;
esac
-exit 0
+exit 0
View
@@ -0,0 +1,6 @@
+require 'mongo_mapper'
+
+MongoMapper.setup(YAML.load_file(Rails.root.join('config', 'mongo.yml')), Rails.env, {
+ :logger => Rails.logger,
+ :passenger => true,
+})
View
@@ -0,0 +1,25 @@
+development: &global_settings
+ database: myapp-development
+ host: 127.0.0.1
+ port: 27017
+
+test:
+ database: myapp-test
+ <<: *global_settings
+
+cucumber:
+ database: myapp-cucumber
+ <<: *global_settings
+
+staging:
+ host: hostname
+ database: myapp-staging
+ username: username
+ password: password
+ <<: *global_settings
+
+production:
+ database: myapp
+ username: username
+ password: password
+ <<: *global_settings

0 comments on commit e64a2a3

Please sign in to comment.