Skip to content

Commit

Permalink
Manage unit file via systemd::unit_file
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Aug 19, 2021
1 parent 8837926 commit 3390cbe
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 101 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fixtures:
mcollective: https://github.com/choria-io/puppet-mcollective.git
choria: https://github.com/choria-io/puppet-choria.git
apt: https://github.com/puppetlabs/puppetlabs-apt.git
systemd: https://github.com/voxpupuli/puppet-systemd.git
cron_core: https://github.com/puppetlabs/puppetlabs-cron_core.git
yumrepo_core: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
forge_modules:
Expand Down
2 changes: 0 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,10 @@

if $facts['os']['family'] == 'Gentoo' {
$webhook_service_file = '/etc/init.d/webhook'
$webhook_service_template = 'webhook.init.gentoo.erb'
$webhook_service_file_mode = '0755'
$webhook_background = true
} else {
$webhook_service_file = '/etc/systemd/system/webhook.service'
$webhook_service_template = 'webhook.service.erb'
$webhook_service_file_mode = '0644'
$webhook_background = false
}
Expand Down
28 changes: 11 additions & 17 deletions manifests/webhook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$group = $r10k::params::webhook_group,
$background = $r10k::params::webhook_background,
$bin_template = $r10k::params::webhook_bin_template,
$service_template = $r10k::params::webhook_service_template,
$service_template = 'webhook.service.epp',
$service_file = $r10k::params::webhook_service_file,
$service_file_mode = $r10k::params::webhook_service_file_mode,
$use_mcollective = $r10k::params::webhook_use_mcollective,
Expand Down Expand Up @@ -48,43 +48,37 @@
ensure => $ensure_file,
owner => $user,
group => $group,
before => Service['webhook'],
before => Service['webhook.service'],
}

file { '/var/log/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
force => $ensure,
before => Service['webhook'],
before => Service['webhook.service'],
}

file { '/var/run/webhook':
ensure => $ensure_directory,
owner => $user,
group => $group,
before => Service['webhook'],
}

file { 'webhook_init_script':
ensure => $ensure_file,
content => template("r10k/${service_template}"),
path => $service_file,
mode => $service_file_mode,
notify => Service['webhook'],
before => Service['webhook.service'],
}

file { 'webhook_bin':
ensure => $ensure_file,
content => template($bin_template),
path => '/usr/local/bin/webhook',
mode => '0755',
notify => Service['webhook'],
notify => Service['webhook.service'],
}

service { 'webhook':
ensure => $ensure_service,
enable => $ensure,
systemd::unit_file { 'webhook.service':
ensure => $ensure_file,
content => epp("${module_name}/${service_template}", { 'user' => $user }),
enable => $ensure,
active => $ensure,
}

# We don't remove the packages/ gem as
Expand All @@ -106,7 +100,7 @@
group => 'peadmin',
mode => '0644',
content => file("${r10k::params::puppetconf_path}/ssl/certs/pe-internal-peadmin-mcollective-client.pem",'/dev/null'),
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/webhook/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
mode => $configfile_mode,
path => $configfile,
content => template($yaml_template),
notify => Service['webhook'],
notify => Service['webhook.service'],
}

if $manage_symlink {
Expand Down
6 changes: 3 additions & 3 deletions manifests/webhook/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package { 'sinatra':
ensure => $sinatra_version,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}

Expand All @@ -19,15 +19,15 @@
package { 'webrick':
ensure => $webrick_version,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}

if !defined(Package['json']) {
package { 'json':
ensure => installed,
provider => $provider,
notify => Service['webhook'],
notify => Service['webhook.service'],
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
{
"name": "choria/mcollective",
"version_requirement": ">= 0.10.0 <1.0.0"
},
{
"name": "puppet/systemd",
"version_requirement": ">= 3.2.0 < 4.0.0"
}
],
"requirements": [
Expand Down
24 changes: 12 additions & 12 deletions spec/classes/webhook/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -77,7 +77,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -140,7 +140,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end

Expand Down Expand Up @@ -185,7 +185,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end

Expand Down Expand Up @@ -230,7 +230,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -275,7 +275,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -320,7 +320,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -363,7 +363,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -408,7 +408,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -453,7 +453,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down Expand Up @@ -521,7 +521,7 @@
owner: 'r10k',
group: 'r10k',
mode: '0600',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
end
Expand All @@ -540,7 +540,7 @@
owner: 'root',
group: 'root',
mode: '0644',
notify: 'Service[webhook]'
notify: 'Service[webhook.service]'
)
end
content = '---
Expand Down
31 changes: 20 additions & 11 deletions spec/classes/webhook/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
end

let :pre_condition do
"service { 'webhook': ensure => present,}"
"service { 'webhook.service': ensure => 'running'}"
end

context 'Puppet Enterprise 2016.4.2' do
context 'Puppet Enterprise 2019.8.7' do
let :params do
{
is_pe_server: true
}
end
let :facts do
facts.merge(
pe_server_version: '2016.4.2'
pe_server_version: '2019.8.7'
)
end

Expand All @@ -28,24 +28,33 @@
else
'puppet_gem'
end
it do
is_expected.to contain_package('sinatra').with(
ensure: '~> 1.0',
provider: provider
)
end
it { is_expected.to contain_package('sinatra').with(provider: provider) }
it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('webrick') }
it { is_expected.not_to contain_package('json') }
end
context 'Puppet FOSS 6' do
let :facts do
facts.merge(
is_pe: false,
puppetversion: '6.24.0'
)
end

context 'Puppet FOSS 4.x' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('sinatra').with(ensure: 'installed') }
it { is_expected.to contain_package('webrick').with(ensure: 'installed') }
it { is_expected.to contain_package('json').with(ensure: 'installed') }
end
context 'Puppet FOSS 7' do
let :facts do
facts.merge(
is_pe: false,
puppetversion: '4.8.0'
puppetversion: '7.10.0'
)
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('sinatra').with(ensure: 'installed') }
it { is_expected.to contain_package('webrick').with(ensure: 'installed') }
it { is_expected.to contain_package('json').with(ensure: 'installed') }
Expand Down
30 changes: 5 additions & 25 deletions spec/classes/webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,13 @@
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('r10k::webhook::package') }
it { is_expected.not_to contain_file('peadmin-cert.pem').with(path: '/var/lib/peadmin/.mcollective.d/peadmin-cert.pem') }
end

context 'On PE', if: facts[:osfamily] == 'RedHat' do
let :facts do
super().merge(
is_pe: 'true',
pe_version: '2016.4.2'
)
end

if facts[:operatingsystemmajrelease].to_i >= 7
it do
is_expected.to contain_file('webhook_init_script').with(
path: '/etc/systemd/system/webhook.service',
content: %r{\[Unit\]}
)
end
else
it do
is_expected.to contain_file('webhook_init_script').with(
path: '/etc/init.d/webhook',
content: %r{#!\/bin\/bash}
)
end
end
it { is_expected.to contain_package('sinatra') }
it { is_expected.to contain_package('json') }
it { is_expected.to contain_package('webrick') }
it { is_expected.to contain_systemd__unit_file('webhook.service') }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/default_module_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
pe_version: '2016.4.1'
puppet_environmentpath: '/etc/puppetlabs/code/environments'
puppet_vardir: '/opt/puppetlabs/puppet/cache'
service_provider: systemd
29 changes: 0 additions & 29 deletions templates/webhook.init.gentoo.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%- | String[1] $user | -%>
# THIS FILE IS MANAGED BY PUPPET
[Unit]
Description=R10K Webhook Service
After=syslog.target network.target
Expand All @@ -6,7 +8,7 @@ After=syslog.target network.target
Type=simple
EnvironmentFile=-/etc/sysconfig/webhook
RuntimeDirectory=webhook
User=<%= @user %>
User=<%= $user %>
TimeoutStartSec=90
TimeoutStopSec=30
RestartSec=10000
Expand Down

0 comments on commit 3390cbe

Please sign in to comment.