Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agent systemd support #195

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 0 additions & 2 deletions attributes/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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

Expand Down
33 changes: 24 additions & 9 deletions recipes/_agent_common_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# 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
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'
Expand All @@ -13,11 +35,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
3 changes: 0 additions & 3 deletions recipes/agent_prebuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion recipes/agent_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions recipes/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions templates/default/tmpfiles.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d <%= node['zabbix']['run_dir'] %> 755 <%= node['zabbix']['login'] %> <%= node['zabbix']['group'] %>
13 changes: 13 additions & 0 deletions templates/default/zabbix-agent.service.erb
Original file line number Diff line number Diff line change
@@ -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