Skip to content
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

Simplify service class #1414

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
### END Package Configuration ###

### START Service Configuation ###
$service_ensure = running,
Stdlib::Ensure::Service $service_ensure = 'running',
$service_enable = true,
$service_flags = undef,
$service_restart = undef,
Expand Down
58 changes: 9 additions & 49 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
# Class: nginx::service
#
# This module manages NGINX service management and server rebuild
#
# Parameters:
#
# There are no default parameters for this class.
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
# This class file is not called directly
class nginx::service (
$service_restart = $nginx::service_restart,
$service_ensure = $nginx::service_ensure,
$service_enable = $nginx::service_enable,
$service_name = $nginx::service_name,
$service_flags = $nginx::service_flags,
$service_manage = $nginx::service_manage,
) {
# @summary Manage NGINX service management
# @api private
class nginx::service {
assert_private()

if $service_manage {
case $facts['os']['name'] {
'OpenBSD': {
service { $service_name:
ensure => $service_ensure,
enable => $service_enable,
flags => $service_flags,
hasstatus => true,
hasrestart => true,
}
}
default: {
service { $service_name:
ensure => $service_ensure,
enable => $service_enable,
hasstatus => true,
hasrestart => true,
}
}
}
}

# Allow overriding of 'restart' of Service resource; not used by default
if $service_restart {
Service[$service_name] {
restart => $service_restart,
if $nginx::service_manage {
service { $nginx::service_name:
ensure => $nginx::service_ensure,
enable => $nginx::service_enable,
flags => $nginx::service_flags,
restart => $nginx::service_restart,
}
}
}
4 changes: 1 addition & 3 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@
it do
is_expected.to contain_service('nginx').with(
ensure: 'running',
enable: true,
hasstatus: true,
hasrestart: true
enable: true
)
end

Expand Down