Skip to content

Commit

Permalink
fix server dependencies + allow standalone
Browse files Browse the repository at this point in the history
We only need to depend on the database, if one is actually used. the
database_type var defaults to postgres, so we can't only rely on that.
there is also a manage_database var. This allows us to only provision
the zabbix-server on one node, and the database on a different one. We
need to configure the systemd unit correctly for this.
  • Loading branch information
bastelfreak committed Jun 5, 2017
1 parent aa53836 commit 5fea593
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
server_configfile_path => $server_configfile_path,
zabbix_user => $zabbix_user,
additional_service_params => $real_additional_service_params,
manage_database => $manage_database,
require => Package["zabbix-server-${db}"],
}

Expand Down
4 changes: 4 additions & 0 deletions manifests/startup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Optional[String] $zabbix_user = undef,
String $additional_service_params = '',
String $service_type = 'simple',
Optional[Boolean] $manage_database = undef,
) {

case $title {
Expand All @@ -34,6 +35,9 @@
unless $database_type {
fail('you have to provide a database_type param')
}
unless $manage_database {
fail('you have to provide a manage_database param')
}
}
default: {
fail('we currently only spport a title that contains agent or server')
Expand Down
13 changes: 8 additions & 5 deletions spec/defines/startup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
let :params do
{
server_configfile_path: '/something',
database_type: 'mysql'
database_type: 'mysql',
manage_database: true
}
end

Expand Down Expand Up @@ -159,7 +160,8 @@
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'mysql',
additional_service_params: '--foreground'
additional_service_params: '--foreground',
manage_database: true
}
end

Expand All @@ -173,18 +175,19 @@
end
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{ExecStart=/usr/sbin/zabbix_server --foreground -c /something}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{PIDFile=/somethingelse}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target mysqld.service}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=mysqld.service}) }

context 'and works on postgres' do
let :params do
{
server_configfile_path: '/something',
pidfile: '/somethingelse',
database_type: 'postgres'
database_type: 'postgresql',
manage_database: true
}
end

it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=syslog.target network.target postgresql.service}) }
it { is_expected.to contain_file('/etc/systemd/system/zabbix-server.service').with_content(%r{After=postgresql.service}) }
end
end

Expand Down
8 changes: 4 additions & 4 deletions templates/zabbix-server-systemd.init.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Unit]
Description=Zabbix Server
Documentation=man:zabbix_server
<% if @database_type == "mysql" %>
After=syslog.target network.target mysqld.service
<% else %>
After=syslog.target network.target postgresql.service
<% if @database_type == "mysql" and @manage_database %>
After=mysqld.service
<% elsif @database_type == "postgresql" and @manage_database %>
After=postgresql.service
<% end -%>

[Service]
Expand Down

0 comments on commit 5fea593

Please sign in to comment.