Installing Mongodb with Chef on Centos6.4

I started working on installing MongoDB with Chef-solo…here are the steps, errors and fixes I came up with.

Here is the Cookbook i used: git@github.com:edelight/chef-mongodb.git

First I ran into an error with the install wanting to use APT to download the packages. The error read something like “APT cookbook/dependancy not found.” Thats not the exact wording but ive already lost the true error because the chef-stacktracefile.out file gets written over when you run chef-solo. I need to set that to append from now on so i can track the errors better.

I looked in the 10gen_repo.rb recipe and found where it was looking for the APT cookbook before it did anything that looked at what OS im on. I just commented that line out and gave it another whirl. this time i got another error…

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Converging 6 resources
Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 * No version specified, and no candidate version available for mongo-10gen-server
================================================================================
Error executing action `install` on resource 'package[mongo-10gen-server]'
================================================================================
Chef::Exceptions::Package
-------------------------
No version specified, and no candidate version available for mongo-10gen-server
Resource Declaration:
---------------------
# In /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb
22: package node[:mongodb][:package_name] do
 23: action :install
 24: version node[:mongodb][:package_version]
 25: end
 26:
Compiled Resource:
------------------
# Declared in /home/seth/chef-repo/cookbooks/mongodb/recipes/default.rb:22:in `from_file'
package("mongo-10gen-server") do
 action [:install]
 retries 0
 retry_delay 2
 package_name "mongo-10gen-server"
 cookbook_name :mongodb
 recipe_name "default"
end
[2013-09-27T09:37:32-04:00] ERROR: Running exception handlers
[2013-09-27T09:37:32-04:00] ERROR: Exception handlers complete
[2013-09-27T09:37:32-04:00] FATAL: Stacktrace dumped to /home/seth/chef-repo/chef-solo/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2013-09-27T09:37:32-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

The stacktrace revealed this:  ArgumentError: Unable to create Chef::RunList::RunListItem from String:”recipe [mongodb::10gen_repo]”: must be recipe[] or role[]
I wasn’t quite sure what was going on with this one but from the error I figured i needed to look into the 10gen_repo.rb and see what it was doing. This recipe sets up the repositories for stable 10gen packages. i looked in the README file to see if there were any instructions related to this recipe and found this…

Adds the stable 10gen repo for the corresponding platform. Currently only implemented for the Debian and Ubuntu repository.

Usage: just add recipe[mongodb::10gen_repo] to the node run_list before any other MongoDB recipe, and the mongodb-10gen stable packages will be installed instead of the distribution default.

So all I had to do now was add this to my mongodb.json file that im calling when I run chef-solo. That looks like this now…

{
“run_list”: [“recipe[mongodb::10gen_repo]”, “recipe[mongodb]”]
}

Trying it again….

[seth@lab001 chef-repo]$ sudo chef-solo -c solo.rb -j mongodb.json

 Starting Chef Client, version 11.6.0
 Compiling Cookbooks...
 Converging 7 resources
 Recipe: mongodb::10gen_repo
 * yum_repository[10gen] action add (up to date)
 Recipe: <Dynamically Defined Resource>
 * execute[yum-makecache] action nothing (skipped due to action :nothing)
 * ruby_block[reload-internal-yum-cache] action nothing (skipped due to action :nothing)
 * template[/etc/yum.repos.d/10gen.repo] action create
 - create new file /etc/yum.repos.d/10gen.repo
 - update content in file /etc/yum.repos.d/10gen.repo from none to d796d9
 --- /etc/yum.repos.d/10gen.repo 2013-09-27 11:01:44.703021565 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1uuzlx3 2013-09-27 11:01:44.719021599 -0400
 @@ -0,0 +1,7 @@
 +# Generated by Chef for
 +# Local modifications will be overwritten.
 +[10gen]
 +name=10gen RPM Repository
 +baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
 +gpgcheck=0
 +enabled=1
 - change mode from '' to '0644'
 - restore selinux security context
 * execute[yum-makecache] action run
 - execute yum -q makecache
 * ruby_block[reload-internal-yum-cache] action create
 - execute the ruby block reload-internal-yum-cache
 Recipe: mongodb::default
 * package[mongo-10gen-server] action install
 - install version 2.4.6-mongodb_1 of package mongo-10gen-server
 * template[/etc/sysconfig/mongodb] action create
 - create new file /etc/sysconfig/mongodb
 - update content in file /etc/sysconfig/mongodb from none to 514bf6
 --- /etc/sysconfig/mongodb 2013-09-27 11:03:25.096241504 -0400
 +++ /tmp/chef-rendered-template20130927-6230-pbm20a 2013-09-27 11:03:25.102241516 -0400
 @@ -0,0 +1,26 @@
 +# This config file is auto-generated by chef
 +# please don't modify manually
 +
 +DAEMON="/usr/bin/mongod"
 +NAME="mongodb"
 +
 +DAEMON_OPTS=""
 +
 +DAEMON_OPTS="$DAEMON_OPTS --port 27017"
 +DAEMON_OPTS="$DAEMON_OPTS --dbpath /var/lib/mongodb"
 +DAEMON_OPTS="$DAEMON_OPTS --logpath /var/log/mongodb/mongodb.log"
 +
 +DAEMON_OPTS="$DAEMON_OPTS --fork"
 +DBPATH="/var/lib/mongodb"
 - change mode from '' to '0644'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * directory[/var/log/mongodb] action create
 - create new directory /var/log/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * directory[/var/lib/mongodb] action create
 - create new directory /var/lib/mongodb
 - change mode from '' to '0755'
 - change owner from '' to 'mongod'
 - change group from '' to 'mongod'
 - restore selinux security context
 * template[/etc/init.d/mongodb] action create
 - create new file /etc/init.d/mongodb
 - update content in file /etc/init.d/mongodb from none to 7360b8
 --- /etc/init.d/mongodb 2013-09-27 11:03:29.560251284 -0400
 +++ /tmp/chef-rendered-template20130927-6230-1no1lyk 2013-09-27 11:03:29.565251294 -0400
 @@ -0,0 +1,74 @@
 +#!/bin/bash
 +
 +# mongodb - Startup script for mongod
 +
 +# chkconfig: 35 85 15
 +# description: Mongo is a scalable, document-oriented database.
 +# processname: mongodb
 +# config: /etc/mongod.conf
 +# pidfile: /var/run/mongo/mongo.pid
 +
 +. /etc/rc.d/init.d/functions
 +
 +SYSCONFIG="/etc/sysconfig/mongodb"
 +DAEMON=/usr/bin/mongod
 +MONGO_USER=mongod
 +
 +. "$SYSCONFIG" || true
 +
 +start()
 +{
 + echo -n $"Starting mongod: "
 + daemon --user "$MONGO_USER" $DAEMON $DAEMON_OPTS
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
 +}
 +
 +stop()
 +{
 + echo -n $"Stopping mongod: "
 + killproc -p "$DBPATH"/mongod.lock -d 300 /usr/bin/mongod
 + RETVAL=$?
 + echo
 + [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
 +}
 +
 +restart () {
 + stop
 + start
 +}
 +
 +ulimit -f unlimited
 +ulimit -t unlimited
 +ulimit -v unlimited
 +ulimit -n 64000
 +ulimit -m unlimited
 +ulimit -u 32000
 +
 +RETVAL=0
 +
 +case "$1" in
 + start)
 + start
 + ;;
 + stop)
 + stop
 + ;;
 + restart|reload|force-reload)
 + restart
 + ;;
 + condrestart)
 + [ -f /var/lock/subsys/mongod ] && restart || :
 + ;;
 + status)
 + status $DAEMON
 + RETVAL=$?
 + ;;
 + *)
 + echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
 + RETVAL=1
 +esac
 +
 +exit $RETVAL
 +
 - change mode from '' to '0755'
 - change owner from '' to 'root'
 - change group from '' to 'root'
 - restore selinux security context
 * service[mongodb] action enable
 - enable service service[mongodb]
 * service[mongodb] action start
 - start service service[mongodb]
 * service[mongodb] action restart
 - restart service service[mongodb]
 Chef Client finished, 11 resources updated

[seth@lab001 chef-repo]$ ps -ef | grep mongodb
 mongod 6484 1 1 11:03 ? 00:00:00 /usr/bin/mongod --port 27017 --dbpath /var/lib/mongodb --logpath /var/log/mongodb/mongodb.log --fork
 seth 6496 5542 0 11:04 pts/0 00:00:00 grep mongodb

And there you go. Good luck and let me know how this works for you or if you have suggestions or comments.