From d1971cac54d6e8713ef278438d93ea443d1e94db Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Sat, 9 Feb 2019 12:35:50 -0600 Subject: [PATCH 1/4] Adding featues for configuring Systemd service options. --- README.md | 11 +++ manifests/instance.pp | 56 +++++++------- manifests/params.pp | 1 - manifests/service.pp | 22 +++--- manifests/service/systemd.pp | 3 +- spec/defines/service/systemd_spec.rb | 105 ++++++++++++++++++++++++++- spec/defines/service_spec.rb | 9 ++- templates/etc/init.d/systemd.erb | 9 ++- 8 files changed, 169 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 38ea142..392dcbd 100644 --- a/README.md +++ b/README.md @@ -832,6 +832,17 @@ Optional. Sets the array of runmodes to apply to the AEM instance. Do not use th ##### `sample_content` Optional. Sets whether or not to include the sample content (e.g. Geometrixx). Valid options: `true` or `false`. Default: `true`. [AEM Documentation][AEM Sample Content]. +##### `service_options` +Optional. Hash. Sets the service options, pretty much only used for the systemd implementation. Default: + +``` +{ + 'TimeoutStopSec' => '4min', + 'KillSignal' => 'SIGCONT', + 'PrivateTmp' => true +} +``` + ##### `snooze` Optional. Sets the wait period between checks for installation completion. When monitoring the system for up state, this is the wait period between checks. Value is specified in seconds. Valid options: any number. Default: `10`. diff --git a/manifests/instance.pp b/manifests/instance.pp index cd9b107..25d9e90 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -4,28 +4,29 @@ # # define aem::instance ( - $ensure = 'present', - $context_root = undef, - $debug_port = undef, - $group = 'aem', - $home = undef, - $jvm_mem_opts = '-Xmx1024m', - $jvm_opts = undef, - $manage_group = true, - $manage_home = true, - $manage_user = true, - $osgi_configs = undef, - $crx_packages = undef, - $port = 4502, - $runmodes = [], - $sample_content = true, - $snooze = 10, - $source = undef, - $status = 'enabled', - $timeout = 600, - $type = author, - $user = 'aem', - $version = undef) { + $ensure = 'present', + $context_root = undef, + $debug_port = undef, + $group = 'aem', + $home = undef, + $jvm_mem_opts = '-Xmx1024m', + $jvm_opts = undef, + $manage_group = true, + $manage_home = true, + $manage_user = true, + $osgi_configs = undef, + $crx_packages = undef, + $port = 4502, + $runmodes = [], + $sample_content = true, + $service_options = undef, + $snooze = 10, + $source = undef, + $status = 'enabled', + $timeout = 600, + $type = author, + $user = 'aem', + $version = undef) { anchor { "aem::${name}::begin": } @@ -112,11 +113,12 @@ if $status != 'unmanaged' { aem::service { $name : - ensure => $ensure, - status => $status, - home => $_home, - user => $user, - group => $group, + ensure => $ensure, + status => $status, + home => $_home, + user => $user, + group => $group, + service_options => $service_options } } diff --git a/manifests/params.pp b/manifests/params.pp index b2c4650..ad157d6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -9,5 +9,4 @@ $puppetgem = 'puppet_gem' $xmlsimple_ver = '>=1.1.5' - } \ No newline at end of file diff --git a/manifests/service.pp b/manifests/service.pp index e3e7d39..3beb6e6 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -5,11 +5,12 @@ # Based on Elastic Search service management. # define aem::service ( - $ensure = 'present', - $group = 'aem', - $home = undef, - $status = 'enabled', - $user = 'aem', + $ensure = 'present', + $group = 'aem', + $home = undef, + $status = 'enabled', + $user = 'aem', + $service_options = { 'TimeoutStopSec' => '4min', 'KillSignal' => 'SIGCONT', 'PrivateTmp' => true } ) { @@ -64,11 +65,12 @@ } 'systemd' : { aem::service::systemd { $name : - ensure => $ensure, - status => $status, - group => $group, - home => $home, - user => $user, + ensure => $ensure, + status => $status, + group => $group, + home => $home, + user => $user, + service_options => $service_options } } default : { diff --git a/manifests/service/systemd.pp b/manifests/service/systemd.pp index 360d383..368f10e 100644 --- a/manifests/service/systemd.pp +++ b/manifests/service/systemd.pp @@ -11,7 +11,8 @@ $status, $group, $home, - $user + $user, + $service_options ) { # Setup the system state. diff --git a/spec/defines/service/systemd_spec.rb b/spec/defines/service/systemd_spec.rb index 184bdc9..a1146be 100644 --- a/spec/defines/service/systemd_spec.rb +++ b/spec/defines/service/systemd_spec.rb @@ -24,7 +24,8 @@ status: 'enabled', home: '/opt/aem', user: 'aem', - group: 'aem' + group: 'aem', + service_options: { 'TimeoutStopSec' => '4min', 'KillSignal' => 'SIGCONT', 'PrivateTmp' => true } } end @@ -48,4 +49,106 @@ end + describe 'aem-author.service file' do + context 'default contents' do + let(:params) do + default_params + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /PIDFile=\/opt\/aem\/crx-quickstart\/conf\/cq.pid/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /User=aem/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /Group=aem/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /ExecStart=\/opt\/aem\/crx-quickstart\/bin\/start/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /ExecStop=\/opt\/aem\/crx-quickstart\/bin\/stop/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /TimeoutStopSec=4min/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /KillSignal=SIGCONT/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /PrivateTmp=true/ + ) + end + end + + context 'custom properties' do + let(:params) do + { + ensure: 'present', + status: 'enabled', + home: '/opt/aem', + user: 'aem', + group: 'aem', + service_options: { + 'TimeoutStopSec' => '10min', + 'KillSignal' => 'SIGKILL', + 'PrivateTmp' => true + } + } + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /TimeoutStopSec=10min/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /KillSignal=SIGKILL/ + ) + end + it do + is_expected.to contain_file( + '/lib/systemd/system/aem-aem.service' + ).with_content( + /PrivateTmp=true/ + ) + end + end + end + end diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 1cd7795..8585baf 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -59,7 +59,8 @@ status: 'enabled', group: 'aem', home: '/opt/aem', - user: 'aem' + user: 'aem', + service_options: { 'TimeoutStopSec' => '4min', 'KillSignal' => 'SIGCONT', 'PrivateTmp' => true } ) end end @@ -125,7 +126,8 @@ status: 'enabled', group: 'aem', home: '/opt/aem', - user: 'aem' + user: 'aem', + service_options: { 'TimeoutStopSec' => '4min', 'KillSignal' => 'SIGCONT', 'PrivateTmp' => true } ) end end @@ -171,7 +173,8 @@ status: 'enabled', group: 'aem', home: '/opt/aem', - user: 'aem' + user: 'aem', + service_options: { 'TimeoutStopSec' => '4min', 'KillSignal' => 'SIGCONT', 'PrivateTmp' => true } ) end end diff --git a/templates/etc/init.d/systemd.erb b/templates/etc/init.d/systemd.erb index 2f7eef1..89baa90 100644 --- a/templates/etc/init.d/systemd.erb +++ b/templates/etc/init.d/systemd.erb @@ -11,7 +11,7 @@ Type=forking PIDFile=<%= @home %>/crx-quickstart/conf/cq.pid User=<%= @user %> Group=<%= @group %> -ExecStart=<%= @home %>/crx-quickstart/bin/start +ExecStart=<%= @home %>/crx-quickstart/bin/start ExecStop=<%= @home %>/crx-quickstart/bin/stop # We want systemd to give aem some time to finish gracefully, but still want # it to kill aem after TimeoutStopSec if something went wrong during the @@ -19,9 +19,10 @@ ExecStop=<%= @home %>/crx-quickstart/bin/stop # ExecStop, which would kill aem. We are sending useless SIGCONT here to give # aem time to finish. -TimeoutStopSec=4min -KillSignal=SIGCONT -PrivateTmp=true +<% @service_options.each do |key, value| -%> +<%= key %>=<%= value %> +<% end -%> + [Install] WantedBy=multi-user.target From e4b7c082d70a6f44173b5d5c86d29c7869ee7a1b Mon Sep 17 00:00:00 2001 From: Bryan Stopp Date: Sat, 9 Feb 2019 12:57:52 -0600 Subject: [PATCH 2/4] Fixing rubocop issues --- spec/defines/service/systemd_spec.rb | 48 ++++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/spec/defines/service/systemd_spec.rb b/spec/defines/service/systemd_spec.rb index a1146be..56f8b41 100644 --- a/spec/defines/service/systemd_spec.rb +++ b/spec/defines/service/systemd_spec.rb @@ -58,54 +58,54 @@ is_expected.to contain_file( '/lib/systemd/system/aem-aem.service' ).with_content( - /PIDFile=\/opt\/aem\/crx-quickstart\/conf\/cq.pid/ + %r|PIDFile=/opt/aem/crx-quickstart/conf/cq.pid| ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /User=aem/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /Group=aem/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( - /ExecStart=\/opt\/aem\/crx-quickstart\/bin\/start/ + %r|ExecStart=/opt/aem/crx-quickstart/bin/start| ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( - /ExecStop=\/opt\/aem\/crx-quickstart\/bin\/stop/ + %r|ExecStop=/opt/aem/crx-quickstart/bin/stop| ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /TimeoutStopSec=4min/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /KillSignal=SIGCONT/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /PrivateTmp=true/ ) @@ -115,35 +115,35 @@ context 'custom properties' do let(:params) do { - ensure: 'present', - status: 'enabled', - home: '/opt/aem', - user: 'aem', - group: 'aem', - service_options: { - 'TimeoutStopSec' => '10min', - 'KillSignal' => 'SIGKILL', - 'PrivateTmp' => true - } + ensure: 'present', + status: 'enabled', + home: '/opt/aem', + user: 'aem', + group: 'aem', + service_options: { + 'TimeoutStopSec' => '10min', + 'KillSignal' => 'SIGKILL', + 'PrivateTmp' => true + } } end - it do + it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /TimeoutStopSec=10min/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /KillSignal=SIGKILL/ ) end it do is_expected.to contain_file( - '/lib/systemd/system/aem-aem.service' + '/lib/systemd/system/aem-aem.service' ).with_content( /PrivateTmp=true/ ) From 022bc2b6bb3874286b98759c9109efd53d6ff862 Mon Sep 17 00:00:00 2001 From: bstopp Date: Mon, 8 Jul 2019 21:06:57 -0500 Subject: [PATCH 3/4] Adding Acceptance test & removing old OS Support --- metadata.json | 10 +++++----- spec/acceptance/aem/service_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 spec/acceptance/aem/service_spec.rb diff --git a/metadata.json b/metadata.json index bee1963..b345367 100644 --- a/metadata.json +++ b/metadata.json @@ -28,21 +28,21 @@ { "operatingsystem": "CentOS", "operatingsystemrelease": [ - "7.2" + "7.4", + "7.6" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "14.04", - "16.04" + "16.04", + "18.04" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ - "7", - "8" + "9" ] } ], diff --git a/spec/acceptance/aem/service_spec.rb b/spec/acceptance/aem/service_spec.rb new file mode 100644 index 0000000..b9f89c7 --- /dev/null +++ b/spec/acceptance/aem/service_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper_acceptance' + +describe 'systemctl service configs' do + + + it 'should create systemctl service file' do + shell('test -f /lib/systemd/system/aem-author.service', acceptable_exit_codes: 0) + end + + it 'should specify the timeout' do + shell("grep TimeoutStopSec=4min /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + end + + it 'should specify the kill signal' do + shell("grep KillSignal=SIGCONT /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + end + + it 'should specify the private tmp' do + shell("grep PrivateTmp=true /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + end +end From 595f708d708fd213ad4c4e838d19771017dc493d Mon Sep 17 00:00:00 2001 From: bstopp Date: Mon, 8 Jul 2019 21:17:13 -0500 Subject: [PATCH 4/4] Fixing rubocop issues. --- spec/acceptance/aem/service_spec.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/acceptance/aem/service_spec.rb b/spec/acceptance/aem/service_spec.rb index b9f89c7..4009d4d 100644 --- a/spec/acceptance/aem/service_spec.rb +++ b/spec/acceptance/aem/service_spec.rb @@ -4,20 +4,19 @@ describe 'systemctl service configs' do - it 'should create systemctl service file' do shell('test -f /lib/systemd/system/aem-author.service', acceptable_exit_codes: 0) end it 'should specify the timeout' do - shell("grep TimeoutStopSec=4min /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + shell('grep TimeoutStopSec=4min /lib/systemd/system/aem-author.service', acceptable_exit_codes: 0) end it 'should specify the kill signal' do - shell("grep KillSignal=SIGCONT /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + shell('grep KillSignal=SIGCONT /lib/systemd/system/aem-author.service', acceptable_exit_codes: 0) end it 'should specify the private tmp' do - shell("grep PrivateTmp=true /lib/systemd/system/aem-author.service", acceptable_exit_codes: 0) + shell('grep PrivateTmp=true /lib/systemd/system/aem-author.service', acceptable_exit_codes: 0) end end