Skip to content
This repository has been archived by the owner on Mar 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #81 from seekingalpha/master
Browse files Browse the repository at this point in the history
systemd + puppet 4 fixes
  • Loading branch information
dwerder authored Mar 27, 2017
2 parents da4b053 + f063934 commit 54bb6af
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fixtures:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
apt: "git://github.com/puppetlabs/puppetlabs-apt.git"
logrotate:
repo: "git://github.com/rodjek/puppet-logrotate.git"
ref: "1.1.1"
repo: "git://github.com/yo61/puppet-logrotate.git"
ref: "1.4.0"
symlinks:
mongodb: "#{source_dir}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Gemfile.lock
*.gem
*.rbc
*.swp
Expand All @@ -23,6 +24,7 @@ build/

## Environment normalisation:
/.bundle/
/vendor
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Array. Each field is "key" or "key=value" for parameters for config file
###Modules needed:

* puppetlabs-stdlib
* rodjek-logrotate
* yo61-logrotate
* puppetlabs-apt ( only for Debian/Ubuntu )

###Software versions needed:
Expand Down
26 changes: 13 additions & 13 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# == Class: mongodb
#
class mongodb (
$systemd_os = $mongodb::params::systemd_os,
$dbdir = $mongodb::params::dbdir,
$pidfilepath = $mongodb::params::pidfilepath,
$logdir = $mongodb::params::logdir,
Expand Down Expand Up @@ -33,28 +34,27 @@
before => Anchor['mongodb::end'],
}

# stop and disable default mongod
# remove not wanted startup script, because it would kill all mongod
# instances and not only the default mongod

file { "/etc/init.d/${::mongodb::old_servicename}":
ensure => file,
content => template("${module_name}/init.d/replacement_mongod.conf.erb"),
mode => '0755',
before => Anchor['mongodb::end'],
}

# stop and disable default mongod
service { $::mongodb::old_servicename:
ensure => stopped,
enable => false,
hasstatus => true,
hasrestart => true,
subscribe => Package['mongodb-package'],
require => File["/etc/init.d/${::mongodb::old_servicename}"],
before => Anchor['mongodb::end'],
}

# remove not wanted startup script, because it would kill all mongod
# instances and not only the default mongod

file { "/etc/init.d/${::mongodb::old_servicename}":
ensure => file,
content => template("${module_name}/replacement_mongod-init.conf.erb"),
require => Service[$::mongodb::old_servicename],
mode => '0755',
before => Anchor['mongodb::end'],
}

mongodb::limits::conf {
'mongod-nofile-soft':
type => soft,
Expand All @@ -79,5 +79,5 @@

# ordering resources application

Mongod<| |> -> Mongos<| |>
Mongodb::Mongod<| |> -> Mongodb::Mongos<| |>
}
45 changes: 35 additions & 10 deletions manifests/mongod.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$mongod_deactivate_transparent_hugepage = false,
) {

# lint:ignore:selector_inside_resource would not add much to readability
$db_specific_dir = "${::mongodb::params::dbdir}/mongod_${mongod_instance}"

file {
"/etc/mongod_${mongod_instance}.conf":
Expand All @@ -27,17 +27,40 @@
# no auto restart of a db because of a config change
# notify => Class['mongodb::service'],
require => Class['mongodb::install'];
}

"/etc/init.d/mongod_${mongod_instance}":
content => $::osfamily ? {
debian => template('mongodb/debian_mongod-init.conf.erb'),
redhat => template('mongodb/redhat_mongod-init.conf.erb'),
},
mode => '0755',
file {
$db_specific_dir:
ensure => directory,
owner => $::mongodb::params::run_as_user,
group => $::mongodb::params::run_as_group,
require => Class['mongodb::install'],
}

# lint:endignore
if $mongodb::params::systemd_os {
$service_provider = 'systemd'
file {
"/etc/init.d/mongod_${mongod_instance}":
ensure => absent,
}
file { "mongod_${mongod_instance}_service":
path => "/lib/systemd/system/mongod_${mongod_instance}.service",
content => template('mongodb/systemd/mongod.service.erb'),
mode => '0644',
require => [
Class['mongodb::install'],
File["/etc/init.d/mongod_${mongod_instance}"]
]
}
} else {
$service_provider = 'init'
file { "mongod_${mongod_instance}_service":
path => "/etc/init.d/mongod_${mongod_instance}",
content => template("mongodb/init.d/${::osfamily}_mongod.conf.erb"),
mode => '0755',
require => Class['mongodb::install'],
}
}

if ($mongod_monit != false) {
# notify { "mongod_monit is : ${mongod_monit}": }
Expand All @@ -64,11 +87,13 @@
enable => $mongod_enable,
hasstatus => true,
hasrestart => true,
provider => $service_provider,
require => [
File[
"/etc/mongod_${mongod_instance}.conf",
"/etc/init.d/mongod_${mongod_instance}"],
Service[$::mongodb::old_servicename]],
"mongod_${mongod_instance}_service",
$db_specific_dir],
Service[$::mongodb::params::old_servicename]],
before => Anchor['mongodb::end']
}

Expand Down
50 changes: 36 additions & 14 deletions manifests/mongos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
$mongos_add_options = []
) {

# lint:ignore:selector_inside_resource would not add much to readability

$init_template = $::osfamily ? {
debian => template('mongodb/debian_mongos-init.conf.erb'),
redhat => template('mongodb/redhat_mongos-init.conf.erb'),
}
$db_specific_dir = "${::mongodb::params::dbdir}/mongos_${mongos_instance}"

file {
"/etc/mongos_${mongos_instance}.conf":
Expand All @@ -27,11 +22,35 @@
# no auto restart of a db because of a config change
# notify => Class['mongodb::service'],
require => Class['mongodb::install'];
$db_specific_dir:
ensure => directory,
owner => $::mongodb::params::run_as_user,
group => $::mongodb::params::run_as_group;
}

"/etc/init.d/mongos_${mongos_instance}":
content => $init_template,
mode => '0755',
require => Class['mongodb::install'],
if $mongodb::params::systemd_os {
$service_provider = 'systemd'
file {
"/etc/init.d/mongos_${mongos_instance}":
ensure => absent,
}
file { "mongos_${mongos_instance}_service":
path => "/lib/systemd/system/mongos_${mongos_instance}.service",
content => template('mongodb/systemd/mongos.service.erb'),
mode => '0644',
require => [
Class['mongodb::install'],
File["/etc/init.d/mongos_${mongos_instance}"]
]
}
} else {
$service_provider = 'init'
file { "mongos_${mongos_instance}_service":
path => "/etc/init.d/mongos_${mongos_instance}",
content => template("mongodb/init.d/${::osfamily}_mongos.conf.erb"),
mode => '0755',
require => Class['mongodb::install'],
}
}

# wait for servers starting
Expand All @@ -47,7 +66,7 @@
file { "/etc/mongos_${mongos_instance}.key":
content => template('mongodb/mongos.key.erb'),
mode => '0700',
owner => $::mongodb::run_as_user,
owner => $::mongodb::params::run_as_user,
require => Class['mongodb::install'],
notify => Service["mongos_${mongos_instance}"],
}
Expand All @@ -59,10 +78,13 @@
enable => $mongos_enable,
hasstatus => true,
hasrestart => true,
provider => $service_provider,
require => [
File["/etc/mongos_${mongos_instance}.conf"],
File["/etc/init.d/mongos_${mongos_instance}"],
Service[$::mongodb::old_servicename],
File[
"/etc/mongos_${mongos_instance}.conf",
"mongos_${mongos_instance}_service",
$db_specific_dir],
Service[$::mongodb::params::old_servicename],
Start_detector['configservers']],
before => Anchor['mongodb::end']
}
Expand Down
12 changes: 12 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
}
}

case $::osfamily {
'Debian': {
$systemd_os = versioncmp($::operatingsystemmajrelease, '15.10') > 0
}
'RedHat': {
$systemd_os = versioncmp($::operatingsystemmajrelease, '7') > 0
}
default: { # deal with lint
$systemd_os = false
}
}

# directorypath to store db directory in
# subdirectories for each mongo instance will be created

Expand Down
6 changes: 1 addition & 5 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
}
],
"requirements": [
{
"name": "pe",
"version_requirement": "3.x"
},
{
"name": "puppet",
"version_requirement": ">=2.7.20 <5.0.0"
Expand All @@ -37,6 +33,6 @@
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0"},
{"name":"puppetlabs/apt","version_requirement":">= 1.1.0"},
{"name":"rodjek/logrotate","version_requirement":">= 1.1.1"}
{"name":"yo61-logrotate","version_requirement":">= 1.4.0"}
]
}
27 changes: 21 additions & 6 deletions spec/defines/mongod_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@

let(:title) { 'testdb' }

context 'with defaults for all parameters on RedHat' do
let(:facts) {{ :osfamily => 'RedHat' }}
let :pre_condition do
context 'with defaults for all parameters on pre-systemd RedHat' do
let(:facts) {{ :osfamily => 'redhat', :operatingsystemmajrelease => '6' }}
let :pre_condition do
'include ::mongodb::params'
end
it { should contain_mongodb__mongod('testdb') }
context 'with deactivate_transparent_hugepage set' do
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
it { should contain_file("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
it { should contain_file("mongod_testdb_service").with_path("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
end
end

context 'with defaults for all parameters on pre-systemd Debian' do
let(:facts) {{ :osfamily => 'debian', :lsbdistid => 'ubuntu', :operatingsystemmajrelease => '14.04' }}
let :pre_condition do
'include ::mongodb::params'
end
it { should contain_mongodb__mongod('testdb') }
context 'with deactivate_transparent_hugepage set' do
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
it { should contain_file("mongod_testdb_service").with_path("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
end
end

context 'with defaults for all parameters on Debian' do
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'ubuntu' }}
let(:facts) {{ :osfamily => 'debian', :lsbdistid => 'ubuntu', :operatingsystemmajrelease => '16.04' }}
let :pre_condition do
'include ::mongodb::params'
end
it { should contain_mongodb__mongod('testdb') }
context 'with deactivate_transparent_hugepage set' do
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
it { should contain_file("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
it { should contain_file("mongod_testdb_service").with_path("/lib/systemd/system/mongod_testdb.service").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
end
end

Expand Down
23 changes: 23 additions & 0 deletions templates/systemd/mongod.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Unit]
Description=Mongos_<%= @mongod_instance %> server
Wants=network.target
After=network.target

[Service]
Type=forking
PIDFile=<%= scope.lookupvar('mongodb::pidfilepath') %>/mongod_<%= @mongod_instance %>/mongod.pid
ExecStart=/usr/bin/mongod --config /etc/mongod_<%= @mongod_instance %>.conf
Restart=on-failure
User=<%= scope.lookupvar('mongodb::run_as_user') %>
Group=<%= scope.lookupvar('mongodb::run_as_group') %>
LimitNOFILE=<%= scope.lookupvar('mongodb::ulimit_nofiles') %>
LimitNPROC=<%= scope.lookupvar('mongodb::ulimit_nproc') %>
<% if @mongod_deactivate_transparent_hugepage -%>
<%# implement mdiag.sh best-practice %>
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/khugepaged/defrag && echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag'
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/defrag && echo never > /sys/kernel/mm/transparent_hugepage/defrag'
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/enabled && echo never > /sys/kernel/mm/transparent_hugepage/enabled'
<% end -%>

[Install]
WantedBy=multi-user.target
17 changes: 17 additions & 0 deletions templates/systemd/mongos.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Mongos_<%= @mongos_instance %> server
Wants=network.target
After=network.target

[Service]
Type=forking
PIDFile=<%= scope.lookupvar('mongodb::pidfilepath') %>/mongos_<%= @mongos_instance %>/mongos.pid
ExecStart=/usr/bin/mongos --config /etc/mongos_<%= @mongos_instance %>.conf
Restart=on-failure
User=<%= scope.lookupvar('mongodb::run_as_user') %>
Group=<%= scope.lookupvar('mongodb::run_as_group') %>
LimitNOFILE=<%= scope.lookupvar('mongodb::ulimit_nofiles') %>
LimitNPROC=<%= scope.lookupvar('mongodb::ulimit_nproc') %>

[Install]
WantedBy=multi-user.target

0 comments on commit 54bb6af

Please sign in to comment.