Skip to content

Opentable specific mods #6

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion Puppetfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
forge 'https://forgeapi.puppetlabs.com'

mod 'puppetlabs-stdlib', '>= 2.3.3 < 5.0.0'
mod 'puppetlabs-stdlib', '>= 2.3.3 < 5.0.0'
mod 'puppet/archive', '>= 0.5.0'
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#puppet-zookeeper

[![Puppet
Forge](http://img.shields.io/puppetforge/v/deric/zookeeper.svg)](https://forge.puppetlabs.com/deric/zookeeper) [![Build Status](https://travis-ci.org/deric/puppet-zookeeper.png?branch=master)](https://travis-ci.org/deric/puppet-zookeeper)
[![Puppet Forge](http://img.shields.io/puppetforge/v/deric/zookeeper.svg)](https://forge.puppetlabs.com/deric/zookeeper) [![Build Status](https://travis-ci.org/deric/puppet-zookeeper.png?branch=master)](https://travis-ci.org/deric/puppet-zookeeper)

A puppet receipt for [Apache Zookeeper](http://zookeeper.apache.org/). ZooKeeper is a high-performance coordination service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

Expand Down Expand Up @@ -141,16 +140,19 @@ After=network-online.target
## Parameters

- `id` - cluster-unique zookeeper's instance id (1-255)
- `datastore`
- `datalogstore` - specifying this configures the `dataLogDir` ZooKeeper config values and allows for transaction logs to be stored in a different location, improving IO performance
- `log_dir`
- `datastore` - configures the zookeeper `dataDir` config parameter
- `datalogstore` - configures the `dataLogDir` ZooKeeper config values and allows for transaction logs to be stored in a different location, improving IO performance
- `log_dir` - Sets java property `zookeeper.log.dir`. Passed to java with `-Dzookeeper.log.dir`
- `purge_interval` - automatically will delete ZooKeeper logs (available since ZooKeeper 3.4.0)
- `snap_retain_count` - number of snapshots that will be kept after purging (since ZooKeeper 3.4.0)
- `min_session_timeout` - the minimum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 2 times the **tickTime** (since ZooKeeper 3.3.0)
- `max_session_timeout` - the maximum session timeout in milliseconds that the server will allow the client to negotiate. Defaults to 20 times the **tickTime** (since ZooKeeper 3.3.0)
- `manage_service` (default: `true`) whether Puppet should ensure running service
- `manage_service_file` when enabled on RHEL 7.0 a systemd config will be managed
- `ensure_account` controls whether `zookeeper` user and group will be ensured (set to `false` to disable this feature)
- `manage_service` (default: `true`) - whether Puppet should ensure running service
- `manage_service_file` - when enabled on RHEL 7.0 a systemd config will be managed
- `ensure_account` - controls whether `zookeeper` user and group will be ensured (set to `false` to disable this feature)
- `install_method` (default: `package`) - installation method (either `package` or `archive`). `package` will use the available package manager. `archive` will install from an archive file.
- `mirror_url` - Base URL of Apache mirror to use if `install_method` is not `package`
- `archive_checksum` - optional hash to use when verifying installation archive. ex: `{ type => 'sha1', hash => 'abcdef123456' }`

and many others, see the `init.pp` file for more details.

Expand Down Expand Up @@ -252,7 +254,7 @@ If you are versioning your puppet conf with git just add it as submodule, from y
## Dependencies

* stdlib `> 2.3.3` - function `ensure_resources` is required
* datacat - experimental (might be removed in future releases)
* archive `>= 0.5.0` - used for tarball installation

## Supported platforms

Expand Down
13 changes: 13 additions & 0 deletions files/znode_exists.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

function usage () {
echo "usage: $0 znode_path" >&2
exit 1
}

_znode="$1"

[ -z $_znode ] && usage

[[ $(echo "stat $_znode" | zkCli.sh 2>&1 >/dev/null) != \
*'Node does not exist:'* ]]
3 changes: 2 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
}
}

if $exhibitor_manaaged == 'false' {
if $exhibitor_managed == false {

Choose a reason for hiding this comment

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

Consider using stdlib/validate_bool

Copy link
Author

Choose a reason for hiding this comment

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

This is validated in init.pp.
Preferable to move it into config.pp?


file { "${cfg_dir}/zoo.cfg":
owner => $user,
group => $group,
Expand Down
10 changes: 6 additions & 4 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
$peer_type = 'UNSET',
$start_with = undef,
$ensure_cron = true,
$install_method = package,
$install_method = 'package',
$install_dir = '/opt/zookeeper',
$download_url = 'http://mirror.cogentco.com/pub/apache/zookeeper',
$mirror_url = 'http://mirror.cogentco.com/pub/apache',
$archive_checksum = {},
$service_package = undef,
$service_name = $::zookeeper::params::service_name,
$service_provider = $::zookeeper::params::service_provider,
Expand Down Expand Up @@ -103,7 +104,8 @@
class { 'zookeeper::install':
ensure => $ensure,
install_method => $install_method,
download_url => $download_url,
mirror_url => $mirror_url,
archive_checksum => $archive_checksum,
install_dir => $install_dir,
snap_retain_count => $snap_retain_count,
datastore => $datastore,
Expand Down Expand Up @@ -155,7 +157,7 @@
systemd_unit_after => $systemd_unit_after,
}

if ($manage_service) {
if ($manage_service and !$exhibitor_managed) {
class { 'zookeeper::service':
cfg_dir => $cfg_dir,
zoo_dir => $zoo_dir,
Expand Down
90 changes: 71 additions & 19 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
# Should not be included directly
#
class zookeeper::install(
$install_method = $zookeeper::install_method,
$download_url = 'http://mirror.cogentco.com/pub/apache/zookeeper',
$install_method = 'package',
$mirror_url = 'http://mirror.cogentco.com/pub/apache',
$archive_checksum = {},
$install_dir = '/opt/zookeeper',
$package_dir = '/var/tmp/zookeeper',
$ensure = present,
$snap_retain_count = 3,
$cleanup_sh = '/usr/lib/zookeeper/bin/zkCleanup.sh',
Expand All @@ -34,6 +36,11 @@
anchor { 'zookeeper::install::end': }

if ($install_method == 'package') {
$clean = $manual_clean
$repo_source = is_hash($repo) ? {
true => 'custom',
false => $repo,
}
case $::osfamily {
'Debian': {
class { 'zookeeper::os::debian':
Expand Down Expand Up @@ -67,37 +74,82 @@
fail("Module '${module_name}' is not supported on OS: '${::operatingsystem}', family: '${::osfamily}'")
}
}
} else {
} elsif ($install_method == 'archive') {
include '::archive'

Choose a reason for hiding this comment

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

Perhaps this should be

} else if ($install_method == 'archive') {
  # ...
} else {
  fail("you must select a valid installation method for zookeeper")
}


$basefilename = "zookeeper-${ensure}.tar.gz"
$package_url = "${mirror_url}/zookeeper/zookeeper-${ensure}/${basefilename}"
$extract_path = "${install_dir}-${ensure}"

if ($manual_clean == undef) {
$clean = versioncmp($ensure, '3.4') ? {
'-1' => true,
default => false,
}
} else {
$clean = $manual_clean
}

package { ['zookeeper','zookeeperd']:
ensure => absent
}

file { $install_dir:
ensure => link,
target => "${install_dir}-${ensure}"
}

exec { 'download-zk-package':
command => "/usr/bin/wget -O /tmp/zookeeper-${ensure}.tar.gz ${package_mirror}/zookeeper-${ensure}/zookeeper-${ensure}.tar.gz",
creates => "/tmp/zookeeper-${ensure}.tar.gz"
target => $extract_path
}

exec { 'install-zk-package':
command => "/bin/tar -xvzf /tmp/zookeeper-${ensure}.tar.gz -C /opt",
creates => "${install_dir}-${ensure}/zookeeper-${ensure}.jar",
file { $package_dir:
ensure => directory,
owner => 'zookeeper',
group => 'zookeeper',
require => [
Exec['download-zk-package']
]
Group['zookeeper'],
User['zookeeper'],
],
}
file { "${install_dir}-${ensure}":

file { $extract_path:
ensure => directory,
recurse => true,
owner => 'zookeeper',
group => 'zookeeper'
group => 'zookeeper',
require => [
Group['zookeeper'],
User['zookeeper'],
],
}

archive { "${package_dir}/${basefilename}":

Choose a reason for hiding this comment

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

Should this resource notify the service resource? (Or else, should the service resource subscribe to this resource). That way if the version is updated and zk is reinstalled, zk will be optionally restarted.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe? The deb doesn't do a restart on upgrade.

ensure => present,
extract => true,
extract_command => 'tar xfz %s --strip-components=1',
extract_path => $extract_path,
source => $package_url,
checksum => $archive_checksum['hash'],
checksum_type => $archive_checksum['type'],
creates => "${extract_path}/conf",
cleanup => true,
user => 'zookeeper',
group => 'zookeeper',
require => [
File[$package_dir],
File[$install_dir],
Group['zookeeper'],
User['zookeeper'],
],
}
} else {
fail("You must specify a valid install method for zookeeper")
}

file { '/usr/local/bin/znode_exists.sh':
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
source => 'puppet:///modules/zookeeper/znode_exists.sh',
require => File['/usr/local/bin'],
}

class { 'zookeeper::post_install':
ensure => $ensure,
Expand All @@ -108,7 +160,7 @@
datastore => $datastore,
snap_retain_count => $snap_retain_count,
cleanup_sh => $cleanup_sh,
manual_clean => $manual_clean,
manual_clean => $clean,
require => Anchor['zookeeper::install::end'],
}

Expand Down
41 changes: 20 additions & 21 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
$cfg_dir = '/etc/zookeeper/conf',
$service_name = 'zookeeper',
$service_ensure = 'running',
$manage_service = true,
$manage_service_file = true,
$user = 'zookeeper',
$group = 'zookeeper',
Expand All @@ -20,27 +19,26 @@
require ::zookeeper::install


if $manage_service == true {
if $manage_service_file == true {
if $service_provider == 'systemd' {
file { '/usr/lib/systemd/system/zookeeper.service':
ensure => 'present',
content => template('zookeeper/zookeeper.service.erb'),
} ~>
exec { 'systemctl daemon-reload # for zookeeper':
refreshonly => true,
path => $::path,
notify => Service[$service_name]
}
} elsif ( $service_provider == 'init' or $service_provider == 'redhat') {
file {"/etc/init.d/${service_name}":
ensure => present,
content => template('zookeeper/zookeeper.init.erb'),
mode => '0755',
notify => Service[$service_name]
}
if $manage_service_file == true {
if $service_provider == 'systemd' {
file { '/usr/lib/systemd/system/zookeeper.service':
ensure => 'present',
content => template('zookeeper/zookeeper.service.erb'),
} ~>
exec { 'systemctl daemon-reload # for zookeeper':
refreshonly => true,
path => $::path,
notify => Service[$service_name]
}
}
} elsif ( $service_provider == 'init' or $service_provider == 'redhat') {
file {"/etc/init.d/${service_name}":
ensure => present,
content => template('zookeeper/zookeeper.init.erb'),
mode => '0755',
notify => Service[$service_name]
}
}
}

service { $service_name:
ensure => $service_ensure,
Expand All @@ -57,4 +55,5 @@
File["${cfg_dir}/environment"], File["${cfg_dir}/log4j.properties"],
]
}

}
34 changes: 28 additions & 6 deletions manifests/znode.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
define zookeeper::znode(
$ensure = '',
$assosiation = ''
$association = ''
) {


validate_re($name, '^\/', "znode path must start with a '/'")
if $name =~ /\/\.{1,2}(\/.*)?$/ {
fail("znode name cannot be '.' or '..'")
}

$create_cmd = shellquote(
'/bin/echo',
"create ${name}",
"\'${association}\'"
)

$rm_cmd = shellquote(
'/bin/echo',
"rmr ${name}"
)

if $ensure == 'present' {
exec { "create znode ${name}":
command => "/bin/echo \"create /${name} '${assosiation}'\" | ${zookeeper::install_dir}/bin/zkCli.sh",
unless => "/bin/bash -c \"if [[ \\\"`echo 'ls /' | /opt/zookeeper/bin/zkCli.sh | tail -n2 | head -n1`\\\" == *${name}* ]]; then exit 0; else exit 1; fi\""
command => "${create_cmd} | zkCli.sh",
unless => shellquote('znode_exists.sh', $name),
path => "/usr/share/zookeeper/bin:${zookeeper::install_dir}/bin:/bin:/usr/bin:/usr/local/bin",
require => Class['::zookeeper::install'],

}
} else {
exec { "delete znode ${name}":
command => "/bin/echo \"rmr /${name}\" | ${zookeeper::install_dir}/bin/zkCli.sh",
unless => "/bin/bash -c \"if [[ \\\"`echo 'ls /' | /opt/zookeeper/bin/zkCli.sh | tail -n2 | head -n1`\\\" == *${name}* ]]; then exit 0; else exit 1; fi\""
command => "${rm_cmd} | zkCli.sh",
onlyif => shellquote('znode_exists.sh', $name),
path => "/usr/share/zookeeper/bin:${zookeeper::install_dir}/bin:/bin:/usr/bin:/usr/local/bin",
require => Class['::zookeeper::install'],
}
}

}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"issues_url": "https://github.com/deric/puppet-zookeeper/issues",
"description": "ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.",
"dependencies": [
{
"name": "puppet/archive",
"version_requirement": ">= 0.5.0"
},
{
"name": "puppetlabs-stdlib",
"version_requirement": ">= 2.3.3 < 5.0.0"
Expand Down
Loading