Skip to content

Commit

Permalink
Fix CentOS8 - jail user/ enable service (#25)
Browse files Browse the repository at this point in the history
* Fix CentOS8

* Update REFERENCE.md
  • Loading branch information
voxel01 committed Jun 8, 2023
1 parent 3027ede commit 136e92c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
13 changes: 11 additions & 2 deletions REFERENCE.md
Expand Up @@ -77,6 +77,7 @@ class { 'varnish':
The following parameters are available in the `varnish` class:

* [`service_ensure`](#-varnish--service_ensure)
* [`service_enable`](#-varnish--service_enable)
* [`reload_vcl`](#-varnish--reload_vcl)
* [`nfiles`](#-varnish--nfiles)
* [`memlock`](#-varnish--memlock)
Expand Down Expand Up @@ -122,6 +123,14 @@ Ensure for varnishservice

Default value: `'running'`

##### <a name="-varnish--service_enable"></a>`service_enable`

Data type: `Boolean`

If Service should be enabled

Default value: `true`

##### <a name="-varnish--reload_vcl"></a>`reload_vcl`

Data type: `Boolean`
Expand Down Expand Up @@ -173,11 +182,11 @@ Default value: `'varnish'`

##### <a name="-varnish--varnish_jail_user"></a>`varnish_jail_user`

Data type: `String`
Data type: `Optional[String]`

passed to varnish-conf

Default value: `'vcache'`
Default value: `undef`

##### <a name="-varnish--varnish_group"></a>`varnish_group`

Expand Down
2 changes: 2 additions & 0 deletions data/os/Debian.yaml
@@ -0,0 +1,2 @@
---
varnish::varnish_jail_user: vcache
5 changes: 4 additions & 1 deletion manifests/init.pp
Expand Up @@ -2,6 +2,8 @@
#
# @param service_ensure
# Ensure for varnishservice
# @param service_enable
# If Service should be enabled
# @param reload_vcl
# V4 paramter if Varnish will be reloaded - deprecated
# Will be removed when support for RHEL7 is dropped
Expand Down Expand Up @@ -92,13 +94,14 @@
#
class varnish (
Stdlib::Ensure::Service $service_ensure = 'running',
Boolean $service_enable = true,
Boolean $reload_vcl = true,
String $nfiles = '131072',
String $memlock = '100M',
String $storage_type = 'malloc',
Stdlib::Absolutepath $varnish_vcl_conf = '/etc/varnish/default.vcl',
String $varnish_user = 'varnish',
String $varnish_jail_user = 'vcache',
Optional[String] $varnish_jail_user = undef,
String $varnish_group = 'varnish',
Optional[String[1]] $varnish_listen_address = undef,
Stdlib::Port $varnish_listen_port = 6081,
Expand Down
4 changes: 4 additions & 0 deletions manifests/service.pp
Expand Up @@ -10,12 +10,15 @@
#
# @param ensure
# Ensure service status
# @param enable
# If Service should be enabled
# @param vcl_reload_script
# Path to reload script
#
# @api private
class varnish::service (
Stdlib::Ensure::Service $ensure = $varnish::service_ensure,
Boolean $enable = $varnish::service_enable,
Stdlib::Absolutepath $vcl_reload_script = '/usr/share/varnish/reload-vcl'
) {
# include install
Expand All @@ -29,5 +32,6 @@
~> service { 'varnish':
ensure => $ensure,
require => Package['varnish'],
enable => $enable,
}
}
25 changes: 20 additions & 5 deletions spec/classes/varnish_spec.rb
Expand Up @@ -14,13 +14,13 @@
it { is_expected.to contain_class('varnish::install').with('add_repo' => 'false') }

it {
is_expected.to contain_class('varnish::service').with('ensure' => 'running')
is_expected.to contain_class('varnish::service').with('ensure' => 'running', 'enable' => true)
is_expected.to contain_systemd__dropin_file('varnish_service').with_unit('varnish.service')
is_expected.to contain_systemd__dropin_file('varnish_service').with_filename('varnish_override.conf')
is_expected.to contain_service('varnish').with_ensure('running')
is_expected.to contain_service('varnish').with(
'ensure' => 'running',
'require' => 'Package[varnish]'
'require' => 'Package[varnish]',
'enable' => true
)
}

Expand Down Expand Up @@ -65,7 +65,7 @@
)
}

if (facts[:osfamily] == 'RedHat') && (facts[:os]['release']['major'] == '7')
if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_file('varnish-conf').without_content(%r{\s -j unix,user=vcache}) }
else
it { is_expected.to contain_file('varnish-conf').with_content(%r{\s -j unix,user=vcache}) }
Expand Down Expand Up @@ -139,7 +139,22 @@

it { is_expected.to compile }
it { is_expected.to contain_class('varnish::install').with_version('6.0.0-manual') }
it { is_expected.to contain_file('varnish-conf').with_content(%r{\s -j unix,user=vcache}) }

if facts[:osfamily] == 'RedHat'
it { is_expected.to contain_file('varnish-conf').without_content(%r{\s -j unix,user=vcache}) }
else
it { is_expected.to contain_file('varnish-conf').with_content(%r{\s -j unix,user=vcache}) }
end
end

context 'set Jail User' do
let :params do
{ version: '6.0.0-manual',
varnish_jail_user: 'myjail' }
end

it { is_expected.to compile }
it { is_expected.to contain_file('varnish-conf').with_content(%r{\s -j unix,user=myjail}) }
end

context 'Storage Type MSE' do
Expand Down
2 changes: 1 addition & 1 deletion templates/varnish-conf.erb
Expand Up @@ -109,7 +109,7 @@ DAEMON_OPTS="-a <%= scope.lookupvar('varnish_listen_address') %>:<%= scope.looku
<% @additional_parameters.each do |param, value| -%>
-p <%= param %>=<%= value %> \
<% end -%>
<% if scope.lookupvar('varnish::major_version').to_i >= 5 -%>
<% if scope.lookupvar('varnish::major_version').to_i >= 5 && scope.lookupvar('varnish_jail_user') -%>
-j unix,user=<%= scope.lookupvar('varnish_jail_user') %> \
<% end -%>
<% if scope.lookupvar('varnish::major_version').to_i == 3 -%>
Expand Down

0 comments on commit 136e92c

Please sign in to comment.