Skip to content

Commit 0dbd42c

Browse files
committed
mongos: always use systemd service
1 parent 26db515 commit 0dbd42c

File tree

11 files changed

+66
-407
lines changed

11 files changed

+66
-407
lines changed

data/Debian-family.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
mongodb::mongos::service_user: 'mongodb'
3+
mongodb::mongos::service_group: 'mongodb'

data/RedHat-family.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
mongodb::mongos::service_user: 'mongod'
3+
mongodb::mongos::service_group: 'mongod'

manifests/mongos.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# @param service_manage
99
# @param service_provider
1010
# @param service_name
11+
# @param service_user
12+
# @param service_group
1113
# @param service_template
1214
# @param service_enable
1315
# @param service_ensure
@@ -31,6 +33,8 @@
3133
Boolean $service_manage = $mongodb::mongos::params::service_manage,
3234
Optional[String] $service_provider = $mongodb::mongos::params::service_provider,
3335
Optional[String] $service_name = $mongodb::mongos::params::service_name,
36+
String $service_user = 'mongodb',
37+
String $service_group = 'mongodb',
3438
Optional[String[1]] $service_template = $mongodb::mongos::params::service_template,
3539
Boolean $service_enable = $mongodb::mongos::params::service_enable,
3640
Stdlib::Ensure::Service $service_ensure = $mongodb::mongos::params::service_ensure,

manifests/mongos/config.pp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# @summary PRIVATE CLASS: do not call directly
1+
# @summary Manages mongos config
2+
#
3+
# @api private
24
#
35
# @param package_ensure
46
# @param config
@@ -51,24 +53,4 @@
5153
group => 'root',
5254
mode => '0644',
5355
}
54-
55-
if $service_manage {
56-
if $facts['os']['family'] == 'RedHat' or $facts['os']['family'] == 'Suse' {
57-
file { '/etc/sysconfig/mongos' :
58-
ensure => $ensure,
59-
owner => 'root',
60-
group => 'root',
61-
mode => '0644',
62-
content => "OPTIONS=\"--quiet -f ${config}\"\n",
63-
}
64-
} elsif $facts['os']['family'] == 'Debian' {
65-
file { '/etc/init.d/mongos' :
66-
ensure => $ensure,
67-
content => template('mongodb/mongos/Debian/mongos.erb'),
68-
owner => 'root',
69-
group => 'root',
70-
mode => '0755',
71-
}
72-
}
73-
}
7456
}

manifests/mongos/install.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# @summary PRIVATE CLASS: do not call directly
1+
# @summary Manages the mongos package
2+
#
3+
# @api private
24
#
35
# @param package_ensure
46
# @param package_name

manifests/mongos/params.pp

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# PRIVATE CLASS: do not use directly
1+
# @summary mongos params
2+
#
3+
# @api private
4+
#
25
class mongodb::mongos::params inherits mongodb::globals {
36
$manage_package = pick($mongodb::globals::manage_package, $mongodb::globals::manage_package_repo, false)
47

@@ -28,37 +31,10 @@
2831
$service_ensure = 'running'
2932
$service_status = undef
3033

31-
# Amazon Linux's OS Family is 'Linux', operating system 'Amazon'.
32-
case $facts['os']['family'] {
33-
'RedHat', 'Linux', 'Suse': {
34-
if $manage_package {
35-
$config = '/etc/mongodb-shard.conf'
36-
$pidfilepath = undef
37-
$unixsocketprefix = undef
38-
$logpath = undef
39-
$fork = undef
40-
$service_template = undef
41-
} else {
42-
# RedHat/CentOS doesn't come with a prepacked mongodb
43-
# so we assume that you are using EPEL repository.
44-
$config = '/etc/mongos.conf'
45-
$pidfilepath = '/var/run/mongodb/mongos.pid'
46-
$unixsocketprefix = '/var/run/mongodb'
47-
$logpath = '/var/log/mongodb/mongos.log'
48-
$fork = true
49-
$service_template = 'mongodb/mongos/RedHat/mongos.service-dropin.epp'
50-
}
51-
}
52-
'Debian': {
53-
$config = '/etc/mongodb-shard.conf'
54-
$pidfilepath = undef
55-
$unixsocketprefix = undef
56-
$logpath = undef
57-
$fork = undef
58-
$service_template = undef
59-
}
60-
default: {
61-
fail("Osfamily ${facts['os']['family']} is not supported")
62-
}
63-
}
34+
$config = '/etc/mongos.conf'
35+
$pidfilepath = '/var/run/mongodb/mongos.pid'
36+
$unixsocketprefix = '/var/run/mongodb'
37+
$logpath = '/var/log/mongodb/mongos.log'
38+
$fork = true
39+
$service_template = 'mongodb/mongos/mongos.service-dropin.epp'
6440
}

manifests/mongos/service.pp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# @summary PRIVATE CLASS: do not call directly
1+
# @summary Manages the mongos service
2+
#
3+
# @api private
24
#
35
# @param package_ensure
46
# @param service_manage
@@ -15,6 +17,8 @@
1517
$package_ensure = $mongodb::mongos::package_ensure,
1618
$service_manage = $mongodb::mongos::service_manage,
1719
$service_name = $mongodb::mongos::service_name,
20+
$service_user = $mongodb::mongos::service_user,
21+
$service_group = $mongodb::mongos::service_group,
1822
$service_enable = $mongodb::mongos::service_enable,
1923
$service_ensure = $mongodb::mongos::service_ensure,
2024
$service_status = $mongodb::mongos::service_status,
@@ -38,12 +42,10 @@
3842
}
3943

4044
if $service_manage {
41-
if $facts['os']['family'] == 'RedHat' {
42-
systemd::unit_file { 'mongos.service':
43-
content => epp($service_template),
44-
enable => $real_service_enable,
45-
} ~> Service['mongos']
46-
}
45+
systemd::unit_file { 'mongos.service':
46+
content => epp($service_template, { service_user => $service_user, service_group => $service_user }),
47+
enable => $real_service_enable,
48+
} ~> Service['mongos']
4749

4850
service { 'mongos':
4951
ensure => $real_service_ensure,

spec/acceptance/mongos_spec.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
require 'spec_helper_acceptance'
44

55
describe 'mongodb::mongos class' do
6-
case fact('osfamily')
7-
when 'Debian'
8-
package_name = if fact('os.distro.codename') =~ %r{^(buster|bullseye)$}
6+
package_name = case fact('osfamily')
7+
when 'Debian'
8+
if fact('os.distro.codename') =~ %r{^(buster|bullseye)$}
99
'mongodb-org-server'
1010
else
1111
'mongodb-server'
1212
end
13-
config_file = '/etc/mongodb-shard.conf'
14-
else
15-
package_name = 'mongodb-org-server'
16-
config_file = '/etc/mongos.conf'
17-
end
13+
else
14+
'mongodb-org-server'
15+
end
16+
config_file = '/etc/mongos.conf'
1817

1918
describe 'installation' do
2019
it 'works with no errors' do

spec/classes/mongos_spec.rb

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
context "on #{os}" do
88
let(:facts) { facts }
99

10-
case facts[:os]['family']
11-
when 'Debian'
12-
package_name = if facts[:os]['release']['major'] =~ %r{(10)}
10+
package_name = case facts[:os]['family']
11+
when 'Debian'
12+
if facts[:os]['release']['major'] =~ %r{(10)}
1313
'mongodb-org-mongos'
1414
else
1515
'mongodb-server'
1616
end
17-
config_file = '/etc/mongodb-shard.conf'
18-
else
19-
package_name = 'mongodb-org-mongos'
20-
config_file = '/etc/mongos.conf'
21-
end
17+
else
18+
'mongodb-org-mongos'
19+
end
20+
config_file = '/etc/mongos.conf'
2221

2322
context 'with defaults' do
2423
it { is_expected.to compile.with_all_deps }
@@ -27,48 +26,25 @@
2726
it { is_expected.to contain_class('mongodb::mongos::install') }
2827

2928
if facts[:os]['release']['major'] =~ %r{(10)}
30-
it { is_expected.to contain_package('mongodb_mongos').with_ensure('4.4.8').with_name(package_name).with_tag('mongodb_package') }
29+
it { is_expected.to contain_package('mongodb_mongos').with_ensure('4.4.29').with_name(package_name).with_tag('mongodb_package') }
3130
else
3231
it { is_expected.to contain_package('mongodb_mongos').with_ensure('present').with_name(package_name).with_tag('mongodb_package') }
3332
end
3433

3534
# config
3635
it { is_expected.to contain_class('mongodb::mongos::config') }
3736

38-
case facts[:osfamily]
39-
when 'RedHat', 'Suse'
40-
expected_content = <<~CONFIG
41-
configdb = 127.0.0.1:27019
42-
fork = true
43-
pidfilepath = /var/run/mongodb/mongos.pid
44-
logpath = /var/log/mongodb/mongos.log
45-
unixSocketPrefix = /var/run/mongodb
46-
CONFIG
47-
48-
it { is_expected.to contain_file('/etc/mongos.conf').with_content(expected_content) }
49-
when 'Debian'
50-
expected_content = <<~CONFIG
51-
configdb = 127.0.0.1:27019
52-
CONFIG
53-
54-
it { is_expected.to contain_file('/etc/mongodb-shard.conf').with_content(expected_content) }
55-
end
37+
expected_content = <<~CONFIG
38+
configdb = 127.0.0.1:27019
39+
fork = true
40+
pidfilepath = /var/run/mongodb/mongos.pid
41+
logpath = /var/log/mongodb/mongos.log
42+
unixSocketPrefix = /var/run/mongodb
43+
CONFIG
44+
it { is_expected.to contain_file(config_file).with_content(expected_content) }
5645

5746
# service
5847
it { is_expected.to contain_class('mongodb::mongos::service') }
59-
60-
if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'Suse'
61-
it { is_expected.to contain_file('/etc/sysconfig/mongos') }
62-
else
63-
it { is_expected.not_to contain_file('/etc/sysconfig/mongos') }
64-
end
65-
66-
if facts[:osfamily] == 'Debian'
67-
it { is_expected.to contain_file('/etc/init.d/mongos') }
68-
else
69-
it { is_expected.not_to contain_file('/etc/init.d/mongos') }
70-
end
71-
7248
it { is_expected.to contain_service('mongos') }
7349
end
7450

@@ -92,7 +68,7 @@
9268
it { is_expected.to compile.with_all_deps }
9369

9470
if facts[:os]['release']['major'] =~ %r{(10)}
95-
it { is_expected.to contain_package('mongodb_mongos').with_name('mongo-foo').with_ensure('4.4.8').with_tag('mongodb_package') }
71+
it { is_expected.to contain_package('mongodb_mongos').with_name('mongo-foo').with_ensure('4.4.29').with_tag('mongodb_package') }
9672
else
9773
it { is_expected.to contain_package('mongodb_mongos').with_name('mongo-foo').with_ensure('present').with_tag('mongodb_package') }
9874
end
@@ -106,8 +82,6 @@
10682
end
10783

10884
it { is_expected.to compile.with_all_deps }
109-
it { is_expected.not_to contain_file('/etc/sysconfig/mongos') }
110-
it { is_expected.not_to contain_file('/etc/init.d/mongos') }
11185
it { is_expected.not_to contain_service('mongos') }
11286
end
11387

@@ -131,29 +105,10 @@
131105

132106
# config
133107
it { is_expected.to contain_class('mongodb::mongos::config') }
134-
135-
case facts[:osfamily]
136-
when 'RedHat', 'Suse'
137-
it { is_expected.to contain_file('/etc/mongos.conf').with_ensure('absent') }
138-
when 'Debian'
139-
it { is_expected.to contain_file('/etc/mongodb-shard.conf').with_ensure('absent') }
140-
end
141-
142-
if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'Suse'
143-
it { is_expected.to contain_file('/etc/sysconfig/mongos').with_ensure('absent') }
144-
else
145-
it { is_expected.not_to contain_file('/etc/sysconfig/mongos') }
146-
end
147-
148-
if facts[:osfamily] == 'Debian'
149-
it { is_expected.to contain_file('/etc/init.d/mongos').with_ensure('absent') }
150-
else
151-
it { is_expected.not_to contain_file('/etc/init.d/mongos') }
152-
end
108+
it { is_expected.to contain_file(config_file).with_ensure('absent') }
153109

154110
# service
155111
it { is_expected.to contain_class('mongodb::mongos::service') }
156-
157112
it { is_expected.to contain_service('mongos').with_ensure('stopped').with_enable(false) }
158113
end
159114
end

0 commit comments

Comments
 (0)