Skip to content

Commit

Permalink
Merge pull request #357 from zilchms/systemd
Browse files Browse the repository at this point in the history
Drop support for non systemd OS
  • Loading branch information
bastelfreak authored Jun 9, 2024
2 parents 262f391 + b06a196 commit c52cc17
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 342 deletions.
8 changes: 4 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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`

Expand Down Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion manifests/broker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 6 additions & 23 deletions manifests/broker/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion manifests/consumer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 6 additions & 23 deletions manifests/consumer/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion manifests/mirror.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 6 additions & 23 deletions manifests/mirror/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion manifests/producer.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 1 addition & 10 deletions manifests/producer/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions spec/acceptance/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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' }
Expand Down
11 changes: 1 addition & 10 deletions spec/acceptance/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
11 changes: 1 addition & 10 deletions spec/acceptance/mirror_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
23 changes: 4 additions & 19 deletions spec/classes/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions spec/classes/consumer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions spec/classes/mirror_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 1 addition & 29 deletions spec/classes/producer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit c52cc17

Please sign in to comment.