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

Decouple service from init system #279

Merged
Merged
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
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$purge = true,
) {

if $::consul::init_style {
if $::consul::init_style != 'unmanaged' {

case $::consul::init_style {
'upstart': {
Expand Down
91 changes: 46 additions & 45 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,132 +1,133 @@
# == Class: consul
#
#
# Installs, configures and manages consul
#
#
# === Parameters
#
#
# [*acls*]
# Hash of consul_acl resources to create.
#
#
# [*arch*]
# Architecture of consul binary to download.
#
#
# [*archive_path*]
# Path used when installing consul via the url.
#
#
# [*bin_dir*]
# Directory to create the symlink to the consul binary in.
#
#
# [*checks*]
# Hash of consul::check resources to create.
#
#
# [*config_defaults*]
# Configuration defaults hash. Gets merged with config_hash.
#
#
# [*config_dir*]
# Directory to place consul configuration files in.
#
#
# [*config_hash*]
# Use this to populate the JSON config file for consul.
#
#
# [*config_mode*]
# Use this to set the JSON config file mode for consul.
#
#
# [*download_extension*]
# The extension of the archive file containing the consul binary to download.
#
#
# [*download_url*]
# Fully qualified url to the location of the archive file containing the consul binary.
#
#
# [*download_url_base*]
# Base url to the location of the archive file containing the consul binary.
#
#
# [*extra_groups*]
# Extra groups to add the consul system user to.
#
#
# [*extra_options*]
# Extra arguments to be passed to the consul agent
#
#
# [*group*]
# Name of the group that should own the consul configuration files.
#
#
# [*init_style*]
# What style of init system your system uses.
#
# What style of init system your system uses. Set to 'unmanaged' to disable
# managing init system files for the consul service entirely.
#
# [*install_method*]
# Valid strings: `package` - install via system package
# `url` - download and extract from a url. Defaults to `url`.
# `none` - disable install.
#
#
# [*join_wan*]
# Whether to join the wan on service start.
#
#
# [*manage_group*]
# Whether to create/manage the group that should own the consul configuration files.
#
#
# [*manage_service*]
# Whether to manage the consul service.
#
#
# [*manage_user*]
# Whether to create/manage the user that should own consul's configuration files.
#
#
# [*os*]
# OS component in the name of the archive file containing the consul binary.
#
#
# [*package_ensure*]
# Only valid when the install_method == package. Defaults to `latest`.
#
#
# [*package_name*]
# Only valid when the install_method == package. Defaults to `consul`.
#
#
# [*pretty_config*]
# Generates a human readable JSON config file. Defaults to `false`.
#
#
# [*pretty_config_indent*]
# Toggle indentation for human readable JSON file. Defaults to `4`.
#
#
# [*purge_config_dir*]
# Purge config files no longer generated by Puppet
#
#
# [*restart_on_change*]
# Determines whether to restart consul agent on $config_hash changes.
# This will not affect reloads when service, check or watch configs change.
# Defaults to `true`.
#
#
# [*service_enable*]
# Whether to enable the consul service to start at boot.
#
#
# [*service_ensure*]
# Whether the consul service should be running or not.
#
#
# [*services*]
# Hash of consul::service resources to create.
#
#
# [*ui_download_extension*]
# The extension of the archive file containing the consul ui to download.
#
#
# [*ui_download_url*]
# Fully qualified url to the location of the archive file containing the consul ui.
#
#
# [*ui_download_url_base*]
# Base url to the location of the archive file containing the consul ui.
#
#
# [*ui_package_ensure*]
# Only valid when the install_method == package. Defaults to `latest`.
#
#
# [*ui_package_name*]
# Only valid when the install_method == package. Defaults to `consul_ui`.
#
#
# [*user*]
# Name of the user that should own the consul configuration files.
#
#
# [*version*]
# Specify version of consul binary to download.
#
#
# [*watches*]
# Hash of consul::watch resources to create.
#
#
# === Examples
#
#
# @example
# class { '::consul':
# config_hash => {
Expand All @@ -136,7 +137,7 @@
# 'retry-join' => ['172.16.0.1'],
# },
# }
#
#
class consul (
$acls = $::consul::params::acls,
$arch = $::consul::params::arch,
Expand Down
5 changes: 1 addition & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
} elsif $::operatingsystem == 'Amazon' {
$init_style = 'init'
} else {
$init_style = undef
}
if $init_style == undef {
fail('Unsupported OS')
fail('Cannot determine init_style, unsupported OS')
}
}
13 changes: 9 additions & 4 deletions manifests/run_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
#
class consul::run_service {

$init_selector = $::consul::init_style ? {
$service_name = $::consul::init_style ? {
'launchd' => 'io.consul.daemon',
default => 'consul',
}

if $::consul::manage_service == true and $::consul::init_style {
$service_provider = $::consul::init_style ? {
'unmanaged' => undef,
default => $::consul::init_style,
}

if $::consul::manage_service == true {
service { 'consul':
ensure => $::consul::service_ensure,
name => $init_selector,
name => $service_name,
enable => $::consul::service_enable,
provider => $::consul::init_style,
provider => $service_provider,
}
}

Expand Down
6 changes: 3 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@
it { should contain_file('/lib/systemd/system/consul.service').with_content(/consul agent/) }
end

context "When asked not to manage the init_style" do
let(:params) {{ :init_style => false }}
it { should contain_class('consul').with_init_style(false) }
context "When asked not to manage the init system" do
let(:params) {{ :init_style => 'unmanaged' }}
it { should contain_class('consul').with_init_style('unmanaged') }
it { should_not contain_file("/etc/init.d/consul") }
it { should_not contain_file("/lib/systemd/system/consul.service") }
end
Expand Down