Skip to content

Commit

Permalink
Merge pull request #698 from StatensPensjonskasse/mongos-as-systemd-s…
Browse files Browse the repository at this point in the history
…ervice

Mongos as systemd service
  • Loading branch information
h-haaks committed Mar 16, 2024
2 parents 1a33bf6 + 8f8872a commit 5ece1ea
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 795 deletions.
403 changes: 30 additions & 373 deletions REFERENCE.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/Debian-10.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
mongodb::globals::version: '4.4.8' # Debian 10 doesn't provide mongodb 3.6.
mongodb::globals::version: '4.4.29' # Debian 10 doesn't provide mongodb 3.6.
mongodb::globals::manage_package_repo: true # Debian 10 doesn't provide mongodb packages. So manage it!
3 changes: 3 additions & 0 deletions data/Debian-family.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
mongodb::mongos::service_user: 'mongodb'
mongodb::mongos::service_group: 'mongodb'
3 changes: 3 additions & 0 deletions data/RedHat-family.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
mongodb::mongos::service_user: 'mongod'
mongodb::mongos::service_group: 'mongod'
3 changes: 3 additions & 0 deletions manifests/client/params.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# @summary mongodb client params
#
# @api private
#
class mongodb::client::params inherits mongodb::globals {
$package_ensure = pick($mongodb::globals::version, 'present')
$manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false)
Expand Down
2 changes: 1 addition & 1 deletion manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# specified.
$_repo_version = $version ? {
Undef => $facts['os']['family'] in ['RedHat', 'Linux', 'Suse'] ? {
true => '3.6',
true => '4.4',
default => $version,
},
default => $version,
Expand Down
4 changes: 4 additions & 0 deletions manifests/mongos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# @param service_manage
# @param service_provider
# @param service_name
# @param service_user
# @param service_group
# @param service_template
# @param service_enable
# @param service_ensure
Expand All @@ -31,6 +33,8 @@
Boolean $service_manage = $mongodb::mongos::params::service_manage,
Optional[String] $service_provider = $mongodb::mongos::params::service_provider,
Optional[String] $service_name = $mongodb::mongos::params::service_name,
String $service_user = 'mongodb',
String $service_group = 'mongodb',
Optional[String[1]] $service_template = $mongodb::mongos::params::service_template,
Boolean $service_enable = $mongodb::mongos::params::service_enable,
Stdlib::Ensure::Service $service_ensure = $mongodb::mongos::params::service_ensure,
Expand Down
24 changes: 3 additions & 21 deletions manifests/mongos/config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# @summary PRIVATE CLASS: do not call directly
# @summary Manages mongos config
#
# @api private
#
# @param package_ensure
# @param config
Expand Down Expand Up @@ -51,24 +53,4 @@
group => 'root',
mode => '0644',
}

if $service_manage {
if $facts['os']['family'] == 'RedHat' or $facts['os']['family'] == 'Suse' {
file { '/etc/sysconfig/mongos' :
ensure => $ensure,
owner => 'root',
group => 'root',
mode => '0644',
content => "OPTIONS=\"--quiet -f ${config}\"\n",
}
} elsif $facts['os']['family'] == 'Debian' {
file { '/etc/init.d/mongos' :
ensure => $ensure,
content => template('mongodb/mongos/Debian/mongos.erb'),
owner => 'root',
group => 'root',
mode => '0755',
}
}
}
}
4 changes: 3 additions & 1 deletion manifests/mongos/install.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# @summary PRIVATE CLASS: do not call directly
# @summary Manages the mongos package
#
# @api private
#
# @param package_ensure
# @param package_name
Expand Down
44 changes: 10 additions & 34 deletions manifests/mongos/params.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PRIVATE CLASS: do not use directly
# @summary mongos params
#
# @api private
#
class mongodb::mongos::params inherits mongodb::globals {
$manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false)

Expand Down Expand Up @@ -28,37 +31,10 @@
$service_ensure = 'running'
$service_status = undef

# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
case $facts['os']['family'] {
'RedHat', 'Linux', 'Suse': {
if $manage_package {
$config = '/etc/mongodb-shard.conf'
$pidfilepath = undef
$unixsocketprefix = undef
$logpath = undef
$fork = undef
$service_template = undef
} else {
# RedHat/CentOS doesn't come with a prepacked mongodb
# so we assume that you are using EPEL repository.
$config = '/etc/mongos.conf'
$pidfilepath = '/var/run/mongodb/mongos.pid'
$unixsocketprefix = '/var/run/mongodb'
$logpath = '/var/log/mongodb/mongos.log'
$fork = true
$service_template = 'mongodb/mongos/RedHat/mongos.service-dropin.epp'
}
}
'Debian': {
$config = '/etc/mongodb-shard.conf'
$pidfilepath = undef
$unixsocketprefix = undef
$logpath = undef
$fork = undef
$service_template = undef
}
default: {
fail("Osfamily ${facts['os']['family']} is not supported")
}
}
$config = '/etc/mongos.conf'
$pidfilepath = '/var/run/mongodb/mongos.pid'
$unixsocketprefix = '/var/run/mongodb'
$logpath = '/var/log/mongodb/mongos.log'
$fork = true
$service_template = 'mongodb/mongos/mongos.service-dropin.epp'
}
16 changes: 9 additions & 7 deletions manifests/mongos/service.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# @summary PRIVATE CLASS: do not call directly
# @summary Manages the mongos service
#
# @api private
#
# @param package_ensure
# @param service_manage
Expand All @@ -15,6 +17,8 @@
$package_ensure = $mongodb::mongos::package_ensure,
$service_manage = $mongodb::mongos::service_manage,
$service_name = $mongodb::mongos::service_name,
$service_user = $mongodb::mongos::service_user,
$service_group = $mongodb::mongos::service_group,
$service_enable = $mongodb::mongos::service_enable,
$service_ensure = $mongodb::mongos::service_ensure,
$service_status = $mongodb::mongos::service_status,
Expand All @@ -38,12 +42,10 @@
}

if $service_manage {
if $facts['os']['family'] == 'RedHat' {
systemd::unit_file { 'mongos.service':
content => epp($service_template),
enable => $real_service_enable,
} ~> Service['mongos']
}
systemd::unit_file { 'mongos.service':
content => epp($service_template, { service_user => $service_user, service_group => $service_user }),
enable => $real_service_enable,
} ~> Service['mongos']

service { 'mongos':
ensure => $real_service_ensure,
Expand Down
5 changes: 4 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PRIVATE CLASS: do not use directly
# @summary mongodb params
#
# @api private
#
class mongodb::params inherits mongodb::globals {
$ensure = true
$dbpath = '/var/lib/mongodb'
Expand Down
4 changes: 3 additions & 1 deletion manifests/repo.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# PRIVATE CLASS: do not use directly
# @summary Manages the mongodb repository
#
# @api private
#
# @param ensure
# @param version
Expand Down
4 changes: 3 additions & 1 deletion manifests/repo/apt.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# PRIVATE CLASS: do not use directly
# @summary This is a repo class for apt
#
# @api private
class mongodb::repo::apt inherits mongodb::repo {
# we try to follow/reproduce the instruction
# from http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
Expand Down
4 changes: 3 additions & 1 deletion manifests/repo/yum.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# PRIVATE CLASS: do not use directly
# @summary This is a repo class for yum
#
# @api private
class mongodb::repo::yum inherits mongodb::repo {
# We try to follow/reproduce the instruction
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/
Expand Down
5 changes: 4 additions & 1 deletion manifests/server/config.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PRIVATE CLASS: do not call directly
# @summary Manages mongod config
#
# @api private
#
class mongodb::server::config {
$ensure = $mongodb::server::ensure
$user = $mongodb::server::user
Expand Down
5 changes: 4 additions & 1 deletion manifests/server/install.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PRIVATE CLASS: do not call directly
# @summary Manages the mongod package
#
# @api private
#
class mongodb::server::install {
$package_ensure = $mongodb::server::package_ensure
$package_name = $mongodb::server::package_name
Expand Down
5 changes: 4 additions & 1 deletion manifests/server/service.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# PRIVATE CLASS: do not call directly
# @summary Manages the mongos service
#
# @api private
#
class mongodb::server::service {
$ensure = $mongodb::server::service_ensure
$service_manage = $mongodb::server::service_manage
Expand Down
15 changes: 7 additions & 8 deletions spec/acceptance/mongos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
require 'spec_helper_acceptance'

describe 'mongodb::mongos class' do
case fact('osfamily')
when 'Debian'
package_name = if fact('os.distro.codename') =~ %r{^(buster|bullseye)$}
package_name = case fact('osfamily')
when 'Debian'
if fact('os.distro.codename') =~ %r{^(buster|bullseye)$}
'mongodb-org-server'
else
'mongodb-server'
end
config_file = '/etc/mongodb-shard.conf'
else
package_name = 'mongodb-org-server'
config_file = '/etc/mongos.conf'
end
else
'mongodb-org-server'
end
config_file = '/etc/mongos.conf'

describe 'installation' do
it 'works with no errors' do
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it { is_expected.to compile.with_all_deps }

if facts[:os]['release']['major'] =~ %r{(10)}
it { is_expected.to create_package('mongodb_client').with_ensure('4.4.8') }
it { is_expected.to create_package('mongodb_client').with_ensure('4.4.29') }
else
it { is_expected.to create_package('mongodb_client').with_ensure('present') }
end
Expand All @@ -25,7 +25,7 @@
it { is_expected.to compile.with_all_deps }

if facts[:os]['release']['major'] =~ %r{(10)}
it { is_expected.to create_package('mongodb_client').with_ensure('4.4.8').with_name('mongodb-org-shell').with_tag('mongodb_package') }
it { is_expected.to create_package('mongodb_client').with_ensure('4.4.29').with_name('mongodb-org-shell').with_tag('mongodb_package') }
else
it { is_expected.to create_package('mongodb_client').with_ensure('present').with_name('mongodb-org-shell').with_tag('mongodb_package') }
end
Expand Down
Loading

0 comments on commit 5ece1ea

Please sign in to comment.