Skip to content

Commit dfc96c5

Browse files
committed
configuration for number of open mongodb connections
Allow users to change the default nofile ulimit value when installing mongodb. The mongodb class has been changed to a parameterized class that accepts a `ulimit_nofile` parameter as well as a `replSet` parameter. This is a backwards incompatible change for users of the old `replica_set` definition.
1 parent 3a2525a commit dfc96c5

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

README

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ Update it:
1919
Sample Usage :
2020
node 'mongodb-1.domain.com', 'mongodb-2.domain.com', 'mongodb-3.domain.com' {
2121
# Install MongoDB
22-
include mongodb
23-
# Nodes are in a replica set
24-
mongodb::replica_set { "example_set_name": }
22+
class { mongodb:
23+
# Nodes are in a replica set
24+
replSet => "example_set_name",
25+
# Increase number of available mongodb connections
26+
ulimit_nofile => 21000,
27+
}
2528
}
2629

2730
## CONTRIBUTORS ##

manifests/init.pp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
# - MongoDB can be part of a replica set
1313
#
1414
# Sample Usage:
15-
# include mongodb
15+
# class { mongodb:
16+
# replSet => "myReplicaSet",
17+
# ulimit_nofile => 21000,
18+
# }
1619
#
17-
class mongodb {
18-
include mongodb::params
19-
20+
class mongodb(
21+
$replSet = $mongodb::params::replSet,
22+
$ulimit_nofile = $mongodb::params::ulimit_nofile,
23+
$repository = $mongodb::params::repository,
24+
$package = $mongodb::params::package
25+
) inherits mongodb::params {
26+
2027
package { "python-software-properties":
2128
ensure => installed,
2229
}
@@ -46,19 +53,15 @@
4653
ensure => installed,
4754
require => Exec["update-apt"],
4855
}
49-
56+
5057
service { "mongodb":
5158
enable => true,
5259
ensure => running,
53-
require => Package[$mongodb::params::package],
54-
}
55-
56-
define replica_set {
57-
file { "/etc/init/mongodb.conf":
58-
content => template("mongodb/mongodb.conf.erb"),
59-
mode => "0644",
60-
notify => Service["mongodb"],
61-
require => Package[$mongodb::params::package],
62-
}
6360
}
61+
62+
file { "/etc/init/mongodb.conf":
63+
content => template("mongodb/mongodb.conf.erb"),
64+
mode => "0644",
65+
notify => Service["mongodb"],
66+
}
6467
}

manifests/params.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,22 @@
55
# Parameters:
66
# - The 10gen Ubuntu $repository to use
77
# - The 10gen Ubuntu $package to use
8+
# - A replica set to join
9+
# - A nofile ulimit
810
#
911
# Sample Usage:
1012
# include mongodb::params
1113
#
1214
class mongodb::params {
1315
$repository="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen"
1416
$package="mongodb-10gen"
17+
18+
# name of replica set (if any) to join
19+
$replSet = ""
20+
21+
# number of open files ulimit can be changed if mongodb.log reports
22+
# "too many open files" or "too many open connections" messages.
23+
# mongodb has an upper limit of 20k.
24+
# http://www.mongodb.org/display/DOCS/Too+Many+Open+Files
25+
$ulimit_nofile = 1024
1526
}

templates/mongodb.conf.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ end script
99
start on runlevel [2345]
1010
stop on runlevel [06]
1111

12+
# http://www.mongodb.org/display/DOCS/Too+Many+Open+Files
13+
# mongodb has a limit of 20k connections
14+
limit nofile <%= ulimit_nofile %> <%= ulimit_nofile %>
15+
1216
script
1317
ENABLE_MONGODB="yes"
1418
if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
15-
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf --replSet <%= name %>; fi
19+
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec /usr/bin/mongod -- --config /etc/mongodb.conf <%= replSet ? "--replSet #{replSet}" : "" %>; fi
1620
end script

0 commit comments

Comments
 (0)