Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Vagrant with mongodb

  • Loading branch information...
commit 83665125a244f3716349358273b10f84385ca435 1 parent 308606f
@wilkes authored
View
4 .gitignore
@@ -3,4 +3,6 @@ Manifest.txt
karras.jar
lib
classes
-autodoc
+autodoc
+.DS_Store
+.vagrant
View
12 Vagrantfile
@@ -0,0 +1,12 @@
+Vagrant::Config.run do |config|
+ config.vm.box = "clojure-dev"
+
+ config.vm.provisioner = :chef_solo
+ config.chef.cookbooks_path = "cookbooks"
+
+ config.vm.customize do |vm|
+ vm.memory_size = 1024
+ vm.name = "Karras VM"
+ end
+
+end
View
47 cookbooks/mongodb/README.rdoc
@@ -0,0 +1,47 @@
+= DESCRIPTION:
+
+Complete Debian/Ubuntu style MongoDB configuration.
+
+= REQUIREMENTS:
+
+Debian or Ubuntu preferred. Tested on Ubuntu 8.04 Server LTS, should work on others.
+
+= ATTRIBUTES:
+
+* mongodb[:user] = User to install and run MongoDB under. Default: "mongodb"
+* mongodb[:group] = User group to install and run MongoDB under. Default: "mongodb"
+* mongodb[:bind_address] = Specifies a single IP that the database server will listen for. Default: "127.0.0.1"
+* mongodb[:port] = Specifies the port number on which Mongo will listen for client connections. Default: "27017"
+* mongodb[:version] = MongoDB version to install. Default: '1.4.2'
+* mongodb[:file_name] = Default: "mongodb-linux-#{kernel[:machine] || 'i686'}-#{mongodb[:version]}"
+* mongodb[:url] = Url to download MongoDB files from. Default: "http://downloads.mongodb.org/linux/#{mongodb[:file_name]}.tgz"
+* mongodb[:root] = Location to install MongoDB files to. Default: "/usr/local/mongodb"
+* mongodb[:data_dir] = Specifies the directory for datafiles. Default: "/var/lib/mongodb"
+* mongodb[:log_dir] = Directory to write log files to. Default: "/var/log/mongodb"
+* mongodb[:config_dir] = Directory to read MongoDB conf file from. Default: "/etc/mongodb"
+* mongodb[:pid_dir] = Directory for inti.d service to write pid file to. Default: "/var/run"
+
+= USAGE:
+
+Include the mongodb recipe to install MongoDB and get 'sane' default settings.
+
+== TODO:
+
+* support for Master-Slave Replication and Replica Pairs configuration
+
+= LICENSE & AUTHOR:
+
+Author:: Seth Chisamore (<schisamo@gmail.com>)
+Copyright:: 2010, Seth Chisamore
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
View
15 cookbooks/mongodb/attributes/mongodb.rb
@@ -0,0 +1,15 @@
+set_unless[:mongodb][:user] = "mongodb"
+set_unless[:mongodb][:group] = "mongodb"
+
+set_unless[:mongodb][:server] = "127.0.0.1"
+set_unless[:mongodb][:bind_address] = "127.0.0.1"
+set_unless[:mongodb][:port] = "27017"
+set_unless[:mongodb][:version] = '1.4.2'
+set_unless[:mongodb][:file_name] = "mongodb-linux-#{kernel[:machine] || 'i686'}-#{mongodb[:version]}"
+set_unless[:mongodb][:url] = "http://downloads.mongodb.org/linux/#{mongodb[:file_name]}.tgz"
+
+set_unless[:mongodb][:root] = "/usr/local/mongodb"
+set_unless[:mongodb][:data_dir] = "/var/lib/mongodb"
+set_unless[:mongodb][:log_dir] = "/var/log/mongodb"
+set_unless[:mongodb][:config_dir] = "/etc/mongodb"
+set_unless[:mongodb][:pid_dir] = "/var/run"
View
10 cookbooks/mongodb/metadata.rb
@@ -0,0 +1,10 @@
+maintainer "Seth Chisaore"
+maintainer_email "schisamo@gmail.com"
+license "Apache 2.0"
+description "Configures MongoDB"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "0.1"
+
+%w{ debian ubuntu}.each do |os|
+ supports os
+end
View
81 cookbooks/mongodb/recipes/default.rb
@@ -0,0 +1,81 @@
+#
+# Cookbook Name:: mongodb
+# Recipe:: default
+
+group node[:mongodb][:group] do
+ action [ :create, :manage ]
+end
+
+user node[:mongodb][:user] do
+ comment "MongoDB Server"
+ gid node[:mongodb][:group]
+ home node[:mongodb][:root]
+ action [ :create, :manage ]
+end
+
+[node[:mongodb][:log_dir], node[:mongodb][:data_dir], node[:mongodb][:pid_dir]].each do |dir|
+ directory dir do
+ owner node[:mongodb][:user]
+ group node[:mongodb][:group]
+ mode 0755
+ recursive true
+ action :create
+ not_if { File.directory?(dir) }
+ end
+end
+
+if !(::File.exists?("/tmp/#{node[:mongodb][:file_name]}.tgz")) && !(::File.directory?(node[:mongodb][:root]))
+ Chef::Log.info "Downloading MongoDB from #{node[:mongodb][:url]}. This could take a while..."
+ remote_file "/tmp/#{node[:mongodb][:file_name]}.tgz" do
+ source node[:mongodb][:url]
+ not_if { ::File.exists?("/tmp/#{node[:mongodb][:file_name]}.tgz") }
+ end
+end
+
+bash "install-mongodb" do
+ cwd "/tmp"
+ code <<-EOH
+ tar zxvf #{node[:mongodb][:file_name]}.tgz
+ mv #{node[:mongodb][:file_name]} #{node[:mongodb][:root]}
+ EOH
+ not_if { ::File.directory?(node[:mongodb][:root]) }
+end
+
+template "/etc/profile.d/mongo_path.sh" do
+ source "mongo_path.sh.erb"
+ owner "root"
+ group "root"
+ mode 0744
+end
+
+# create init.d service
+template "/etc/init.d/mongodb" do
+ source "init.sh.erb"
+ owner "root"
+ group "root"
+ mode 0755
+end
+service "mongodb" do
+ supports :start => true, :stop => true, :restart => true
+ action [ :enable ]
+end
+
+# create config directory and file
+directory "/etc/mongodb" do
+ action :create
+ owner "root"
+ group "root"
+ mode 0755
+end
+template "/etc/mongodb/mongodb.conf" do
+ source "mongodb.conf.erb"
+ owner "root"
+ group "root"
+ mode 0744
+ notifies :restart, resources(:service => "mongodb")
+end
+
+execute "start Mongo DB" do
+ command "/etc/init.d/mongodb start"
+ not_if { File.exist?("/var/run/mongodb.pid") }
+end
View
268 cookbooks/mongodb/templates/default/init.sh.erb
@@ -0,0 +1,268 @@
+#! /bin/sh
+# Inspired heavily by http://pasite.org/code/469
+#
+# init.d script with LSB support.
+#
+# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
+#
+# Modified for Chef (c) 2009 Seth Chisamore <schisamo@gmail.com>
+#
+### BEGIN INIT INFO
+# Provides: mongodb
+# Required-Start: $all
+# Required-Stop: $all
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: An object/document-oriented database
+# Description: MongoDB is a high-performance, open source, schema-free
+# document-oriented data store that's easy to deploy, manage
+# and use. It's network accessible, written in C++ and offers
+# the following features:
+#
+# * Collection oriented storage - easy storage of object-
+# style data
+# * Full index support, including on inner objects
+# * Query profiling
+# * Replication and fail-over support
+# * Efficient storage of binary data including large
+# objects (e.g. videos)
+# * Auto-sharding for cloud-level scalability (Q209)
+#
+# High performance, scalability, and reasonable depth of
+# functionality are the goals for the project.
+### END INIT INFO
+#
+# Dynamically generated by Chef - local modifications will be replaced
+#
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+DAEMON=<%= @node[:mongodb][:root] %>/bin/mongod
+CONFIG_FILE=<%= @node[:mongodb][:config_dir] %>/mongodb.conf
+NAME=MongoDB
+DESC=database
+
+if test ! -x $DAEMON; then
+ echo "Could not find $DAEMON"
+ exit 0
+fi
+
+. /lib/lsb/init-functions
+
+PIDFILE=<%= @node[:mongodb][:pid_dir] %>/mongodb.pid
+DIETIME=10 # Time to wait for the server to die, in seconds
+ # If this value is set too low you might not
+ # let some servers to die gracefully and
+ # 'restart' will not work
+
+DAEMON_OPTS="--config $CONFIG_FILE run"
+DAEMONUSER=<%= @node[:mongodb][:user] %>
+
+# Check that the user exists (if we set a user)
+# Does the user exist?
+if [ -n "$DAEMONUSER" ] ; then
+ if getent passwd | grep -q "^$DAEMONUSER:"; then
+ # Obtain the uid and gid
+ DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
+ DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
+ else
+ log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
+ exit 1
+ fi
+fi
+
+set -e
+
+running_pid() {
+# Check if a given process pid's cmdline matches a given name
+ pid=$1
+ name=$2
+ [ -z "$pid" ] && return 1
+ [ ! -d /proc/$pid ] && return 1
+ cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
+ # Is this the expected server
+ [ "$cmd" != "$name" ] && return 1
+ return 0
+}
+
+running() {
+# Check if the process is running looking at /proc
+# (works for all users)
+
+ # No pidfile, probably no daemon present
+ [ ! -f "$PIDFILE" ] && return 1
+ pid=`cat $PIDFILE`
+ running_pid $pid $DAEMON || return 1
+ return 0
+}
+
+start_server() {
+# Start the process using the wrapper
+ if [ -z "$DAEMONUSER" ] ; then
+ start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
+ --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
+ errcode=$?
+ else
+# if we are using a daemonuser then change the user id
+ start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
+ --make-pidfile --chuid $DAEMONUSER \
+ --exec $DAEMON -- $DAEMON_OPTS
+ errcode=$?
+ fi
+ return $errcode
+}
+
+stop_server() {
+# Stop the process using the wrapper
+ if [ -z "$DAEMONUSER" ] ; then
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE
+ rm $PIDFILE
+ errcode=$?
+ else
+# if we are using a daemonuser then look for process that match
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE \
+ --user $DAEMONUSER \
+ --exec $DAEMON
+ errcode=$?
+ fi
+
+ return $errcode
+}
+
+reload_server() {
+ [ ! -f "$PIDFILE" ] && return 1
+ pid=pidofproc $PIDFILE # This is the daemon's pid
+ # Send a SIGHUP
+ kill -USR1 $pid
+ return $?
+}
+
+force_stop() {
+# Force the process to die killing it manually
+ [ ! -e "$PIDFILE" ] && return
+ if running ; then
+ kill -15 $pid
+ # Is it really dead?
+ sleep "$DIETIME"s
+ if running ; then
+ kill -9 $pid
+ sleep "$DIETIME"s
+ if running ; then
+ echo "Cannot kill $NAME (pid=$pid)!"
+ exit 1
+ fi
+ fi
+ fi
+ rm -f $PIDFILE
+}
+
+
+case "$1" in
+ start)
+ log_daemon_msg "Starting $DESC $NAME"
+ # Check if it's running first
+ if running ; then
+ log_progress_msg "apparently already running"
+ log_end_msg 0
+ exit 0
+ fi
+ if start_server ; then
+ # NOTE: Some servers might die some time after they start,
+ # this code will detect this issue if STARTTIME is set
+ # to a reasonable value
+ [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
+ if running ; then
+ # It's ok, the server started and is running
+ log_end_msg 0
+ else
+ # It is not running after we did start
+ log_end_msg 1
+ fi
+ else
+ # Either we could not start it
+ log_end_msg 1
+ fi
+ ;;
+ stop)
+ log_daemon_msg "Stopping $DESC" "$NAME"
+ if running ; then
+ # Only stop the server if we see it running
+ errcode=0
+ stop_server || errcode=$?
+ log_end_msg $errcode
+ else
+ # If it's not running don't do anything
+ log_progress_msg "apparently not running"
+ log_end_msg 0
+ exit 0
+ fi
+ ;;
+ force-stop)
+ # First try to stop gracefully the program
+ $0 stop
+ if running; then
+ # If it's still running try to kill it more forcefully
+ log_daemon_msg "Stopping (force) $DESC" "$NAME"
+ errcode=0
+ force_stop || errcode=$?
+ log_end_msg $errcode
+ fi
+ ;;
+ restart|force-reload)
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ errcode=0
+ stop_server || errcode=$?
+ # Wait some sensible amount, some server need this
+ [ -n "$DIETIME" ] && sleep $DIETIME
+ start_server || errcode=$?
+ [ -n "$STARTTIME" ] && sleep $STARTTIME
+ running || errcode=$?
+ log_end_msg $errcode
+ ;;
+ status)
+
+ log_daemon_msg "Checking status of $DESC" "$NAME"
+ if running ; then
+ log_progress_msg "running"
+ log_end_msg 0
+ else
+ log_progress_msg "apparently not running"
+ log_end_msg 1
+ exit 1
+ fi
+ ;;
+ # Use this if the daemon cannot reload
+ reload)
+ log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
+ log_warning_msg "cannot re-read the config file (use restart)."
+ ;;
+ # And this if it cann
+ #reload)
+ #
+ # If the daemon can reload its config files on the fly
+ # for example by sending it SIGHUP, do it here.
+ #
+ # If the daemon responds to changes in its config file
+ # directly anyway, make this a do-nothing entry.
+ #
+ # log_daemon_msg "Reloading $DESC configuration files" "$NAME"
+ # if running ; then
+ # reload_server
+ # if ! running ; then
+ # Process died after we tried to reload
+ # log_progress_msg "died on reload"
+ # log_end_msg 1
+ # exit 1
+ # fi
+ # else
+ # log_progress_msg "server is not running"
+ # log_end_msg 1
+ # exit 1
+ # fi
+ #;;
+ *)
+ N=/etc/init.d/$NAME
+ echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
+ exit 1
+ ;;
+esac
+
+exit 0
View
1  cookbooks/mongodb/templates/default/mongo_path.sh.erb
@@ -0,0 +1 @@
+PATH=$PATH:<%= @node[:mongodb][:root] %>/bin
View
10 cookbooks/mongodb/templates/default/mongodb.conf.erb
@@ -0,0 +1,10 @@
+#
+# Dynamically generated by Chef - local modifications will be replaced
+#
+
+dbpath = <%= @node[:mongodb][:data_dir] %>
+#bind_ip = <%= @node[:mongodb][:bind_address] %>
+port = <%= @node[:mongodb][:port] %>
+logpath = <%= @node[:mongodb][:log_dir] %>/mongodb.log
+logappend = true
+noauth = true
View
2  cookbooks/mongodb/templates/default/port_mongodb.erb
@@ -0,0 +1,2 @@
+# MongoDB port
+-A FWR -p tcp -m tcp --dport <%= @port %> -j ACCEPT
View
1  cookbooks/vagrant_main/recipes/default.rb
@@ -0,0 +1 @@
+require_recipe "mongodb"
Please sign in to comment.
Something went wrong with that request. Please try again.