From 50d66f54cb2ff3c1b14b3e4626379009c4f9ba22 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 10:01:01 +0100 Subject: [PATCH 1/7] remove unused doctag variables --- manifests/broker/config.pp | 1 - manifests/consumer/config.pp | 1 - manifests/producer/config.pp | 1 - 3 files changed, 3 deletions(-) diff --git a/manifests/broker/config.pp b/manifests/broker/config.pp index 1e207aa0..ad5e7d29 100644 --- a/manifests/broker/config.pp +++ b/manifests/broker/config.pp @@ -24,7 +24,6 @@ $config_notify = undef } - $doctag = 'brokerconfigs' file { "${config_dir}/server.properties": ensure => file, owner => $user_name, diff --git a/manifests/consumer/config.pp b/manifests/consumer/config.pp index ec11ac16..21c8f058 100644 --- a/manifests/consumer/config.pp +++ b/manifests/consumer/config.pp @@ -20,7 +20,6 @@ $config_notify = undef } - $doctag = 'consumerconfigs' file { "${config_dir}/consumer.properties": ensure => file, owner => $user_name, diff --git a/manifests/producer/config.pp b/manifests/producer/config.pp index a4113c84..66269f70 100644 --- a/manifests/producer/config.pp +++ b/manifests/producer/config.pp @@ -17,7 +17,6 @@ $config_notify = undef } - $doctag = 'producerconfigs' file { "${config_dir}/producer.properties": ensure => file, owner => $user_name, From 84081ed4c78e5a2a9337681a097368019a18df02 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 10:09:24 +0100 Subject: [PATCH 2/7] remove non systemd code --- manifests/broker/service.pp | 29 ++++++----------------------- manifests/consumer/service.pp | 29 ++++++----------------------- manifests/mirror/service.pp | 29 ++++++----------------------- manifests/producer/service.pp | 11 +---------- 4 files changed, 19 insertions(+), 79 deletions(-) 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/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/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/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, From d9c9a2f0395d4f598d393d2a0ecf1e88150b0771 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 10:14:40 +0100 Subject: [PATCH 3/7] remove non systemd tests --- manifests/broker.pp | 2 +- manifests/consumer.pp | 2 +- manifests/mirror.pp | 2 +- manifests/producer.pp | 2 +- spec/acceptance/broker_spec.rb | 10 ---------- spec/acceptance/consumer_spec.rb | 9 --------- spec/acceptance/mirror_spec.rb | 9 --------- spec/classes/broker_spec.rb | 23 ++++------------------- spec/classes/consumer_spec.rb | 7 +------ spec/classes/mirror_spec.rb | 9 +-------- spec/classes/producer_spec.rb | 30 +----------------------------- 11 files changed, 11 insertions(+), 94 deletions(-) diff --git a/manifests/broker.pp b/manifests/broker.pp index fa321583..46913c10 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/consumer.pp b/manifests/consumer.pp index d94bffbd..f12593d0 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/mirror.pp b/manifests/mirror.pp index f0493b38..b58ab0b2 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/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/spec/acceptance/broker_spec.rb b/spec/acceptance/broker_spec.rb index e41311b5..3b96f4b0 100644 --- a/spec/acceptance/broker_spec.rb +++ b/spec/acceptance/broker_spec.rb @@ -197,16 +197,6 @@ 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 it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } diff --git a/spec/acceptance/consumer_spec.rb b/spec/acceptance/consumer_spec.rb index c0950f34..aba081f0 100644 --- a/spec/acceptance/consumer_spec.rb +++ b/spec/acceptance/consumer_spec.rb @@ -140,15 +140,6 @@ 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 it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } diff --git a/spec/acceptance/mirror_spec.rb b/spec/acceptance/mirror_spec.rb index 4a4b3251..0b40ae27 100644 --- a/spec/acceptance/mirror_spec.rb +++ b/spec/acceptance/mirror_spec.rb @@ -220,15 +220,6 @@ 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 it { is_expected.to be_file } it { is_expected.to be_owned_by 'root' } diff --git a/spec/classes/broker_spec.rb b/spec/classes/broker_spec.rb index 222823be..3fd3d35f 100644 --- a/spec/classes/broker_spec.rb +++ b/spec/classes/broker_spec.rb @@ -52,41 +52,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 From ed9f96f7dd9187c45a8001793e673eb171ab58f3 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 10:39:23 +0100 Subject: [PATCH 4/7] regenerate reference --- REFERENCE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 68c70b25..73f6ed72 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -502,7 +502,7 @@ Default value: `'kafka'` Data type: `Boolean` -Install the init.d or systemd service. +Install the systemd service. Default value: `$kafka::params::manage_service` @@ -862,7 +862,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` @@ -1306,7 +1306,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` @@ -1658,7 +1658,7 @@ Default value: `'kafka-producer'` Data type: `Boolean` -Install the init.d or systemd service. +Install systemd service. Default value: `$kafka::params::manage_service` From 05bd300b12cab7b2c4308edfb202694098e80a8a Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 13:37:24 +0100 Subject: [PATCH 5/7] readd doctags --- manifests/broker/config.pp | 1 + manifests/consumer/config.pp | 1 + manifests/producer/config.pp | 1 + 3 files changed, 3 insertions(+) diff --git a/manifests/broker/config.pp b/manifests/broker/config.pp index ad5e7d29..1e207aa0 100644 --- a/manifests/broker/config.pp +++ b/manifests/broker/config.pp @@ -24,6 +24,7 @@ $config_notify = undef } + $doctag = 'brokerconfigs' file { "${config_dir}/server.properties": ensure => file, owner => $user_name, diff --git a/manifests/consumer/config.pp b/manifests/consumer/config.pp index 21c8f058..ec11ac16 100644 --- a/manifests/consumer/config.pp +++ b/manifests/consumer/config.pp @@ -20,6 +20,7 @@ $config_notify = undef } + $doctag = 'consumerconfigs' file { "${config_dir}/consumer.properties": ensure => file, owner => $user_name, diff --git a/manifests/producer/config.pp b/manifests/producer/config.pp index 66269f70..a4113c84 100644 --- a/manifests/producer/config.pp +++ b/manifests/producer/config.pp @@ -17,6 +17,7 @@ $config_notify = undef } + $doctag = 'producerconfigs' file { "${config_dir}/producer.properties": ensure => file, owner => $user_name, From eeaf2ee6c9da708b521a5b8d0b798eb03dda0a0b Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 11 Feb 2024 13:38:27 +0100 Subject: [PATCH 6/7] delete unused init.erb template --- templates/init.erb | 161 --------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 templates/init.erb 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 From b06a19640195f4d65884374752bc1e76c2fb4e11 Mon Sep 17 00:00:00 2001 From: markuszilch Date: Sun, 9 Jun 2024 17:44:16 +0200 Subject: [PATCH 7/7] expand redhat 7 specific checks to all OSes --- spec/acceptance/broker_spec.rb | 4 ++-- spec/acceptance/consumer_spec.rb | 2 +- spec/acceptance/mirror_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/acceptance/broker_spec.rb b/spec/acceptance/broker_spec.rb index 3b96f4b0..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,7 +197,7 @@ class { 'kafka::broker': apply_manifest(pp, catch_changes: 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' } diff --git a/spec/acceptance/consumer_spec.rb b/spec/acceptance/consumer_spec.rb index aba081f0..490c896c 100644 --- a/spec/acceptance/consumer_spec.rb +++ b/spec/acceptance/consumer_spec.rb @@ -140,7 +140,7 @@ class { 'kafka::consumer': apply_manifest(pp, catch_failures: true) 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 0b40ae27..20848fd8 100644 --- a/spec/acceptance/mirror_spec.rb +++ b/spec/acceptance/mirror_spec.rb @@ -220,7 +220,7 @@ class { 'kafka::mirror': apply_manifest(pp, catch_changes: true) 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' }