diff --git a/.fixtures.yml b/.fixtures.yml index 9f6a3c9..3a274b4 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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}" diff --git a/.gitignore b/.gitignore index 35e6349..962c261 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +Gemfile.lock *.gem *.rbc *.swp @@ -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 diff --git a/README.md b/README.md index d70f533..3e38ab2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/manifests/init.pp b/manifests/init.pp index 40a1d2e..512451d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, @@ -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, @@ -79,5 +79,5 @@ # ordering resources application - Mongod<| |> -> Mongos<| |> + Mongodb::Mongod<| |> -> Mongodb::Mongos<| |> } diff --git a/manifests/mongod.pp b/manifests/mongod.pp index 083eadf..9f88dfa 100644 --- a/manifests/mongod.pp +++ b/manifests/mongod.pp @@ -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": @@ -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}": } @@ -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'] } diff --git a/manifests/mongos.pp b/manifests/mongos.pp index 2926bdf..b08d242 100644 --- a/manifests/mongos.pp +++ b/manifests/mongos.pp @@ -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": @@ -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 @@ -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}"], } @@ -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'] } diff --git a/manifests/params.pp b/manifests/params.pp index 2d62dd5..abb39e4 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 diff --git a/metadata.json b/metadata.json index 5184a7f..9959f4a 100644 --- a/metadata.json +++ b/metadata.json @@ -17,10 +17,6 @@ } ], "requirements": [ - { - "name": "pe", - "version_requirement": "3.x" - }, { "name": "puppet", "version_requirement": ">=2.7.20 <5.0.0" @@ -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"} ] } diff --git a/spec/defines/mongod_spec.rb b/spec/defines/mongod_spec.rb index 9809e2b..88407be 100644 --- a/spec/defines/mongod_spec.rb +++ b/spec/defines/mongod_spec.rb @@ -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 diff --git a/templates/debian_mongod-init.conf.erb b/templates/init.d/debian_mongod.conf.erb similarity index 100% rename from templates/debian_mongod-init.conf.erb rename to templates/init.d/debian_mongod.conf.erb diff --git a/templates/debian_mongos-init.conf.erb b/templates/init.d/debian_mongos.conf.erb similarity index 100% rename from templates/debian_mongos-init.conf.erb rename to templates/init.d/debian_mongos.conf.erb diff --git a/templates/redhat_mongod-init.conf.erb b/templates/init.d/redhat_mongod.conf.erb similarity index 100% rename from templates/redhat_mongod-init.conf.erb rename to templates/init.d/redhat_mongod.conf.erb diff --git a/templates/redhat_mongos-init.conf.erb b/templates/init.d/redhat_mongos.conf.erb similarity index 100% rename from templates/redhat_mongos-init.conf.erb rename to templates/init.d/redhat_mongos.conf.erb diff --git a/templates/replacement_mongod-init.conf.erb b/templates/init.d/replacement_mongod.conf.erb similarity index 100% rename from templates/replacement_mongod-init.conf.erb rename to templates/init.d/replacement_mongod.conf.erb diff --git a/templates/systemd/mongod.service.erb b/templates/systemd/mongod.service.erb new file mode 100644 index 0000000..5380454 --- /dev/null +++ b/templates/systemd/mongod.service.erb @@ -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 diff --git a/templates/systemd/mongos.service.erb b/templates/systemd/mongos.service.erb new file mode 100644 index 0000000..e268c92 --- /dev/null +++ b/templates/systemd/mongos.service.erb @@ -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