Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

(Thanks achiu) Added mongodb recipes to library

  • Loading branch information...
commit 8cde0373bec8fe8b3fe06bf346b2724982e0ffb7 1 parent d58b5fc
Nathan Esquenazi nesquena authored
28 README.textile
View
@@ -22,6 +22,7 @@ Currently included recipes in this gem:
* Backgroundrb Server
* DelayedJob Worker
* Whenever Cron Scheduling
+ * MongoDB Management
* Aptitude Package Management
* Gitosis Git Repository Hosting
@@ -47,7 +48,8 @@ Then, include into your @deploy.rb@ configuration file for Capistrano:
require 'cap_recipes/tasks/passenger'
require 'cap_recipes/tasks/thinking_sphinx'
require 'cap_recipes/tasks/rails'
- # or ruby, rubygems, apache, delayed_job, juggernaut, backgroundrb, aptitude, gitosis, whenever
+ require 'cap_recipes/tasks/delayed_job'
+ # or ruby, rubygems, apache, mongodb, juggernaut, backgroundrb, aptitude, gitosis, whenever
# OR
# only use managing tasks:
@@ -335,6 +337,28 @@ hooks.rb
after "deploy:restart", "memcache:restart" # clear cache after updating code
</code></pre>
+h3. MongoDB
+
+These recipes are for installing and managing the mongodb document-oriented database
+
+h4. Configuration
+
+ * mongodb_data_path - the location to store the mongodb data [default: "/data/db"]
+ * mongodb_bin_path - the location to install mongodb [default: "/opt/mongo"]
+ * mongodb_log - the path to the mongodb log file [default: "/var/log/mongodb.log"]
+
+h4. Tasks
+
+install.rb
+
+ * mongodb:install - Performs the full installation of mongodb and dependencies
+
+manage.rb
+
+ * mongodb:start - Starts the mongodb process
+ * mongodb:stop - Stops the mongodb process
+ * mongodb:restart - Restarts the mongodb process
+
h3. Gitosis
These recipes are for installing Gitosis Git Repository Hosting
@@ -465,7 +489,7 @@ h2. CONTRIBUTORS
The following people are the reason this library exists:
* nesquena [Nathan Esquenazi] - created and maintaining the library
- * achiu [Arthur Chiu] - contributed gitosis, ruby and other recipes
+ * achiu [Arthur Chiu] - contributed gitosis, ruby, mongodb and other recipes
* hubertlepicki - contributed thinking_sphinx recipes
h2. LICENSE
1  lib/cap_recipes/tasks/mongodb.rb
View
@@ -0,0 +1 @@
+Dir[File.join(File.dirname(__FILE__), 'mongodb/*.rb')].sort.each { |lib| require lib }
39 lib/cap_recipes/tasks/mongodb/install.rb
View
@@ -0,0 +1,39 @@
+require File.expand_path(File.dirname(__FILE__) + '/../utilities')
+require File.expand_path(File.dirname(__FILE__) + '/manage')
+
+Capistrano::Configuration.instance(true).load do
+ set :mongodb_data_path, "/data/db"
+ set :mongodb_bin_path, "/opt/mongo"
+
+ namespace :mongodb do
+ desc "Installs mongodb binaries and all dependencies"
+ task :install, :role => :app do
+ utilities.apt_install "tcsh scons g++ libpcre++-dev"
+ utilities.apt_install "libboost1.37-dev libreadline-dev xulrunner-dev"
+ mongodb.make_spidermonkey
+ mongodb.make_mongodb
+ mongodb.setup_db_path
+ end
+
+ task :make_spidermonkey, :role => :app do
+ run "mkdir -p ~/tmp"
+ run "cd ~/tmp; wget ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz"
+ run "cd ~/tmp; tar -zxvf js-1.7.0.tar.gz"
+ run "cd ~/tmp/js/src; export CFLAGS=\"-DJS_C_STRINGS_ARE_UTF8\""
+ run "cd ~/tmp/js/src; #{sudo} make -f Makefile.ref"
+ run "cd ~/tmp/js/src; #{sudo} JS_DIST=/usr make -f Makefile.ref export"
+ end
+
+ task :make_mongodb, :role => :app do
+ sudo "rm -rf ~/tmp/mongo"
+ run "cd ~/tmp; git clone git://github.com/mongodb/mongo.git"
+ run "cd ~/tmp/mongo; #{sudo} scons all"
+ run "cd ~/tmp/mongo; #{sudo} scons --prefix=#{mongodb_bin_path} install"
+ end
+
+ task :setup_db_path, :role => :app do
+ sudo "mkdir -p #{mongodb_path}"
+ mongodb.start
+ end
+ end
+end
27 lib/cap_recipes/tasks/mongodb/manage.rb
View
@@ -0,0 +1,27 @@
+require File.expand_path(File.dirname(__FILE__) + '/../utilities')
+require File.expand_path(File.dirname(__FILE__) + '/install')
+
+Capistrano::Configuration.instance(true).load do
+ set :mongodb_log, "/var/log/mongodb.log"
+
+ namespace :mongodb do
+ desc "Starts the mongodb server"
+ task :start, :role => :app do
+ sudo "#{mongodb_bin_path}/bin/mongod --fork --logpath #{mongodb_log} --logappend --dbpath #{mongodb_path}"
+ end
+
+ desc "Stop the mongodb server"
+ task :stop, :role => :app do
+ pid = capture("ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'")
+ sudo "kill -2 #{pid}" unless pid.strip.empty?
+ end
+
+ desc "Restart the mongodb server"
+ task :restart, :role => :app do
+ pid = capture("ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'")
+ mongodb.stop unless pid.strip.empty?
+ mongodb.start
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.