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 (experimental) support for systemd as an init_style #38

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 37 additions & 4 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ suites:
run_list:
- recipe[java::default]
- recipe[kafka::default]
excludes:
- centos-6.5
- debian-7.4
- fedora-20
includes:
- ubuntu-14.04
attributes:
kafka:
init_style: 'upstart'
Expand All @@ -65,6 +63,23 @@ suites:
zookeeper:
connect: ['localhost:2181']
connection_timeout_ms: 15_000
- name: init-style-systemd
run_list:
- recipe[java::default]
- recipe[kafka::default]
includes:
- fedora-20
attributes:
kafka:
init_style: 'systemd'
version: <%= ENV.fetch('KAFKA_VERSION', '0.8.1.1') %>
checksum: <%= ENV.fetch('KAFKA_CHECKSUM', '""') %>
md5_checksum: <%= ENV.fetch('KAFKA_MD5', '""') %>
log:
dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
zookeeper:
connect: ['localhost:2181']
connection_timeout_ms: 15_000
- name: source-init-style-upstart
run_list:
- recipe[java::default]
Expand Down Expand Up @@ -100,3 +115,21 @@ suites:
zookeeper:
connect: ['localhost:2181']
connection_timeout_ms: 15_000
- name: source-init-style-systemd
run_list:
- recipe[java::default]
- recipe[kafka::default]
includes:
- fedora-20
attributes:
kafka:
install_method: 'source'
init_style: 'systemd'
version: <%= ENV.fetch('KAFKA_VERSION', '0.8.1.1') %>
checksum: <%= ENV.fetch('KAFKA_CHECKSUM', '""') %>
md5_checksum: <%= ENV.fetch('KAFKA_MD5', '""') %>
log:
dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
zookeeper:
connect: ['localhost:2181']
connection_timeout_ms: 15_000
9 changes: 9 additions & 0 deletions libraries/kafka_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def kafka_init_opts
opts[:script_path] = '/etc/init/kafka.conf'
opts[:provider] = ::Chef::Provider::Service::Upstart
opts[:permissions] = '644'
when :systemd
opts[:env_path] = '/etc/sysconfig/kafka'
opts[:env_template] = 'systemd/kafka.env.erb'
opts[:source] = value_for_platform_family({
'default' => 'systemd/default.erb'
})
opts[:script_path] = '/etc/systemd/system/kafka.service'
opts[:provider] = ::Chef::Provider::Service::Systemd
opts[:permissions] = '644'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion recipes/_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
end

template kafka_init_opts[:env_path] do
source 'env.erb'
source kafka_init_opts.fetch(:env_template, 'env.erb')
owner 'root'
group 'root'
mode '644'
Expand Down
40 changes: 32 additions & 8 deletions spec/recipes/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@

it 'configures loggers' do
expect(chef_run).to have_configured(path).with('log4j.logger.org.IOItec.zkclient.ZkClient').as('INFO')
expect(chef_run).to have_configured(path).with('log4j.logger.kafka.network.RequestChannel$').as('WARN, requestAppender')
expect(chef_run).to have_configured(path).with('log4j.logger.kafka.network.RequestChannel\$').as('WARN, requestAppender')
expect(chef_run).to have_configured(path).with('log4j.logger.kafka.request.logger').as('WARN, requestAppender')
expect(chef_run).to have_configured(path).with('log4j.logger.kafka.controller').as('INFO, controllerAppender')
expect(chef_run).to have_configured(path).with('log4j.logger.state.change.logger').as('INFO, stateChangeAppender')
Expand Down Expand Up @@ -1052,31 +1052,31 @@
end

it 'sets SCALA_VERSION' do
expect(chef_run).to have_configured(env_path).with('export SCALA_VERSION').as('"2.8.0"')
expect(chef_run).to have_configured(env_path).with('(export |)SCALA_VERSION').as('"2.8.0"')
end

it 'sets JMX_PORT' do
expect(chef_run).to have_configured(env_path).with('export JMX_PORT').as('"9999"')
expect(chef_run).to have_configured(env_path).with('(export |)JMX_PORT').as('"9999"')
end

it 'sets KAFKA_LOG4J_OPTS' do
expect(chef_run).to have_configured(env_path).with('export KAFKA_LOG4J_OPTS').as('"-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"')
expect(chef_run).to have_configured(env_path).with('(export |)KAFKA_LOG4J_OPTS').as('"-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"')
end

it 'sets KAFKA_HEAP_OPTS' do
expect(chef_run).to have_configured(env_path).with('export KAFKA_HEAP_OPTS').as('"-Xmx1G -Xms1G"')
expect(chef_run).to have_configured(env_path).with('(export |)KAFKA_HEAP_OPTS').as('"-Xmx1G -Xms1G"')
end

it 'sets KAFKA_GC_LOG_OPTS' do
expect(chef_run).to have_configured(env_path).with('export KAFKA_GC_LOG_OPTS').as('"-Xloggc:/var/log/kafka/kafka-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"')
expect(chef_run).to have_configured(env_path).with('(export |)KAFKA_GC_LOG_OPTS').as('"-Xloggc:/var/log/kafka/kafka-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"')
end

it 'sets KAFKA_OPTS' do
expect(chef_run).to have_configured(env_path).with('export KAFKA_OPTS').as('""')
expect(chef_run).to have_configured(env_path).with('(export |)KAFKA_OPTS').as('""')
end

it 'sets KAFKA_JVM_PERFORMANCE_OPTS' do
expect(chef_run).to have_configured(env_path).with('export KAFKA_JVM_PERFORMANCE_OPTS').as('"-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true"')
expect(chef_run).to have_configured(env_path).with('(export |)KAFKA_JVM_PERFORMANCE_OPTS').as('"-server -XX:+UseCompressedOops -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true"')
end

it 'sets KAFKA_RUN' do
Expand Down Expand Up @@ -1185,6 +1185,30 @@
end
end
end

context 'when init_style is :systemd' do
it_behaves_like 'an init style' do
let :init_style do
'systemd'
end

let :init_path do
'/etc/systemd/system/kafka.service'
end

let :env_path do
'/etc/sysconfig/kafka'
end

let :script_permissions do
'644'
end

let :source_template do
'systemd/default.erb'
end
end
end
end

context 'kafka service' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec::Matchers.define :have_configured do |configuration_file|
match do |chef_run|
regexp_str = %(^#{Regexp.quote(@attribute)})
regexp_str = %(^#{@attribute})
regexp_str << %(=#{Regexp.quote(@value)}$) if @value
regexp = Regexp.new(regexp_str)
@matcher = ChefSpec::Matchers::RenderFileMatcher.new(configuration_file)
Expand Down
8 changes: 8 additions & 0 deletions templates/default/systemd/default.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=<%= @daemon_name %> daemon

[Service]
User=<%= @user %>
EnvironmentFile=/etc/sysconfig/<%= @daemon_name %>
ExecStart=/bin/bash $KAFKA_RUN $KAFKA_ARGS $KAFKA_CONFIG
TimeoutSec=10
12 changes: 12 additions & 0 deletions templates/default/systemd/kafka.env.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SCALA_VERSION="<%= node[:kafka][:scala_version] %>"
JMX_PORT="<%= @jmx_port %>"

KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:<%= node[:kafka][:config_dir] %>/<%= @log4j_config %>"
KAFKA_HEAP_OPTS="<%= node[:kafka][:heap_opts] %>"
KAFKA_GC_LOG_OPTS="-Xloggc:<%= node[:kafka][:log_dir] %>/kafka-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"
KAFKA_OPTS="<%= node[:kafka][:generic_opts] %>"
KAFKA_JVM_PERFORMANCE_OPTS="<%= node[:kafka][:jvm_performance_opts] %>"

KAFKA_RUN="<%= node[:kafka][:install_dir] %>/bin/kafka-run-class.sh"
KAFKA_ARGS="<%= @main_class %>"
KAFKA_CONFIG="<%= node[:kafka][:config_dir] %>/<%= @config %>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# encoding: utf-8

require 'spec_helper'
require 'support/install_common'

describe 'kafka::binary' do
it_behaves_like 'an install method'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# encoding: utf-8

require 'spec_helper'

describe 'required files for upstart init style' do
describe 'environment file' do
let :env_file do
file '/etc/sysconfig/kafka'
end

it 'exists' do
expect(env_file).to be_a_file
end

it 'is owned by root' do
expect(env_file).to be_owned_by 'root'
end

it 'belongs to the root group' do
expect(env_file).to be_grouped_into 'root'
end

it 'has 644 permissions' do
expect(env_file).to be_mode 644
end
end

describe 'init configuration' do
let :init_file do
file '/etc/systemd/system/kafka.service'
end

it 'exists' do
expect(init_file).to be_a_file
end

it 'is owned by root' do
expect(init_file).to be_owned_by 'root'
end

it 'belongs to the root group' do
expect(init_file).to be_grouped_into 'root'
end

it 'has 644 permissions' do
expect(init_file).to be_mode 644
end
end
end
Loading