Skip to content

Commit

Permalink
Merge pull request #138 from jordiprats/master
Browse files Browse the repository at this point in the history
BindsTo option
  • Loading branch information
jordiprats authored May 21, 2019
2 parents 5bccccb + faf9ad2 commit cba7eb7
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [])
Expand Down
1 change: 1 addition & 0 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
$after_units = [],
$before_units = [],
$requires = [],
$binds_to = [],
$conflicts = [],
$on_failure = [],
$partof = undef,
Expand Down
1 change: 1 addition & 0 deletions manifests/service/dropin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
$after_units = [],
$before_units = [],
$requires = [],
$binds_to = [],
$conflicts = [],
$on_failure = [],
$partof = undef,
Expand Down
1 change: 1 addition & 0 deletions manifests/socket.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$after_units = [],
$before_units = [],
$requires = [],
$binds_to = [],
$conflicts = [],
$on_failure = [],
$partof = undef,
Expand Down
1 change: 1 addition & 0 deletions manifests/target.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$after_units = [],
$before_units = [],
$requires = [],
$binds_to = [],
$conflicts = [],
$on_failure = [],
$partof = undef,
Expand Down
1 change: 1 addition & 0 deletions manifests/timer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$after_units = [],
$before_units = [],
$requires = [],
$binds_to = [],
$conflicts = [],
$on_failure = [],
$partof = undef,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 31 additions & 0 deletions spec/acceptance/logind_spec.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 28 additions & 7 deletions spec/acceptance/service_dropin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class { 'systemd': }
class { 'systemd::logind': }
# test
systemd::service { 'test':
execstart => '/bin/sleep 60',
Expand All @@ -22,13 +22,31 @@ class { 'systemd::logind': }
systemd::service::dropin { 'test':
execstart => '/bin/sleep 100',
before => Service['test'],
}
service { 'test':
ensure => 'running',
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
Expand All @@ -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
23 changes: 17 additions & 6 deletions spec/acceptance/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class { 'systemd': }
class { 'systemd::logind': }
# test
systemd::service { 'test':
execstart => '/bin/sleep 60',
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions templates/section/unit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down

0 comments on commit cba7eb7

Please sign in to comment.