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

Candlepin service running via a systemd container #121

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
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fixtures:
concat: 'https://github.com/puppetlabs/puppetlabs-concat'
postgresql: 'https://github.com/puppetlabs/puppetlabs-postgresql.git'
qpid: 'https://github.com/theforeman/puppet-qpid.git'
systemd: 'https://github.com/camptocamp/puppet-systemd.git'
yumrepo_core:
repo: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core'
puppet_version: '>= 6.0.0'
2 changes: 1 addition & 1 deletion manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
>> ${log_dir}/cpdb.log \
2>&1 && touch /var/lib/candlepin/cpdb_done",
creates => '/var/lib/candlepin/cpdb_done',
before => Service['tomcat'],
before => Service[$candlepin::service_name],
require => Concat['/etc/candlepin/candlepin.conf'],
}
# if both manage_db and init_db enforce order of resources
Expand Down
18 changes: 18 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
# @param shutdown_wait
# Time to wait in seconds, before killing process
#
# @param container
# Run Candlepin as a systemd service via a container
#
# @param container_version
# Version of Candlepin container to run when running as a container
#
# @param container_image
# Candlepin container image to use (default: quay.io/foreman/candlepin)
#
class candlepin (
Boolean $manage_db = $candlepin::params::manage_db,
Boolean $init_db = $candlepin::params::init_db,
Expand Down Expand Up @@ -234,12 +243,21 @@
Optional[String] $lang = $candlepin::params::lang,
Boolean $security_manager = $candlepin::params::security_manager,
Optional[Integer[0]] $shutdown_wait = $candlepin::params::shutdown_wait,
Boolean $container = $candlepin::params::container,
String $container_version = $candlepin::params::container_version,
String $container_image = $candlepin::params::container_image,
) inherits candlepin::params {
if $amq_enable {
assert_type(String, $amqp_keystore_password)
assert_type(String, $amqp_truststore_password)
}

if $candlepin::container {
$service_name = 'candlepin'
} else {
$service_name = 'tomcat'
}

$amqpurl = "tcp://${qpid_hostname}:${qpid_ssl_port}?ssl='true'&ssl_cert_alias='amqp-client'"

contain candlepin::service
Expand Down
27 changes: 19 additions & 8 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
class candlepin::install {
assert_private()

package { ['candlepin']:
ensure => $candlepin::version,
}
if $candlepin::container {
ensure_packages(['podman'])

if $facts['selinux'] {
package { ['candlepin-selinux']:
exec { 'pull candlepin image':
command => "/usr/bin/podman pull ${candlepin::container_image}:${candlepin::container_version}",
unless => "/usr/bin/podman images ${candlepin::container_image}:${candlepin::container_version}",
require => Package['podman'],
timeout => 600,
}
sean797 marked this conversation as resolved.
Show resolved Hide resolved
} else {
package { ['candlepin']:
ensure => $candlepin::version,
}
}

if $candlepin::run_init {
ensure_packages(['wget'], { ensure => $candlepin::wget_version, })
if $facts['selinux'] {
package { ['candlepin-selinux']:
ensure => $candlepin::version,
}
}

if $candlepin::run_init {
ensure_packages(['wget'], { ensure => $candlepin::wget_version, })
}
}
}
4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
class candlepin::params {
$ssl_port = 8443

$container = false
$container_version = 'latest'
$container_image = 'quay.io/foreman/candlepin'

$manage_db = true
$init_db = true
$db_type = 'postgresql'
Expand Down
18 changes: 16 additions & 2 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@
class candlepin::service {
assert_private()

service { 'tomcat':
if $candlepin::container {
file { '/etc/sysconfig/candlepin':
ensure => file,
content => template('candlepin/candlepin.sysconfig.erb'),
notify => Service[$candlepin::service_name],
mode => '0640',
}

systemd::unit_file { 'candlepin.service':
content => template('candlepin/candlepin.service.erb'),
notify => Service[$candlepin::service_name],
}
}

service { $candlepin::service_name:
ensure => running,
enable => true,
hasstatus => true,
Expand All @@ -15,7 +29,7 @@
exec { 'cpinit':
# tomcat startup is slow - try multiple times (the initialization service is idempotent)
command => "/usr/bin/wget --no-check-certificate --no-proxy --timeout=30 --tries=40 --wait=20 --retry-connrefused -qO- https://localhost:${candlepin::ssl_port}/candlepin/admin/init > /var/log/candlepin/cpinit.log 2>&1 && touch /var/lib/candlepin/cpinit_done",
require => [Package['wget'], Service['tomcat']],
require => [Package['wget'], Service[$candlepin::service_name]],
creates => '/var/lib/candlepin/cpinit_done',
# timeout is roughly "wait" * "tries" from above
timeout => 800,
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
"name": "katello/qpid",
"version_requirement": ">= 3.0.0 < 5.0.0"
},
{
"name": "camptocamp/systemd",
"version_requirement": ">= 0.4.0 < 3.0.0"
}
],
"requirements": [
Expand Down
19 changes: 19 additions & 0 deletions spec/classes/candlepin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@
end
end

context 'with container true' do
let :params do
{container: true}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('candlepin') }
it { is_expected.to contain_package('podman').with_ensure('present') }
it { is_expected.to contain_systemd__unit_file('candlepin.service') }
it do
is_expected.to contain_file("/etc/sysconfig/candlepin").
with_content(/POSTGRES_SERVICE_HOST/).
with_content(/POSTGRES_PORT/).
with_content(/POSTGRES_DB/).
with_content(/POSTGRES_USER/).
with_content(/POSTGRES_PASSWORD/)
end
end

describe 'notify' do
let :pre_condition do
<<-EOS
Expand Down
18 changes: 18 additions & 0 deletions templates/candlepin.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Candlepin
Wants=syslog.service

[Service]
Restart=always
RestartSec=30
TimeoutStartSec=0
TimeoutSec=300
ExecStartPre=-/usr/bin/podman rm "candlepin-1"
ExecStart=/usr/bin/podman run --name candlepin-1 --env-file /etc/sysconfig/candlepin --net host -v /etc/candlepin:/etc/candlepin:z -v /etc/tomcat:/etc/tomcat:z -p <%= scope['candlepin::ssl_port'] %> <%= scope['candlepin::container_image'] %>:<%= scope['candlepin::container_version'] %>
ExecReload=-/usr/bin/podman stop "candlepin-1"
ExecReload=-/usr/bin/podman rm "candlepin-1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't reload be used for "make the service reload its configuration without stopping it" kind of thing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you make any configuration changes on disk, or environment variables you have to stop the container and re-start to pick up the new. I could be wrong though :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds more like restart and reload should simply not be implemented then.

ExecStop=-/usr/bin/podman stop "candlepin-1"
EnvironmentFile=-/etc/sysconfig/candlepin

[Install]
WantedBy=multi-user.target
5 changes: 5 additions & 0 deletions templates/candlepin.sysconfig.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_SERVICE_HOST=<%= scope['candlepin::db_host'] %>
POSTGRES_PORT=<%= scope['candlepin::db_port'] %>
POSTGRES_DB=<%= scope['candlepin::db_name'] %>
POSTGRES_USER=<%= scope['candlepin::db_user'] %>
POSTGRES_PASSWORD=<%= scope['candlepin::db_password'] %>