From ede91a6e4e14199ac41349315052828ce358f042 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 31 Aug 2020 12:30:31 +0200 Subject: [PATCH] Simplify service class It's valid to pass in undef values. That makes the OpenBSD check redundant. The same goes for the restart command. That removes pretty much all logic so there is no more benefit to having class parameters. That's why it now uses all the variables directly from the nginx class. The has{status,restart} parameters default to true since Puppet 2.7 so can be removed. --- manifests/init.pp | 2 +- manifests/service.pp | 58 ++++++-------------------------------- spec/classes/nginx_spec.rb | 4 +-- 3 files changed, 11 insertions(+), 53 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index c75bd2e69..904db3fc4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, diff --git a/manifests/service.pp b/manifests/service.pp index fd1a57812..aba84ebbf 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -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, } } } diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 91ecb3bb2..b384d5ba1 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -221,9 +221,7 @@ it do is_expected.to contain_service('nginx').with( ensure: 'running', - enable: true, - hasstatus: true, - hasrestart: true + enable: true ) end