Skip to content

Commit

Permalink
Merge pull request #1035 from ekohl/native-systemd
Browse files Browse the repository at this point in the history
Rewrite to native systemd
  • Loading branch information
ekohl committed May 3, 2022
2 parents ddbe1cc + 860af1e commit 31950a7
Show file tree
Hide file tree
Showing 38 changed files with 147 additions and 1,048 deletions.
1 change: 0 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ fixtures:
zypprepo: "https://github.com/voxpupuli/puppet-zypprepo.git"
archive: "https://github.com/voxpupuli/puppet-archive.git"
systemd: "https://github.com/voxpupuli/puppet-systemd"
transition: "https://github.com/puppetlabs/puppetlabs-transition"
yumrepo_core:
repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git
puppet_version: ">= 6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ configuration are all driven through this script.
When an API-based resource is defined, the Jenkins' CLI is installed and run
against the local system (127.0.0.1). Jenkins is assumed to be listening on
port 8080, but the module is smart enough to notice if you've configured an
alternate port using jenkins::config_hash['HTTP_PORT'].
alternate port using jenkins::config_hash['JENKINS_PORT'].

Users and credentials are Puppet-managed, meaning that changes made to them
from outside Puppet will be reset at the next puppet run. In this way, you can
Expand Down
22 changes: 0 additions & 22 deletions lib/facter/jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,3 @@
plugins.keys.sort.map { |plugin| "#{plugin} #{plugins[plugin][:plugin_version]}" }.join(', ')
end
end

Facter.add(:jenkins_version) do
confine kernel: 'Linux'

setcode do
libdir = case Facter.value('os.family')
when 'Debian'
'/usr/share/jenkins'
when 'Archlinux'
'/usr/share/java/jenkins'
else
'/usr/lib/jenkins'
end
war = libdir + '/jenkins.war'

if Facter::Util::Resolution.which('java') and File.exist?(war)
Facter::Util::Resolution.exec(
'java -jar %s --version' % [war]
)
end
end
end
8 changes: 1 addition & 7 deletions lib/puppet/parser/functions/jenkins_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ module Puppet::Parser::Functions
ENDHEREDOC

config_hash = lookupvar('::jenkins::config_hash')
if config_hash && \
config_hash['HTTP_PORT'] && \
config_hash['HTTP_PORT']['value']
return config_hash['HTTP_PORT']['value']
else
return 8080
end
config_hash&.dig('JENKINS_PORT', 'value') || 8080
end
end
8 changes: 1 addition & 7 deletions lib/puppet/parser/functions/jenkins_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ module Puppet::Parser::Functions
ENDHEREDOC

config_hash = lookupvar('::jenkins::config_hash')
if config_hash && \
config_hash['PREFIX'] && \
config_hash['PREFIX']['value']
return config_hash['PREFIX']['value']
else
return ''
end
config_hash&.dig('PREFIX', 'value') || ''
end
end
4 changes: 2 additions & 2 deletions lib/puppet/x/jenkins/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Puppet::X::Jenkins::Config
class UnknownConfig < ArgumentError; end

DEFAULTS = {
cli_jar: '/usr/lib/jenkins/jenkins-cli.jar',
cli_jar: '/usr/share/java/jenkins-cli.jar',
url: 'http://localhost:8080',
ssh_private_key: nil,
puppet_helper: '/usr/lib/jenkins/puppet_helper.groovy',
puppet_helper: '/usr/share/java/puppet_helper.groovy',
cli_tries: 30,
cli_try_sleep: 2,
cli_username: nil,
Expand Down
6 changes: 5 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
$jenkins::params::config_hash_defaults,
$jenkins::config_hash
)
create_resources('jenkins::sysconfig', $config_hash)

systemd::dropin_file { 'puppet-overrides.conf':
unit => 'jenkins.service',
content => epp("${module_name}/jenkins-override.epp", { 'environment' => $config_hash }),
}
}
56 changes: 20 additions & 36 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# This class manages the [Jenkins CI/CD service](https://jenkins.io/index.html).
#
# Note that if different jenkins listening port(s) are configured via
# ``jenkins::port``, ``jenkins::config_hash`` and/or a ``jenkins::sysconf``
# resource, "bad things" are likely to happen. This is a known implementation
# problem with this module that can not be fixed without breaking backwards
# compatibility.
# ``jenkins::port`` and ``jenkins::config_hash`` resource, "bad things" are
# likely to happen. This is a known implementation problem with this module
# that can not be fixed without breaking backwards compatibility.
#
# @param version
# package to install
Expand Down Expand Up @@ -79,8 +78,7 @@
# @example Bulk sysconf
# class{ 'jenkins':
# config_hash => {
# 'HTTP_PORT' => { 'value' => '9090' },
# 'AJP_PORT' => { 'value' => '9009' },
# 'JENKINS_PORT' => { 'value' => '9090' },
# }
# }
#
Expand Down Expand Up @@ -169,11 +167,9 @@
# install ``jenkins-cli.jar`` CLI utility
#
# * force installation of the jenkins CLI jar to
# ``$libdir/cli/jenkins-cli.jar``
# ``$libdir/jenkins-cli.jar``
# * the cli is automatically installed when needed by components that use it,
# such as the user and credentials types, and the security class
# * CLI installation (both implicit and explicit) requires the ``unzip``
# command
#
# @param cli_ssh_keyfile
# Provides the location of an ssh private key file to make authenticated
Expand Down Expand Up @@ -207,16 +203,6 @@
# @param libdir
# Path to jenkins core files
#
# * Redhat: ``/usr/lib/jenkins``
# * Debian: ``/usr/share/jenkins``
#
# @param sysconfdir
# Controls the path to the "sysconfig" file that stores jenkins service
# start-up variables
#
# * RedHat: ``/etc/sysconfig/jenkins``
# * Debian: ``/etc/default/jenkins``
#
# @param manage_datadirs
# manage the local state dir, plugins dir and jobs dir
#
Expand Down Expand Up @@ -284,9 +270,6 @@
# version: '2.16.0'
# # /support-core deps
#
# @param systemd_type
# Define a systemd unit type
#
class jenkins (
String $version = 'installed',
Boolean $lts = true,
Expand All @@ -298,7 +281,7 @@
Boolean $manage_service = true,
Boolean $service_enable = true,
Enum['running', 'stopped'] $service_ensure = 'running',
Optional[String] $service_provider = $jenkins::params::service_provider,
Optional[String] $service_provider = undef,
Hash $config_hash = {},
Hash $plugin_hash = {},
Hash $job_hash = {},
Expand All @@ -317,8 +300,7 @@
Integer $cli_tries = 10,
Integer $cli_try_sleep = 10,
Integer $port = 8080,
Stdlib::Absolutepath $libdir = $jenkins::params::libdir,
Stdlib::Absolutepath $sysconfdir = $jenkins::params::sysconfdir,
Stdlib::Absolutepath $libdir = '/usr/share/java',
Boolean $manage_datadirs = true,
Stdlib::Absolutepath $localstatedir = '/var/lib/jenkins',
Optional[Integer] $executors = undef,
Expand All @@ -330,7 +312,6 @@
Array $default_plugins = $jenkins::params::default_plugins,
String $default_plugins_host = 'https://updates.jenkins.io',
Boolean $purge_plugins = false,
Enum['simple', 'forking'] $systemd_type = $jenkins::params::systemd_type,
) inherits jenkins::params {
if $purge_plugins and ! $manage_datadirs {
warning('jenkins::purge_plugins has no effect unless jenkins::manage_datadirs is true')
Expand Down Expand Up @@ -396,17 +377,20 @@
notice(sprintf('INFO: make sure you install the following plugins with your code using this module: %s',join($jenkins::params::default_plugins,','))) # lint:ignore:140chars
}

if $service_provider == 'systemd' {
jenkins::systemd { 'jenkins':
user => $user,
libdir => $libdir,
}
# puppet/jenkins used to implement systemd but Jenkins 2.332 moved to
# systemd and implements this natively. Clean up the old implementation.
$old_libdir = $facts['os']['family'] ? {
'Archlinux' => '/usr/share/java/jenkins/',
'Debian' => '/usr/share/jenkins',
default => '/usr/lib/jenkins',
}
file { "${old_libdir}/jenkins-run":
ensure => absent,
}

# jenkins::config manages the jenkins user resource, which is autorequired
# by the file resource for the run wrapper.
Class['jenkins::config']
-> Jenkins::Systemd['jenkins']
-> Anchor['jenkins::end']
file { '/etc/systemd/system/jenkins.service':
ensure => absent,
notify => Service['jenkins'],
}
}

Expand Down
56 changes: 6 additions & 50 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,33 @@
# @api private
class jenkins::params {
$swarm_version = '2.2'
$_java_args = '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false'
$config_hash_defaults = {
'JAVA_OPTS' => { value => '-Djava.awt.headless=true -Djenkins.install.runSetupWizard=false' },
}
$default_plugins = [
'credentials', # required by puppet_helper.groovy
'javax-activation-api', # implied by all plugin
'javax-mail-api', # implied by all plugins
'sshd', # implied by structs
'structs', # required by credentials plugin
]

if versioncmp(pick($facts['jenkins_version'], '2.313'), '2.313') >= 0 {
$systemd_type = 'simple'
} else {
$systemd_type = 'forking'
}

case $facts['os']['family'] {
'Debian': {
$repo = true
$libdir = '/usr/share/jenkins'
$package_provider = 'dpkg'
$service_provider = undef
$sysconfdir = '/etc/default'
$config_hash_defaults = {
'JAVA_ARGS' => { value => $_java_args },
'AJP_PORT' => { value => '-1' },
}
}
'RedHat': {
$repo = true
$libdir = '/usr/lib/jenkins'
$package_provider = 'rpm'
$sysconfdir = '/etc/sysconfig'
$config_hash_defaults = {
'JENKINS_JAVA_OPTIONS' => { value => $_java_args },
'JENKINS_AJP_PORT' => { value => '-1' },
}

# explicitly use systemd if it is available
# XXX only enable explicit systemd support on RedHat at this time due to
# the Debian packaging using variable interpolation in
# /etc/default/jenkins.
# XXX this param exists because of a historical work around to PUP-5353
# it is part of the public interface to ::jenkins; it needs to be
# maintained until at least a major version bump. It has been somewhat
# repurposed as a flag for specific systemd support.
if $facts['systemd'] {
$service_provider = 'systemd'
} else {
$service_provider = undef
}
}
'Archlinux': {
$repo = false
$libdir = '/usr/share/java/jenkins/'
$package_provider = 'pacman'
$service_provider = undef
$sysconfdir = '/etc/conf.d'
$config_hash_defaults = {
# Archlinux's jenkins package uses it's own variables
# which are not compatible with these.
#'JENKINS_JAVA_OPTIONS' => { value => $_java_args },
#'JENKINS_AJP_PORT' => { value => '-1' },
}
}
default: {
$repo = true
$libdir = '/usr/lib/jenkins'
$package_provider = undef
$service_provider = undef
$sysconfdir = '/etc/sysconfig'
$config_hash_defaults = {
'JENKINS_JAVA_OPTIONS' => { value => $_java_args },
'JENKINS_AJP_PORT' => { value => '-1' },
}
}
}
}
43 changes: 16 additions & 27 deletions manifests/slave.pp
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@

# customizations based on the OS family
case $facts['os']['family'] {
'Debian': {
$defaults_location = $jenkins::params::sysconfdir

ensure_packages(['daemon'])
Package['daemon'] -> Service['jenkins-slave']
'Archlinux': {
$defaults_location = '/etc/conf.d'
}
'Darwin': {
$defaults_location = $slave_home
}
'Debian': {
$defaults_location = '/etc/default'
}
default: {
$defaults_location = $jenkins::params::sysconfdir
$defaults_location = '/etc/sysconfig'
}
}

Expand All @@ -224,29 +224,18 @@
$defaults_user = 'root'
$defaults_group = 'root'
$manage_user_home = true
$sysv_init = '/etc/init.d/jenkins-slave'

if $facts['systemd'] {
jenkins::systemd { 'jenkins-slave':
user => $slave_user,
libdir => $slave_home,
}
} else {
file { "${slave_home}/${service_name}-run":
content => template("${module_name}/${service_name}-run.erb"),
owner => $slave_user,
mode => '0755',
notify => Service[$service_name],
}
file { "${slave_home}/${service_name}-run":
content => template("${module_name}/${service_name}-run.erb"),
owner => $slave_user,
mode => '0755',
seltype => 'bin_t',
notify => Service[$service_name],
}

file { $sysv_init:
ensure => 'file',
mode => '0755',
owner => 'root',
group => 'root',
content => template("${module_name}/${service_name}.${facts['os']['family']}.erb"),
notify => Service[$service_name],
}
systemd::unit_file { "${service_name}.service":
content => template("${module_name}/${service_name}.service.erb"),
notify => Service[$service_name],
}
}
'Darwin': {
Expand Down
21 changes: 0 additions & 21 deletions manifests/sysconfig.pp

This file was deleted.

Loading

0 comments on commit 31950a7

Please sign in to comment.