Skip to content

Commit

Permalink
Add manage_init_script parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
baurmatt committed Oct 22, 2018
1 parent 87d6527 commit 029ed8d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
22 changes: 14 additions & 8 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
# [*loadmodule*]
# Module to load at agent startup.
#
# [*manage_init_script*]
# If the init script should be managed by this module. Attention: This might cause problems with some config options of this module (e.g agent_configfile_path)
#
# === Example
#
# Basic installation:
Expand Down Expand Up @@ -263,6 +266,7 @@
Hash[String, Array] $selinux_rules = $zabbix::params::selinux_rules,
String $additional_service_params = $zabbix::params::additional_service_params,
String $service_type = $zabbix::params::service_type,
Boolean $manage_init_script = $zabbix::params::manage_init_script,
) inherits zabbix::params {

# the following two codeblocks are a bit blargh. The correct default value for
Expand Down Expand Up @@ -340,14 +344,16 @@
}

# Ensure that the correct config file is used.
zabbix::startup {$servicename:
pidfile => $pidfile,
agent_configfile_path => $agent_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
service_type => $real_service_type,
service_name => 'zabbix-agent',
require => Package[$zabbix_package_agent],
if $manage_init_script {
zabbix::startup {$servicename:
pidfile => $pidfile,
agent_configfile_path => $agent_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
service_type => $real_service_type,
service_name => 'zabbix-agent',
require => Package[$zabbix_package_agent],
}
}

if $agent_configfile_path != '/etc/zabbix/zabbix_agentd.conf' {
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
$zabbix_web_ip = '127.0.0.1'
$manage_database = true
$manage_service = true
$manage_init_script = true
$default_vhost = false
$manage_firewall = false
$manage_apt = true
Expand Down
24 changes: 15 additions & 9 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
# [*sslkeylocation_dir*]
# Location of SSL private key files for client authentication.
#
# [*manage_init_script*]
# If the init script should be managed by this module. Attention: This might cause problems with some config options of this module (e.g server_configfile_path)
#
# === Example
#
# When running everything on a single node, please check
Expand Down Expand Up @@ -378,6 +381,7 @@
Boolean $manage_selinux = $zabbix::params::manage_selinux,
String $additional_service_params = $zabbix::params::additional_service_params,
Optional[String[1]] $zabbix_user = $zabbix::params::server_zabbix_user,
Boolean $manage_init_script = $zabbix::params::manage_init_script,
) inherits zabbix::params {

# the following codeblock is a bit blargh. The correct default value for
Expand Down Expand Up @@ -458,15 +462,17 @@
}

# Ensure that the correct config file is used.
zabbix::startup {'zabbix-server':
pidfile => $pidfile,
database_type => $database_type,
server_configfile_path => $server_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
manage_database => $manage_database,
service_name => 'zabbix-server',
require => Package["zabbix-server-${db}"],
if $manage_init_script {
zabbix::startup {'zabbix-server':
pidfile => $pidfile,
database_type => $database_type,
server_configfile_path => $server_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
manage_database => $manage_database,
service_name => 'zabbix-server',
require => Package["zabbix-server-${db}"],
}
}

if $server_configfile_path != '/etc/zabbix/zabbix_server.conf' {
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@
end
end

context 'when declaring manage_init_script is false' do
let :params do
{
manage_init_script: false
}
end

it { is_expected.not_to contain_zabbix__startup('zabbix-agent') }
end

context 'when declaring zabbix_alias' do
let :params do
{
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@
it { is_expected.not_to contain_firewall('151 zabbix-server') }
end

context 'it creates a startup script' do
case facts[:osfamily]
when 'Archlinux', 'Fedora'
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('absent') }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_ensure('file') }
else
it { is_expected.to contain_file('/etc/init.d/zabbix-server').with_ensure('file') }
it { is_expected.not_to contain_file('/etc/systemd/system/zabbix-server.service') }
end
end

context 'when declaring manage_init_script is false' do
let :params do
{
manage_init_script: false
}
end

it { is_expected.not_to contain_zabbix__startup('zabbix-server') }
end

# If manage_service is true (default), it should create a service
# and ensure that it is running.
context 'when declaring manage_service is true' do
Expand Down

0 comments on commit 029ed8d

Please sign in to comment.