From a01715791fb496033f73d796bd861c02877140f1 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 13:54:57 +0200 Subject: [PATCH 1/6] improved acceptance --- spec/acceptance/service_dropin_spec.rb | 28 +++++++++++++++++++++++++- spec/acceptance/service_spec.rb | 16 ++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/service_dropin_spec.rb b/spec/acceptance/service_dropin_spec.rb index 9bc3d64..739d01f 100644 --- a/spec/acceptance/service_dropin_spec.rb +++ b/spec/acceptance/service_dropin_spec.rb @@ -22,6 +22,7 @@ class { 'systemd::logind': } systemd::service::dropin { 'test': execstart => '/bin/sleep 100', + before => Service['test'], } service { 'test': @@ -29,6 +30,23 @@ class { 'systemd::logind': } require => Class['::systemd'], } + // test2 + + systemd::service { 'test2': + execstart => '/bin/sleep 600', + before => Service['test2'], + } + + systemd::service::dropin { 'test2': + execstart => '/bin/sleep 200', + before => Service['test2'], + } + + service { 'test2': + ensure => 'running', + require => Class['::systemd'], + } + EOF # Run it twice and test for idempotency @@ -56,8 +74,16 @@ class { 'systemd::logind': } expect(shell("systemctl status test").exit_code).to be_zero end - it "check sleep" do + it "check sleep test" do expect(shell("ps -fea | grep \"[s]leep 100\"").exit_code).to be_zero end + + it "systemctl status test2" do + expect(shell("systemctl status test2").exit_code).to be_zero + end + + it "check sleep test2" do + expect(shell("ps -fea | grep \"[s]leep 200\"").exit_code).to be_zero + end end end diff --git a/spec/acceptance/service_spec.rb b/spec/acceptance/service_spec.rb index 49c9de8..332ae98 100644 --- a/spec/acceptance/service_spec.rb +++ b/spec/acceptance/service_spec.rb @@ -25,6 +25,16 @@ class { 'systemd::logind': } require => Class['::systemd'], } + systemd::service { 'test2': + execstart => '/bin/sleep 120', + before => Service['test2'], + } + + service { 'test2': + ensure => 'running', + require => Class['::systemd'], + } + EOF # Run it twice and test for idempotency @@ -42,10 +52,14 @@ class { 'systemd::logind': } its(:content) { should match 'RemoveIPC=no' } end - it "systemctl status" do + it "systemctl status test" do expect(shell("systemctl status test").exit_code).to be_zero end + it "systemctl status test2" do + expect(shell("systemctl status test2").exit_code).to be_zero + end + it "check sleep" do expect(shell("ps -fea | grep [s]leep").exit_code).to be_zero end From f6706d6771daf5dd19a45a2c088471266def9583 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 14:34:51 +0200 Subject: [PATCH 2/6] binds_to option to unit --- manifests/service.pp | 1 + manifests/service/dropin.pp | 1 + manifests/socket.pp | 1 + manifests/target.pp | 1 + manifests/timer.pp | 1 + templates/section/unit.erb | 3 +++ 6 files changed, 8 insertions(+) diff --git a/manifests/service.pp b/manifests/service.pp index e800c88..fba8966 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -60,6 +60,7 @@ $after_units = [], $before_units = [], $requires = [], + $binds_to = [], $conflicts = [], $on_failure = [], $partof = undef, diff --git a/manifests/service/dropin.pp b/manifests/service/dropin.pp index c5b9181..201c9a3 100644 --- a/manifests/service/dropin.pp +++ b/manifests/service/dropin.pp @@ -62,6 +62,7 @@ $after_units = [], $before_units = [], $requires = [], + $binds_to = [], $conflicts = [], $on_failure = [], $partof = undef, diff --git a/manifests/socket.pp b/manifests/socket.pp index c0a4cf3..2862f20 100644 --- a/manifests/socket.pp +++ b/manifests/socket.pp @@ -25,6 +25,7 @@ $after_units = [], $before_units = [], $requires = [], + $binds_to = [], $conflicts = [], $on_failure = [], $partof = undef, diff --git a/manifests/target.pp b/manifests/target.pp index 8678765..070bc77 100644 --- a/manifests/target.pp +++ b/manifests/target.pp @@ -8,6 +8,7 @@ $after_units = [], $before_units = [], $requires = [], + $binds_to = [], $conflicts = [], $on_failure = [], $partof = undef, diff --git a/manifests/timer.pp b/manifests/timer.pp index dcfd0fd..536869f 100644 --- a/manifests/timer.pp +++ b/manifests/timer.pp @@ -20,6 +20,7 @@ $after_units = [], $before_units = [], $requires = [], + $binds_to = [], $conflicts = [], $on_failure = [], $partof = undef, diff --git a/templates/section/unit.erb b/templates/section/unit.erb index 38a41e9..297cda6 100644 --- a/templates/section/unit.erb +++ b/templates/section/unit.erb @@ -20,6 +20,9 @@ Conflicts=<%= @conflicts.join(' ') %> <% if @requires.any? -%> Requires=<%= @requires.join(' ') %> <% end -%> +<% if @binds_to.any? -%> +BindsTo=<%= @binds_to.join(' ') %> +<% end -%> <% if @on_failure.any? -%> OnFailure=<%= @on_failure.join(' ') %> <% end -%> From a1bd4c786cb4a93d674272e8b41f5adce27a714c Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 14:35:41 +0200 Subject: [PATCH 3/6] doc binds_to --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c291f92..a052547 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ systemd-journald is a system service that collects and stores logging data * **before_units**: Configures ordering dependencies between units, for example, if a unit foo.service contains a setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service is started up (default: []) * **after_units**: Configures ordering dependencies between units. (default: []) * **requires**: Configures requirement dependencies on other units. If this unit gets activated, the units listed here will be activated as well. If one of the other units gets deactivated or its activation fails, this unit will be deactivated (default: []) +* **binds_to**: Configures requirement dependencies, very similar in style to Requires=. However, this dependency type is stronger: in addition to the effect of Requires= it declares that if the unit bound to is stopped, this unit will be stopped too (default: []) * **conflicts**: A space-separated list of unit names. Configures negative requirement dependencies. If a unit has a Conflicts= setting on another unit, starting the former will stop the latter and vice versa (default: []) * **wantedby**: Array, this has the effect that a dependency of type **Wants=** is added from the listed unit to the current unit (default: ['multi-user.target']) * **requiredby**: Array, this has the effect that a dependency of type **Requires=** is added from the listed unit to the current unit (default: []) From 4c0e2d122075ac8ad9ce759653ef5e5731a5c7e3 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 14:38:14 +0200 Subject: [PATCH 4/6] notes --- CHANGELOG.md | 5 +++++ metadata.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f33eb8..c8e99a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.2.5 + +* added **BindsTo** option - fixes [issue 118](https://github.com/NTTCom-MS/eyp-systemd/issues/118) +* fixed permissions on the forge build - fixes [issue 132](https://github.com/NTTCom-MS/eyp-systemd/issues/132) + ## 0.2.4 * BUGFIX: changed name for service dropins - thanks to [ArVincentr](https://github.com/ArVincentr) for this [PR-135](https://github.com/NTTCom-MS/eyp-systemd/pull/135) diff --git a/metadata.json b/metadata.json index dd6ab48..68c5bcf 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-systemd", - "version": "0.2.4", + "version": "0.2.5", "author": "eyp", "summary": "management of systemd services, services dropins, sockets, timers, timesyncd, journald, logind and resolved", "license": "Apache-2.0", From 6932eb32a655ed0205727ef396ee31f7e7fa7003 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 14:44:17 +0200 Subject: [PATCH 5/6] comentaris manifest --- spec/acceptance/service_dropin_spec.rb | 4 +++- spec/acceptance/service_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/acceptance/service_dropin_spec.rb b/spec/acceptance/service_dropin_spec.rb index 739d01f..ddb007b 100644 --- a/spec/acceptance/service_dropin_spec.rb +++ b/spec/acceptance/service_dropin_spec.rb @@ -15,6 +15,8 @@ class { 'systemd': } class { 'systemd::logind': } + # test + systemd::service { 'test': execstart => '/bin/sleep 60', before => Service['test'], @@ -30,7 +32,7 @@ class { 'systemd::logind': } require => Class['::systemd'], } - // test2 + # test2 systemd::service { 'test2': execstart => '/bin/sleep 600', diff --git a/spec/acceptance/service_spec.rb b/spec/acceptance/service_spec.rb index 332ae98..fb3c709 100644 --- a/spec/acceptance/service_spec.rb +++ b/spec/acceptance/service_spec.rb @@ -15,6 +15,8 @@ class { 'systemd': } class { 'systemd::logind': } + # test + systemd::service { 'test': execstart => '/bin/sleep 60', before => Service['test'], @@ -25,6 +27,8 @@ class { 'systemd::logind': } require => Class['::systemd'], } + # test 2 + systemd::service { 'test2': execstart => '/bin/sleep 120', before => Service['test2'], From faf9ad23a584fd098e8f4d63e3c8be9b5ef209c4 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Tue, 21 May 2019 16:34:39 +0200 Subject: [PATCH 6/6] logind tests --- spec/acceptance/logind_spec.rb | 31 ++++++++++++++++++++++++++ spec/acceptance/service_dropin_spec.rb | 7 ------ spec/acceptance/service_spec.rb | 7 ------ 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 spec/acceptance/logind_spec.rb diff --git a/spec/acceptance/logind_spec.rb b/spec/acceptance/logind_spec.rb new file mode 100644 index 0000000..512f3af --- /dev/null +++ b/spec/acceptance/logind_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper_acceptance' +require_relative './version.rb' + +describe 'systemd class' do + context 'service' do + it "cleanup" do + expect(shell("pkill sleep; echo").exit_code).to be_zero + end + + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOF + + class { 'systemd': } + + class { 'systemd::logind': } + + EOF + + # Run it twice and test for idempotency + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to eq(0) + end + + describe file("/etc/systemd/logind.conf") do + it { should be_file } + its(:content) { should match 'RemoveIPC=no' } + end + + end +end diff --git a/spec/acceptance/service_dropin_spec.rb b/spec/acceptance/service_dropin_spec.rb index ddb007b..3c010e9 100644 --- a/spec/acceptance/service_dropin_spec.rb +++ b/spec/acceptance/service_dropin_spec.rb @@ -13,8 +13,6 @@ class { 'systemd': } - class { 'systemd::logind': } - # test systemd::service { 'test': @@ -67,11 +65,6 @@ class { 'systemd::logind': } its(:content) { should match 'ExecStart=/bin/sleep 100' } end - describe file("/etc/systemd/logind.conf") do - it { should be_file } - its(:content) { should match 'RemoveIPC=no' } - end - it "systemctl status" do expect(shell("systemctl status test").exit_code).to be_zero end diff --git a/spec/acceptance/service_spec.rb b/spec/acceptance/service_spec.rb index fb3c709..56dedb9 100644 --- a/spec/acceptance/service_spec.rb +++ b/spec/acceptance/service_spec.rb @@ -13,8 +13,6 @@ class { 'systemd': } - class { 'systemd::logind': } - # test systemd::service { 'test': @@ -51,11 +49,6 @@ class { 'systemd::logind': } its(:content) { should match 'ExecStart=/bin/sleep 60' } end - describe file("/etc/systemd/logind.conf") do - it { should be_file } - its(:content) { should match 'RemoveIPC=no' } - end - it "systemctl status test" do expect(shell("systemctl status test").exit_code).to be_zero end