Skip to content

Commit

Permalink
Updated with example yml and initializer. Also some new settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jul 15, 2010
1 parent dad636b commit e64a2a3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 deletions.
19 changes: 16 additions & 3 deletions README.rdoc
Expand Up @@ -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>
44 changes: 42 additions & 2 deletions lib/mongodb.rb
@@ -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:
Expand All @@ -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'

Expand Down Expand Up @@ -51,4 +91,4 @@ def mongodb(hash = {})
]
end

end
end
16 changes: 15 additions & 1 deletion templates/mongo.init.erb
Expand Up @@ -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
Expand Down Expand Up @@ -292,4 +306,4 @@ case "$1" in
;;
esac

exit 0
exit 0
6 changes: 6 additions & 0 deletions templates/mongo.rb
@@ -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,
})
25 changes: 25 additions & 0 deletions templates/mongo.yml
@@ -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.