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

Commit 54bb6af

Browse files
authored
Merge pull request #81 from seekingalpha/master
systemd + puppet 4 fixes
2 parents da4b053 + f063934 commit 54bb6af

16 files changed

+163
-51
lines changed

.fixtures.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fixtures:
33
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
44
apt: "git://github.com/puppetlabs/puppetlabs-apt.git"
55
logrotate:
6-
repo: "git://github.com/rodjek/puppet-logrotate.git"
7-
ref: "1.1.1"
6+
repo: "git://github.com/yo61/puppet-logrotate.git"
7+
ref: "1.4.0"
88
symlinks:
99
mongodb: "#{source_dir}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Gemfile.lock
12
*.gem
23
*.rbc
34
*.swp
@@ -23,6 +24,7 @@ build/
2324

2425
## Environment normalisation:
2526
/.bundle/
27+
/vendor
2628
/lib/bundler/man/
2729

2830
# for a library or gem, you might want to ignore these files since the code is

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ Array. Each field is "key" or "key=value" for parameters for config file
376376
###Modules needed:
377377

378378
* puppetlabs-stdlib
379-
* rodjek-logrotate
379+
* yo61-logrotate
380380
* puppetlabs-apt ( only for Debian/Ubuntu )
381381

382382
###Software versions needed:

manifests/init.pp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# == Class: mongodb
22
#
33
class mongodb (
4+
$systemd_os = $mongodb::params::systemd_os,
45
$dbdir = $mongodb::params::dbdir,
56
$pidfilepath = $mongodb::params::pidfilepath,
67
$logdir = $mongodb::params::logdir,
@@ -33,28 +34,27 @@
3334
before => Anchor['mongodb::end'],
3435
}
3536

36-
# stop and disable default mongod
37+
# remove not wanted startup script, because it would kill all mongod
38+
# instances and not only the default mongod
39+
40+
file { "/etc/init.d/${::mongodb::old_servicename}":
41+
ensure => file,
42+
content => template("${module_name}/init.d/replacement_mongod.conf.erb"),
43+
mode => '0755',
44+
before => Anchor['mongodb::end'],
45+
}
3746

47+
# stop and disable default mongod
3848
service { $::mongodb::old_servicename:
3949
ensure => stopped,
4050
enable => false,
4151
hasstatus => true,
4252
hasrestart => true,
4353
subscribe => Package['mongodb-package'],
54+
require => File["/etc/init.d/${::mongodb::old_servicename}"],
4455
before => Anchor['mongodb::end'],
4556
}
4657

47-
# remove not wanted startup script, because it would kill all mongod
48-
# instances and not only the default mongod
49-
50-
file { "/etc/init.d/${::mongodb::old_servicename}":
51-
ensure => file,
52-
content => template("${module_name}/replacement_mongod-init.conf.erb"),
53-
require => Service[$::mongodb::old_servicename],
54-
mode => '0755',
55-
before => Anchor['mongodb::end'],
56-
}
57-
5858
mongodb::limits::conf {
5959
'mongod-nofile-soft':
6060
type => soft,
@@ -79,5 +79,5 @@
7979

8080
# ordering resources application
8181

82-
Mongod<| |> -> Mongos<| |>
82+
Mongodb::Mongod<| |> -> Mongodb::Mongos<| |>
8383
}

manifests/mongod.pp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$mongod_deactivate_transparent_hugepage = false,
1919
) {
2020

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

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

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

40-
# lint:endignore
40+
if $mongodb::params::systemd_os {
41+
$service_provider = 'systemd'
42+
file {
43+
"/etc/init.d/mongod_${mongod_instance}":
44+
ensure => absent,
45+
}
46+
file { "mongod_${mongod_instance}_service":
47+
path => "/lib/systemd/system/mongod_${mongod_instance}.service",
48+
content => template('mongodb/systemd/mongod.service.erb'),
49+
mode => '0644',
50+
require => [
51+
Class['mongodb::install'],
52+
File["/etc/init.d/mongod_${mongod_instance}"]
53+
]
54+
}
55+
} else {
56+
$service_provider = 'init'
57+
file { "mongod_${mongod_instance}_service":
58+
path => "/etc/init.d/mongod_${mongod_instance}",
59+
content => template("mongodb/init.d/${::osfamily}_mongod.conf.erb"),
60+
mode => '0755',
61+
require => Class['mongodb::install'],
62+
}
63+
}
4164

4265
if ($mongod_monit != false) {
4366
# notify { "mongod_monit is : ${mongod_monit}": }
@@ -64,11 +87,13 @@
6487
enable => $mongod_enable,
6588
hasstatus => true,
6689
hasrestart => true,
90+
provider => $service_provider,
6791
require => [
6892
File[
6993
"/etc/mongod_${mongod_instance}.conf",
70-
"/etc/init.d/mongod_${mongod_instance}"],
71-
Service[$::mongodb::old_servicename]],
94+
"mongod_${mongod_instance}_service",
95+
$db_specific_dir],
96+
Service[$::mongodb::params::old_servicename]],
7297
before => Anchor['mongodb::end']
7398
}
7499

manifests/mongos.pp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
$mongos_add_options = []
1414
) {
1515

16-
# lint:ignore:selector_inside_resource would not add much to readability
17-
18-
$init_template = $::osfamily ? {
19-
debian => template('mongodb/debian_mongos-init.conf.erb'),
20-
redhat => template('mongodb/redhat_mongos-init.conf.erb'),
21-
}
16+
$db_specific_dir = "${::mongodb::params::dbdir}/mongos_${mongos_instance}"
2217

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

31-
"/etc/init.d/mongos_${mongos_instance}":
32-
content => $init_template,
33-
mode => '0755',
34-
require => Class['mongodb::install'],
31+
if $mongodb::params::systemd_os {
32+
$service_provider = 'systemd'
33+
file {
34+
"/etc/init.d/mongos_${mongos_instance}":
35+
ensure => absent,
36+
}
37+
file { "mongos_${mongos_instance}_service":
38+
path => "/lib/systemd/system/mongos_${mongos_instance}.service",
39+
content => template('mongodb/systemd/mongos.service.erb'),
40+
mode => '0644',
41+
require => [
42+
Class['mongodb::install'],
43+
File["/etc/init.d/mongos_${mongos_instance}"]
44+
]
45+
}
46+
} else {
47+
$service_provider = 'init'
48+
file { "mongos_${mongos_instance}_service":
49+
path => "/etc/init.d/mongos_${mongos_instance}",
50+
content => template("mongodb/init.d/${::osfamily}_mongos.conf.erb"),
51+
mode => '0755',
52+
require => Class['mongodb::install'],
53+
}
3554
}
3655

3756
# wait for servers starting
@@ -47,7 +66,7 @@
4766
file { "/etc/mongos_${mongos_instance}.key":
4867
content => template('mongodb/mongos.key.erb'),
4968
mode => '0700',
50-
owner => $::mongodb::run_as_user,
69+
owner => $::mongodb::params::run_as_user,
5170
require => Class['mongodb::install'],
5271
notify => Service["mongos_${mongos_instance}"],
5372
}
@@ -59,10 +78,13 @@
5978
enable => $mongos_enable,
6079
hasstatus => true,
6180
hasrestart => true,
81+
provider => $service_provider,
6282
require => [
63-
File["/etc/mongos_${mongos_instance}.conf"],
64-
File["/etc/init.d/mongos_${mongos_instance}"],
65-
Service[$::mongodb::old_servicename],
83+
File[
84+
"/etc/mongos_${mongos_instance}.conf",
85+
"mongos_${mongos_instance}_service",
86+
$db_specific_dir],
87+
Service[$::mongodb::params::old_servicename],
6688
Start_detector['configservers']],
6789
before => Anchor['mongodb::end']
6890
}

manifests/params.pp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
}
2727
}
2828

29+
case $::osfamily {
30+
'Debian': {
31+
$systemd_os = versioncmp($::operatingsystemmajrelease, '15.10') > 0
32+
}
33+
'RedHat': {
34+
$systemd_os = versioncmp($::operatingsystemmajrelease, '7') > 0
35+
}
36+
default: { # deal with lint
37+
$systemd_os = false
38+
}
39+
}
40+
2941
# directorypath to store db directory in
3042
# subdirectories for each mongo instance will be created
3143

metadata.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
}
1818
],
1919
"requirements": [
20-
{
21-
"name": "pe",
22-
"version_requirement": "3.x"
23-
},
2420
{
2521
"name": "puppet",
2622
"version_requirement": ">=2.7.20 <5.0.0"
@@ -37,6 +33,6 @@
3733
"dependencies": [
3834
{"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0"},
3935
{"name":"puppetlabs/apt","version_requirement":">= 1.1.0"},
40-
{"name":"rodjek/logrotate","version_requirement":">= 1.1.1"}
36+
{"name":"yo61-logrotate","version_requirement":">= 1.4.0"}
4137
]
4238
}

spec/defines/mongod_spec.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,39 @@
44

55
let(:title) { 'testdb' }
66

7-
context 'with defaults for all parameters on RedHat' do
8-
let(:facts) {{ :osfamily => 'RedHat' }}
9-
let :pre_condition do
7+
context 'with defaults for all parameters on pre-systemd RedHat' do
8+
let(:facts) {{ :osfamily => 'redhat', :operatingsystemmajrelease => '6' }}
9+
let :pre_condition do
1010
'include ::mongodb::params'
1111
end
1212
it { should contain_mongodb__mongod('testdb') }
1313
context 'with deactivate_transparent_hugepage set' do
1414
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
15-
it { should contain_file("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
15+
it { should contain_file("mongod_testdb_service").with_path("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
16+
end
17+
end
18+
19+
context 'with defaults for all parameters on pre-systemd Debian' do
20+
let(:facts) {{ :osfamily => 'debian', :lsbdistid => 'ubuntu', :operatingsystemmajrelease => '14.04' }}
21+
let :pre_condition do
22+
'include ::mongodb::params'
23+
end
24+
it { should contain_mongodb__mongod('testdb') }
25+
context 'with deactivate_transparent_hugepage set' do
26+
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
27+
it { should contain_file("mongod_testdb_service").with_path("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
1628
end
1729
end
1830

1931
context 'with defaults for all parameters on Debian' do
20-
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'ubuntu' }}
32+
let(:facts) {{ :osfamily => 'debian', :lsbdistid => 'ubuntu', :operatingsystemmajrelease => '16.04' }}
33+
let :pre_condition do
34+
'include ::mongodb::params'
35+
end
2136
it { should contain_mongodb__mongod('testdb') }
2237
context 'with deactivate_transparent_hugepage set' do
2338
let(:params) {{ :mongod_deactivate_transparent_hugepage => true }}
24-
it { should contain_file("/etc/init.d/mongod_testdb").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
39+
it { should contain_file("mongod_testdb_service").with_path("/lib/systemd/system/mongod_testdb.service").with_content(/\/sys\/kernel\/mm\/transparent_hugepage\//) }
2540
end
2641
end
2742

templates/systemd/mongod.service.erb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[Unit]
2+
Description=Mongos_<%= @mongod_instance %> server
3+
Wants=network.target
4+
After=network.target
5+
6+
[Service]
7+
Type=forking
8+
PIDFile=<%= scope.lookupvar('mongodb::pidfilepath') %>/mongod_<%= @mongod_instance %>/mongod.pid
9+
ExecStart=/usr/bin/mongod --config /etc/mongod_<%= @mongod_instance %>.conf
10+
Restart=on-failure
11+
User=<%= scope.lookupvar('mongodb::run_as_user') %>
12+
Group=<%= scope.lookupvar('mongodb::run_as_group') %>
13+
LimitNOFILE=<%= scope.lookupvar('mongodb::ulimit_nofiles') %>
14+
LimitNPROC=<%= scope.lookupvar('mongodb::ulimit_nproc') %>
15+
<% if @mongod_deactivate_transparent_hugepage -%>
16+
<%# implement mdiag.sh best-practice %>
17+
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/khugepaged/defrag && echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag'
18+
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/defrag && echo never > /sys/kernel/mm/transparent_hugepage/defrag'
19+
ExecPreStart=/bin/bash -c 'test -f /sys/kernel/mm/transparent_hugepage/enabled && echo never > /sys/kernel/mm/transparent_hugepage/enabled'
20+
<% end -%>
21+
22+
[Install]
23+
WantedBy=multi-user.target

templates/systemd/mongos.service.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Unit]
2+
Description=Mongos_<%= @mongos_instance %> server
3+
Wants=network.target
4+
After=network.target
5+
6+
[Service]
7+
Type=forking
8+
PIDFile=<%= scope.lookupvar('mongodb::pidfilepath') %>/mongos_<%= @mongos_instance %>/mongos.pid
9+
ExecStart=/usr/bin/mongos --config /etc/mongos_<%= @mongos_instance %>.conf
10+
Restart=on-failure
11+
User=<%= scope.lookupvar('mongodb::run_as_user') %>
12+
Group=<%= scope.lookupvar('mongodb::run_as_group') %>
13+
LimitNOFILE=<%= scope.lookupvar('mongodb::ulimit_nofiles') %>
14+
LimitNPROC=<%= scope.lookupvar('mongodb::ulimit_nproc') %>
15+
16+
[Install]
17+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)