-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a private socket_service helper #199
Merged
+80
−20
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# @summary Create a systemd socket activated service | ||
# @api private | ||
# | ||
# Systemd socket activated services have their own dependencies. This is a | ||
# convenience wrapper around systemd::unit_file. | ||
# | ||
# @param name [Pattern['^[^/]+$']] | ||
# The target unit file to create | ||
# @param socket_content | ||
# The content for the socket unit file. Required if ensure isn't absent. | ||
# @param service_content | ||
# The content for the service unit file. Required if ensure isn't absent. | ||
# @param enable | ||
# Whether to enable or disable the service. By default this is derived from | ||
# $ensure but can be overridden for advanced use cases where the service is | ||
# running during a migration but shouldn't be enabled on boot. | ||
define pulpcore::socket_service ( | ||
Enum['running', 'stopped', 'present', 'absent'] $ensure = 'running', | ||
Optional[String[1]] $socket_content = undef, | ||
Optional[String[1]] $service_content = undef, | ||
Optional[Boolean] $enable = undef, | ||
) { | ||
assert_type(Pattern['^[^/]+$'], $name) | ||
|
||
if $ensure != 'absent' { | ||
assert_type(NotUndef, $socket_content) | ||
assert_type(NotUndef, $service_content) | ||
} | ||
|
||
$active = $ensure ? { | ||
'running' => true, | ||
'stopped' => false, | ||
'absent' => false, | ||
default => undef, | ||
} | ||
$real_enable = pick($enable, $active) | ||
|
||
$unit_file_ensure = bool2str($ensure == 'absent', 'absent', 'present') | ||
|
||
systemd::unit_file { "${name}.socket": | ||
ensure => $unit_file_ensure, | ||
content => $socket_content, | ||
active => $active, | ||
enable => $real_enable, | ||
} | ||
|
||
systemd::unit_file { "${name}.service": | ||
ensure => $unit_file_ensure, | ||
content => $service_content, | ||
active => $active, | ||
enable => $real_enable, | ||
} | ||
|
||
if $active or $real_enable { | ||
# Systemd needs both .socket and .service to be loaded when starting the | ||
# service. The unit_file takes care of matching, this ensures the | ||
# non-matching order. | ||
File["/etc/systemd/system/${name}.socket"] -> Service["${name}.service"] | ||
File["/etc/systemd/system/${name}.service"] -> Service["${name}.socket"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,14 @@ | |
|
||
it 'configures services' do | ||
is_expected.to contain_class('pulpcore::service') | ||
is_expected.to contain_pulpcore__socket_service('pulpcore-api') | ||
is_expected.to contain_systemd__unit_file('pulpcore-api.socket') | ||
is_expected.to contain_systemd__unit_file('pulpcore-api.service') | ||
is_expected.to contain_file('/etc/systemd/system/pulpcore-api.socket').that_comes_before('Service[pulpcore-api.service]') | ||
is_expected.to contain_pulpcore__socket_service('pulpcore-content') | ||
is_expected.to contain_systemd__unit_file('pulpcore-content.socket') | ||
is_expected.to contain_systemd__unit_file('pulpcore-content.service') | ||
is_expected.to contain_file('/etc/systemd/system/pulpcore-content.socket').that_comes_before('Service[pulpcore-content.service]') | ||
is_expected.to contain_systemd__unit_file('pulpcore-resource-manager.service') | ||
is_expected.to contain_systemd__unit_file('[email protected]') | ||
is_expected.to contain_service("[email protected]").with_ensure(true) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see
present
in the list but it is in the Enum of the parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what
default
is for. I agree it's a bit ugly, but puppet-lint wants adefault
statement and this is how I dealt with it.