Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created April 30, 2012 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/2558255 to your computer and use it in GitHub Desktop.
Save wtnabe/2558255 to your computer and use it in GitHub Desktop.
mongo task for rails ( put this task file as lib/tasks/mongo.rake )
# -*- mode: ruby -*-
include FileUtils::Verbose
@root = File.expand_path( File.dirname(__FILE__) + '/../../' )
namespace :mongo do
desc 'prepare'
task :prepare do
dbpath = "#{@root}/db/mongodb"
mkdir( dbpath ) unless File.exist? dbpath
conf = File.join( @root, 'config', 'mongo_develop.conf.erb' )
if ( not File.exist? conf )
open( conf, 'w' ) { |f|
f.puts <<'EOD'
<% root = File.expand_path( File.dirname(__FILE__) + '/../' ) %>
dbpath = <%= "#{root}/db/mongodb" %>
logpath = <%= "#{root}/log/mongodb.log" %>
EOD
}
puts "created #{conf} ."
end
end
desc 'start mongod'
task :start do
conf = File.join( @root, 'config', 'mongo_develop.conf' )
sh <<EOD
bundle exec erubis #{conf}.erb > #{conf}
mongod -f #{conf}
EOD
end
end
@wtnabe
Copy link
Author

wtnabe commented Apr 30, 2012

sample mongo_develop.conf.erb

<% root = File.expand_path( File.dirname(__FILE__) + '/../' ) %>
dbpath  = <%= "#{root}/db/mongodb" %>
logpath = <%= "#{root}/log/mongodb.log" %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment