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/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: []) 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/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", 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 9bc3d64..3c010e9 100644 --- a/spec/acceptance/service_dropin_spec.rb +++ b/spec/acceptance/service_dropin_spec.rb @@ -13,7 +13,7 @@ class { 'systemd': } - class { 'systemd::logind': } + # test systemd::service { 'test': execstart => '/bin/sleep 60', @@ -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 @@ -47,17 +65,20 @@ 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 - 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..56dedb9 100644 --- a/spec/acceptance/service_spec.rb +++ b/spec/acceptance/service_spec.rb @@ -13,7 +13,7 @@ class { 'systemd': } - class { 'systemd::logind': } + # test systemd::service { 'test': execstart => '/bin/sleep 60', @@ -25,6 +25,18 @@ class { 'systemd::logind': } require => Class['::systemd'], } + # test 2 + + 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 @@ -37,13 +49,12 @@ 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' } + it "systemctl status test" do + expect(shell("systemctl status test").exit_code).to be_zero end - it "systemctl status" do - expect(shell("systemctl status test").exit_code).to be_zero + it "systemctl status test2" do + expect(shell("systemctl status test2").exit_code).to be_zero end it "check sleep" do 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 -%>