diff --git a/REFERENCE.md b/REFERENCE.md index 49ed9a5d..f99d9cd7 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -503,7 +503,7 @@ Default value: `'kafka'` Data type: `Boolean` -Install the init.d or systemd service. +Install the systemd service. Default value: `$kafka::params::manage_service` @@ -872,7 +872,7 @@ Default value: `'kafka-consumer'` Data type: `Boolean` -Install the init.d or systemd service. +Install the systemd service. Default value: `$kafka::params::manage_service` @@ -1208,7 +1208,7 @@ Default value: `'kafka-mirror'` Data type: `Boolean` -Install the init.d or systemd service. +Install the systemd service. Default value: `$kafka::params::manage_service` @@ -1560,7 +1560,7 @@ Default value: `'kafka-producer'` Data type: `Boolean` -Install the init.d or systemd service. +Install systemd service. Default value: `$kafka::params::manage_service` diff --git a/manifests/broker.pp b/manifests/broker.pp index 65249f54..ffaa2ac3 100644 --- a/manifests/broker.pp +++ b/manifests/broker.pp @@ -70,7 +70,7 @@ # Set the name of the service. # # @param manage_service -# Install the init.d or systemd service. +# Install the systemd service. # # @param service_ensure # Set the ensure state of the service. diff --git a/manifests/broker/service.pp b/manifests/broker/service.pp index 36e6abc6..5879b72a 100644 --- a/manifests/broker/service.pp +++ b/manifests/broker/service.pp @@ -36,31 +36,14 @@ } $environment = deep_merge($env_defaults, $env) - if $facts['service_provider'] == 'systemd' { - include systemd + include systemd - file { "/etc/systemd/system/${service_name}.service": - ensure => file, - mode => '0644', - content => template('kafka/unit.erb'), - } - - file { "/etc/init.d/${service_name}": - ensure => absent, - } - - File["/etc/systemd/system/${service_name}.service"] - ~> Service[$service_name] - } else { - file { "/etc/init.d/${service_name}": - ensure => file, - mode => '0755', - content => template('kafka/init.erb'), - before => Service[$service_name], - } + file { "/etc/systemd/system/${service_name}.service": + ensure => file, + mode => '0644', + content => template('kafka/unit.erb'), } - - service { $service_name: + ~> service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, diff --git a/manifests/consumer.pp b/manifests/consumer.pp index 530ec09d..40ea6a5d 100644 --- a/manifests/consumer.pp +++ b/manifests/consumer.pp @@ -70,7 +70,7 @@ # Set the name of the service. # # @param manage_service -# Install the init.d or systemd service. +# Install the systemd service. # # @param service_ensure # Set the ensure state of the service. diff --git a/manifests/consumer/service.pp b/manifests/consumer/service.pp index a225856c..dc454117 100644 --- a/manifests/consumer/service.pp +++ b/manifests/consumer/service.pp @@ -36,31 +36,14 @@ } $environment = deep_merge($env_defaults, $env) - if $facts['service_provider'] == 'systemd' { - include systemd + include systemd - file { "/etc/systemd/system/${service_name}.service": - ensure => file, - mode => '0644', - content => template('kafka/unit.erb'), - } - - file { "/etc/init.d/${service_name}": - ensure => absent, - } - - File["/etc/systemd/system/${service_name}.service"] - ~> Service[$service_name] - } else { - file { "/etc/init.d/${service_name}": - ensure => file, - mode => '0755', - content => template('kafka/init.erb'), - before => Service[$service_name], - } + file { "/etc/systemd/system/${service_name}.service": + ensure => file, + mode => '0644', + content => template('kafka/unit.erb'), } - - service { $service_name: + ~> service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, diff --git a/manifests/mirror.pp b/manifests/mirror.pp index 4e7baa4f..2a115141 100644 --- a/manifests/mirror.pp +++ b/manifests/mirror.pp @@ -76,7 +76,7 @@ # Set the name of the service. # # @param manage_service -# Install the init.d or systemd service. +# Install the systemd service. # # @param service_ensure # Set the ensure state of the service. diff --git a/manifests/mirror/service.pp b/manifests/mirror/service.pp index 39c1c019..87e59bfe 100644 --- a/manifests/mirror/service.pp +++ b/manifests/mirror/service.pp @@ -33,31 +33,14 @@ } $environment = deep_merge($env_defaults, $env) - if $facts['service_provider'] == 'systemd' { - include systemd + include systemd - file { "/etc/systemd/system/${service_name}.service": - ensure => file, - mode => '0644', - content => template('kafka/unit.erb'), - } - - file { "/etc/init.d/${service_name}": - ensure => absent, - } - - File["/etc/systemd/system/${service_name}.service"] - ~> Service[$service_name] - } else { - file { "/etc/init.d/${service_name}": - ensure => file, - mode => '0755', - content => template('kafka/init.erb'), - before => Service[$service_name], - } + file { "/etc/systemd/system/${service_name}.service": + ensure => file, + mode => '0644', + content => template('kafka/unit.erb'), } - - service { $service_name: + ~> service { $service_name: ensure => $service_ensure, enable => true, hasstatus => true, diff --git a/manifests/producer.pp b/manifests/producer.pp index 45f7561c..1e96478c 100644 --- a/manifests/producer.pp +++ b/manifests/producer.pp @@ -73,7 +73,7 @@ # Set the name of the service. # # @param manage_service -# Install the init.d or systemd service. +# Install systemd service. # # @param service_ensure # Set the ensure state of the service. diff --git a/manifests/producer/service.pp b/manifests/producer/service.pp index 89f44c9a..a5ad30b4 100644 --- a/manifests/producer/service.pp +++ b/manifests/producer/service.pp @@ -37,16 +37,7 @@ } $environment = deep_merge($env_defaults, $env) - if $facts['service_provider'] == 'systemd' { - fail('Console Producer is not supported on systemd, because the stdin of the process cannot be redirected') - } else { - file { "/etc/init.d/${service_name}": - ensure => file, - mode => '0755', - content => template('kafka/init.erb'), - before => Service[$service_name], - } - } + fail('Console Producer is not supported on systemd, because the stdin of the process cannot be redirected') service { $service_name: ensure => $service_ensure, diff --git a/spec/acceptance/broker_spec.rb b/spec/acceptance/broker_spec.rb index e41311b5..6275827d 100644 --- a/spec/acceptance/broker_spec.rb +++ b/spec/acceptance/broker_spec.rb @@ -162,7 +162,7 @@ class { 'kafka::broker': apply_manifest(pp, catch_failures: true) end - describe file('/etc/systemd/system/kafka.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do + describe file('/etc/systemd/system/kafka.service') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } @@ -197,17 +197,7 @@ class { 'kafka::broker': apply_manifest(pp, catch_changes: true) end - describe file('/etc/init.d/kafka'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain %r{^# Provides:\s+kafka$} } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote"' } - it { is_expected.to contain 'export KAFKA_HEAP_OPTS="-Xmx512M -Xmx512M"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/tmp/log4j.properties"' } - end - - describe file('/etc/systemd/system/kafka.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do + describe file('/etc/systemd/system/kafka.service') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } diff --git a/spec/acceptance/consumer_spec.rb b/spec/acceptance/consumer_spec.rb index c0950f34..490c896c 100644 --- a/spec/acceptance/consumer_spec.rb +++ b/spec/acceptance/consumer_spec.rb @@ -140,16 +140,7 @@ class { 'kafka::consumer': apply_manifest(pp, catch_failures: true) end - describe file('/etc/init.d/kafka-consumer'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain %r{^# Provides:\s+kafka-consumer$} } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9993"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } - end - - describe file('/etc/systemd/system/kafka-consumer.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do + describe file('/etc/systemd/system/kafka-consumer.service') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } diff --git a/spec/acceptance/mirror_spec.rb b/spec/acceptance/mirror_spec.rb index 4a4b3251..20848fd8 100644 --- a/spec/acceptance/mirror_spec.rb +++ b/spec/acceptance/mirror_spec.rb @@ -220,16 +220,7 @@ class { 'kafka::mirror': apply_manifest(pp, catch_changes: true) end - describe file('/etc/init.d/kafka-mirror'), if: (fact('service_provider') == 'upstart' && fact('osfamily') == 'Debian') do - it { is_expected.to be_file } - it { is_expected.to be_owned_by 'root' } - it { is_expected.to be_grouped_into 'root' } - it { is_expected.to contain %r{^# Provides:\s+kafka-mirror$} } - it { is_expected.to contain 'export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=9991"' } - it { is_expected.to contain 'export KAFKA_LOG4J_OPTS="-Dlog4j.configuration=file:/opt/kafka/config/log4j.properties"' } - end - - describe file('/etc/systemd/system/kafka-mirror.service'), if: (fact('operatingsystemmajrelease') == '7' && fact('osfamily') == 'RedHat') do + describe file('/etc/systemd/system/kafka-mirror.service') do it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } it { is_expected.to be_grouped_into 'root' } diff --git a/spec/classes/broker_spec.rb b/spec/classes/broker_spec.rb index f0e2ddfb..311fce07 100644 --- a/spec/classes/broker_spec.rb +++ b/spec/classes/broker_spec.rb @@ -58,41 +58,26 @@ context 'manage_service false' do let(:params) { super().merge(manage_service: false) } - it { is_expected.not_to contain_file('/etc/init.d/kafka') } it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service') } it { is_expected.not_to contain_service('kafka') } end context 'defaults' do - if os_facts['service_provider'] == 'systemd' - it { is_expected.to contain_file('/etc/init.d/kafka').with_ensure('absent') } - it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=} } - it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=} } - else - it { is_expected.to contain_file('/etc/init.d/kafka') } - end - + it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=} } + it { is_expected.not_to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=} } it { is_expected.to contain_service('kafka') } end context 'limit_nofile set' do let(:params) { super().merge(limit_nofile: '65536') } - if os_facts['service_provider'] == 'systemd' - it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=65536$} } - else - it { is_expected.to contain_file('/etc/init.d/kafka').with_content %r{ulimit -n 65536$} } - end + it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitNOFILE=65536$} } end context 'limit_core set' do let(:params) { super().merge(limit_core: 'infinity') } - if os_facts['service_provider'] == 'systemd' - it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=infinity$} } - else - it { is_expected.to contain_file('/etc/init.d/kafka').with_content %r{ulimit -c infinity$} } - end + it { is_expected.to contain_file('/etc/systemd/system/kafka.service').with_content %r{^LimitCORE=infinity$} } end context 'service_requires set', if: os_facts['service_provider'] == 'systemd' do diff --git a/spec/classes/consumer_spec.rb b/spec/classes/consumer_spec.rb index 2ee6959f..a602de37 100644 --- a/spec/classes/consumer_spec.rb +++ b/spec/classes/consumer_spec.rb @@ -51,12 +51,7 @@ describe 'kafka::consumer::service' do context 'defaults' do - if os_facts['service_provider'] == 'systemd' - it { is_expected.to contain_file('/etc/systemd/system/kafka-consumer.service') } - else - it { is_expected.to contain_file('/etc/init.d/kafka-consumer') } - end - + it { is_expected.to contain_file('/etc/systemd/system/kafka-consumer.service') } it { is_expected.to contain_service('kafka-consumer') } end end diff --git a/spec/classes/mirror_spec.rb b/spec/classes/mirror_spec.rb index 92794be1..4ddd0de5 100644 --- a/spec/classes/mirror_spec.rb +++ b/spec/classes/mirror_spec.rb @@ -48,14 +48,7 @@ describe 'kafka::mirror::service' do context 'defaults' do - if os_facts['service_provider'] == 'systemd' - it { is_expected.to contain_file('/etc/init.d/kafka-mirror').with_ensure('absent') } - it { is_expected.to contain_file('/etc/systemd/system/kafka-mirror.service').with_content %r{/opt/kafka/config/(?=.*consumer)|(?=.*producer).propertie} } - else - it { is_expected.to contain_file('/etc/init.d/kafka-mirror') } - it { is_expected.to contain_file('/etc/init.d/kafka-mirror').with_content %r{/opt/kafka/config/(?=.*consumer)|(?=.*producer).properties} } - end - + it { is_expected.to contain_file('/etc/systemd/system/kafka-mirror.service').with_content %r{/opt/kafka/config/(?=.*consumer)|(?=.*producer).propertie} } it { is_expected.to contain_service('kafka-mirror') } end end diff --git a/spec/classes/producer_spec.rb b/spec/classes/producer_spec.rb index 950ce791..4f204f81 100644 --- a/spec/classes/producer_spec.rb +++ b/spec/classes/producer_spec.rb @@ -20,35 +20,7 @@ } end - if os_facts['service_provider'] == 'systemd' - it { is_expected.to compile.and_raise_error(%r{Console Producer is not supported on systemd, because the stdin of the process cannot be redirected}) } - else - it { is_expected.to contain_class('kafka::producer::install').that_comes_before('Class[kafka::producer::config]') } - it { is_expected.to contain_class('kafka::producer::config').that_comes_before('Class[kafka::producer::service]') } - it { is_expected.to contain_class('kafka::producer::service').that_comes_before('Class[kafka::producer]') } - it { is_expected.to contain_class('kafka::producer') } - - describe 'kafka::producer::install' do - context 'defaults' do - it { is_expected.to contain_class('kafka') } - end - end - - describe 'kafka::producer::config' do - context 'defaults' do - it { is_expected.to contain_file('/opt/kafka/config/producer.properties') } - end - end - - describe 'kafka::producer::service' do - context 'defaults' do - it { is_expected.to contain_file('/etc/init.d/kafka-producer') } - it { is_expected.to contain_service('kafka-producer') } - end - end - - it_validates_parameter 'mirror_url' - end + it { is_expected.to compile.and_raise_error(%r{Console Producer is not supported on systemd, because the stdin of the process cannot be redirected}) } end end end diff --git a/templates/init.erb b/templates/init.erb deleted file mode 100644 index 3cdd4314..00000000 --- a/templates/init.erb +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/sh -# -# Init file for Apache Kafka <%= @service_name.split(/-/)[1] and @service_name.split(/-/)[1].capitalize %> -# -<%- if @osfamily == 'Debian' -%> -### BEGIN INIT INFO -# Provides: <%= @service_name %> -# Required-Start: <%= @service_requires.join(' ') %> -# Required-Stop: -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# X-Interactive: true -# Short-Description: Apache Kafka is a distributed publish-subscribe messaging system -### END INIT INFO -<%- else -%> -# chkconfig: 35 85 15 -# description: Apache Kafka is a distributed publish-subscribe messaging system -# pidfile: /var/run/<%= @service_name -%>.pid -<%- end -%> - -NAME=<%= @service_name %> -<% @environment.sort.map do |k,v| -%> -<% unless v.to_s.strip.empty? -%> -export <%= k %>="<%= v %>" -<% end -%> -<% end -%> -PID_FILE="/var/run/$NAME.pid" -KAFKA_USER=<%= @user_name %> -<%- case @service_name when 'kafka' -%> -PGREP_PATTERN=kafka.Kafka -DAEMON="<%= @bin_dir %>/kafka-server-start.sh" -DAEMON_OPTS="<%= @config_dir %>/server.properties" -<%- when 'kafka-consumer' -%> -PGREP_PATTERN=kafka.tools.ConsoleConsumer -DAEMON="<%= @bin_dir %>/kafka-console-consumer.sh" -DAEMON_OPTS="<% @service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%> '<%= v.is_a?(Array) ? v.join(',') : v %>' <% end -%><% end -%>" -<%- when 'kafka-mirror' -%> -PGREP_PATTERN=kafka.tools.MirrorMaker -DAEMON="<%= @bin_dir %>/kafka-run-class.sh" -DAEMON_OPTS="kafka.tools.MirrorMaker --consumer.config <%= @config_dir %>/consumer.properties --producer.config <%= @config_dir %>/producer.properties <% @service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%> '<%= v.is_a?(Array) ? v.join(',') : v %>' <% end -%><% end -%>" -<%- when 'kafka-producer' -%> -PGREP_PATTERN=kafka.tools.ConsoleProducer -DAEMON="<%= @bin_dir %>/kafka-console-producer.sh" -DAEMON_OPTS="<% @service_config.sort.each do |k,v| -%><% unless v.to_s.strip.empty? -%>--<%= k -%> '<%= v.is_a?(Array) ? v.join(',') : v %>' <% end -%><% end -%>" -PRODUCER_INPUT="<%= @input %>" -<%- end -%> - -if [ -f /etc/default/kafka ]; then - . /etc/default/kafka -fi - -start() { - - <% if @limit_nofile -%> - ulimit -n <%= @limit_nofile %> - <% end -%> - - <% if @limit_core -%> - ulimit -c <%= @limit_core %> - <% end -%> - - ulimit -s 10240 - - if [ -f "$PID_FILE" ]; then - PID=`cat "$PID_FILE"` - if [ `ps -p "$PID" -o pid= || echo 1` -eq `ps ax | grep -i "$PGREP_PATTERN" | grep -v grep | awk '{print $1}' || echo 2` ] ; then - echo "$PID_FILE exists, process is already running" - exit 0 - fi - echo "$PID_FILE exists but the process is not running. Deleting $PID_FILE and re-trying" - rm -f -- "$PID_FILE" - start - return $? - fi - - /bin/su "$KAFKA_USER" -c "KAFKA_JMX_OPTS=\"$KAFKA_JMX_OPTS\" $DAEMON $DAEMON_OPTS<%- if @service_name == 'kafka-producer' -%> $PRODUCER_INPUT<%- end -%> >/dev/null 2>&1 &" - sleep 2 - PID=`ps ax | grep -i "$PGREP_PATTERN" | grep -v grep | awk '{print $1}'` - if [ -z "$PID" ]; then - echo "$NAME could not be started" - exit 1 - fi - - echo "$PID" > "$PID_FILE"; - echo "$NAME started" - return 0 -} - -stop() { - if ! [ -f "$PID_FILE" ]; then - echo -n "$PID_FILE does not exist" - if PID=`ps ax | grep -i "$PGREP_PATTERN" | grep -v grep | awk '{print $1}'` ; then - echo -n ", but process is running" - echo "$PID" > "$PID_FILE" - else - echo -n ", and process is not running" - return 1 - fi - fi - - PID=`cat $PID_FILE` - kill $PID; - rm -f -- "$PID_FILE"; - - # wait until the process is finished - RETRIES=0 - MAX_RETRIES=10 - while [ ! -z `ps ax | grep -i "$PGREP_PATTERN" | grep -v grep | awk '{print $1}'` ]; do - sleep 1 - RETRIES=$((RETRIES+1)) - if [ "$RETRIES" -ge "$MAX_RETRIES" ]; then - echo "$NAME service: stop tried $MAX_RETRIES times but process $PID is still running" - return 1 - fi - done - - echo "$NAME stopped" - return 0 -} - -status() { - if ! [ -f "$PID_FILE" ]; then - echo "$NAME stopped" - exit 1 - fi - - PID=`cat "$PID_FILE"` - if ! [ `ps -p "$PID" -o pid= || echo 1` -eq `ps ax | grep -i "$PGREP_PATTERN" | grep -v grep | awk '{print $1}' || echo 2` ] ; then - echo "$NAME stopped but pid file exists" - exit 1 - fi - - echo "$NAME running with pid $PID" - exit 0 -} - -case "$1" in - status) - status - ;; - start) - echo "Starting daemon: $NAME" - start - ;; - stop) - echo "Stopping daemon: $NAME" - stop - ;; - restart) - echo "Restarting daemon: $NAME" - stop - sleep 2 - start - ;; - - *) - echo "Usage: "$1" {status|start|stop|restart}" - exit 1 -esac - -exit 0