From 408259286b769f40c840cbf3ce67142463d33b07 Mon Sep 17 00:00:00 2001 From: Cesare Bellini Date: Wed, 17 Dec 2014 17:39:56 +0000 Subject: [PATCH 1/3] Add agent systemd support --- .kitchen.yml | 1 + attributes/agent.rb | 2 -- recipes/_agent_common_service.rb | 31 +++++++++++++++------- templates/default/zabbix-agent.service.erb | 13 +++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 templates/default/zabbix-agent.service.erb diff --git a/.kitchen.yml b/.kitchen.yml index 25d1b6d..d925883 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -10,6 +10,7 @@ platforms: - name: ubuntu-12.04 - name: centos-6.4 - name: centos-5.9 +- name: centos-7.0 provisioner: name: chef_zero diff --git a/attributes/agent.rb b/attributes/agent.rb index 2dfb437..b764e19 100644 --- a/attributes/agent.rb +++ b/attributes/agent.rb @@ -23,7 +23,6 @@ case node['platform_family'] when 'rhel', 'debian' - default['zabbix']['agent']['init_style'] = 'sysvinit' default['zabbix']['agent']['install_method'] = 'prebuild' default['zabbix']['agent']['pid_file'] = ::File.join(node['zabbix']['run_dir'], 'zabbix_agentd.pid') @@ -32,7 +31,6 @@ default['zabbix']['agent']['shell'] = node['zabbix']['shell'] when 'windows' - default['zabbix']['agent']['init_style'] = 'windows' default['zabbix']['agent']['install_method'] = 'chocolatey' end diff --git a/recipes/_agent_common_service.rb b/recipes/_agent_common_service.rb index d6e6160..ca7f9ae 100644 --- a/recipes/_agent_common_service.rb +++ b/recipes/_agent_common_service.rb @@ -1,6 +1,26 @@ # Manage Agent service -case node['zabbix']['agent']['init_style'] -when 'sysvinit' +if platform_family?('windows') + service 'zabbix_agentd' do + service_name 'Zabbix Agent' + provider Chef::Provider::Service::Windows + supports :restart => true + action :nothing + end +elsif node['init_package'] == 'systemd' + template '/lib/systemd/system/zabbix-agent.service' do + source 'zabbix-agent.service.erb' + owner 'root' + group 'root' + mode '0644' + end + + # RHEL package names it "zabbix-agent" + service 'zabbix_agentd' do + service_name 'zabbix-agent' + supports :status => true, :start => true, :stop => true, :restart => true + action :nothing + end +else template '/etc/init.d/zabbix_agentd' do source value_for_platform_family(['rhel'] => 'zabbix_agentd.init-rh.erb', 'default' => 'zabbix_agentd.init.erb') owner 'root' @@ -13,11 +33,4 @@ supports :status => true, :start => true, :stop => true, :restart => true action :nothing end -when 'windows' - service 'zabbix_agentd' do - service_name 'Zabbix Agent' - provider Chef::Provider::Service::Windows - supports :restart => true - action :nothing - end end diff --git a/templates/default/zabbix-agent.service.erb b/templates/default/zabbix-agent.service.erb new file mode 100644 index 0000000..a4567be --- /dev/null +++ b/templates/default/zabbix-agent.service.erb @@ -0,0 +1,13 @@ +[Unit] +Description=Zabbix Monitor Agent +After=syslog.target network.target + +[Service] +Type=forking +ExecStart=<%= node['zabbix']['install_dir'] %>/sbin/zabbix_agentd -c <%= node['zabbix']['agent']['config_file'] %> +User=<%= node['zabbix']['agent']['user'] %> +Group=<%= node['zabbix']['agent']['group'] %> +PIDFile=<%= node['zabbix']['agent']['pid_file'] %> + +[Install] +WantedBy=multi-user.target From bdba9e82b88c40a1f07242bddc65a784ad7071fd Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 19 Dec 2014 11:55:18 +0000 Subject: [PATCH 2/3] redhat-lsb is not needed for the agent systemd script This package pulls in everything and the kitchen sink and you really don't want it on your server if you can avoid it. The RedHat SysVinit script should also be rewritten to use the RedHat functions instead of the LSB ones like the EPEL package does but I lack the time. --- README.md | 5 ----- recipes/_agent_common_service.rb | 2 ++ recipes/agent_prebuild.rb | 3 --- recipes/agent_source.rb | 2 +- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0d8e3e3..7a5404b 100644 --- a/README.md +++ b/README.md @@ -116,11 +116,6 @@ You can control the agent install with the following attributes: Downloads and installs the Zabbix agent from a pre built package -If you are on a machine in the RHEL family of platforms, then you must have your -package manager setup to allow installation of: - - package "redhat-lsb" - You can control the agent version with: node['zabbix']['agent']['version'] diff --git a/recipes/_agent_common_service.rb b/recipes/_agent_common_service.rb index ca7f9ae..0eb2147 100644 --- a/recipes/_agent_common_service.rb +++ b/recipes/_agent_common_service.rb @@ -21,6 +21,8 @@ action :nothing end else + package 'redhat-lsb' if platform_family?('rhel') + template '/etc/init.d/zabbix_agentd' do source value_for_platform_family(['rhel'] => 'zabbix_agentd.init-rh.erb', 'default' => 'zabbix_agentd.init.erb') owner 'root' diff --git a/recipes/agent_prebuild.rb b/recipes/agent_prebuild.rb index cba2d24..a812e2d 100644 --- a/recipes/agent_prebuild.rb +++ b/recipes/agent_prebuild.rb @@ -9,9 +9,6 @@ include_recipe 'zabbix::agent_common' -# Install prerequisite RPM -package 'redhat-lsb' if node['platform_family'] == 'rhel' - ark 'zabbix_agent' do name 'zabbix' url node['zabbix']['agent']['prebuild']['url'] diff --git a/recipes/agent_source.rb b/recipes/agent_source.rb index 4030ab5..88ae5d8 100644 --- a/recipes/agent_source.rb +++ b/recipes/agent_source.rb @@ -19,7 +19,7 @@ end when 'redhat', 'centos', 'scientific', 'amazon' - %w(fping curl-devel iksemel-devel iksemel-utils net-snmp-libs net-snmp-devel openssl-devel redhat-lsb).each do |pck| + %w(fping curl-devel iksemel-devel iksemel-utils net-snmp-libs net-snmp-devel openssl-devel).each do |pck| package pck do action :install end From 20e3f09277eff338f1c622b3e3c0f9e7693296ce Mon Sep 17 00:00:00 2001 From: Cesare Bellini Date: Wed, 25 Feb 2015 17:45:21 +0000 Subject: [PATCH 3/3] Added template for systemd-tmpfiles --- recipes/common.rb | 10 ++++++++++ templates/default/tmpfiles.conf.erb | 1 + 2 files changed, 11 insertions(+) create mode 100644 templates/default/tmpfiles.conf.erb diff --git a/recipes/common.rb b/recipes/common.rb index 79e0fe1..c70bd82 100644 --- a/recipes/common.rb +++ b/recipes/common.rb @@ -52,6 +52,16 @@ end end +if node['init_package'] == 'systemd' + template "/usr/lib/tmpfiles.d/zabbix.conf" do + source 'tmpfiles.conf.erb' + owner 'root' + group 'root' + mode '644' + action :create + end +end + unless node['zabbix']['agent']['source_url'] node.default['zabbix']['agent']['source_url'] = Chef::Zabbix.default_download_url(node['zabbix']['agent']['branch'], node['zabbix']['agent']['version']) end diff --git a/templates/default/tmpfiles.conf.erb b/templates/default/tmpfiles.conf.erb new file mode 100644 index 0000000..56d1d9c --- /dev/null +++ b/templates/default/tmpfiles.conf.erb @@ -0,0 +1 @@ +d <%= node['zabbix']['run_dir'] %> 755 <%= node['zabbix']['login'] %> <%= node['zabbix']['group'] %>