From 8fcdb4dcc1710f3b9e40cfe0d946f5535c8f3e5e Mon Sep 17 00:00:00 2001 From: Yves Galante Date: Sat, 20 Jun 2015 02:13:44 -0500 Subject: [PATCH] Add tarball installation support. --- .fixtures.yml | 1 + .gitignore | 4 + .travis.yml | 11 +-- README.markdown | 18 +++++ manifests/config.pp | 43 ++++++----- manifests/init.pp | 65 ++++++++-------- manifests/packages.pp | 108 +++++++++++++++++++++++---- manifests/params.pp | 17 ++++- manifests/service.pp | 14 ++-- metadata.json | 3 +- spec/classes/activemq_spec.rb | 95 ++++++++++++++++++++--- templates/activemq.xml.erb | 24 +++--- templates/init/default/activemq | 94 +++++++++++++++++++++++ templates/init/{ => redhat}/activemq | 0 14 files changed, 390 insertions(+), 107 deletions(-) create mode 100755 templates/init/default/activemq rename templates/init/{ => redhat}/activemq (100%) diff --git a/.fixtures.yml b/.fixtures.yml index cda023b..b02a897 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,6 @@ fixtures: repositories: stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" + staging: "git://github.com/nanliu/puppet-staging" symlinks: activemq: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 624a803..4ee2c45 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ pkg/ tmp/ .DS_Store spec/fixtures +.ruby-gemset +.ruby-version +Gemfile.lock +activemq.iml diff --git a/.travis.yml b/.travis.yml index ebf1ea0..29c7437 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,26 +3,21 @@ language: ruby bundler_args: --without development script: "bundle exec rake spec SPEC_OPTS='--format documentation'" rvm: - - 1.8.7 - 1.9.3 - 2.0.0 env: matrix: - - PUPPET_GEM_VERSION="~> 2.7.0" - PUPPET_GEM_VERSION="~> 3.0.0" - PUPPET_GEM_VERSION="~> 3.1.0" - - PUPPET_GEM_VERSION="~> 3.2.0" + - PUPPET_GEM_VERSION="~> 3.6.2" + - PUPPET_GEM_VERSION="~> 3.8.1" matrix: exclude: - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 2.7.0" + env: PUPPET_GEM_VERSION="~> 3.8.1" - rvm: 2.0.0 env: PUPPET_GEM_VERSION="~> 3.0.0" - rvm: 2.0.0 env: PUPPET_GEM_VERSION="~> 3.1.0" - - rvm: 1.8.7 - env: PUPPET_GEM_VERSION="~> 3.2.0" notifications: email: false diff --git a/README.markdown b/README.markdown index b7d6640..19f815e 100644 --- a/README.markdown +++ b/README.markdown @@ -50,4 +50,22 @@ To disable this behavior, pass in webconsole => false to the class. e.g. webconsole => false, } } + +# Custom configuration # + node default { + class { 'activemq': + server_config => template("${module_name}/activemq.xml.erb"), + } + } + +# Install from binary # + +If you do not have a activemq package ready for your favorite distribution, you can install it from the binary + + node default { + class { 'activemq': + install_from_binary => true, + package => 'http://www.eu.apache.org/dist/activemq/5.13.0/apache-activemq-5.13.0-bin.tar.gz', + } + } \ No newline at end of file diff --git a/manifests/config.pp b/manifests/config.pp index b0b0032..551fe97 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -11,33 +11,34 @@ # Sample Usage: # class activemq::config ( - $server_config, - $instance, - $package, - $path = '/etc/activemq/activemq.xml', - $server_config_show_diff = 'UNSET', + $server_config = $activemq::server_config_content, + $instance = $activemq::instance, + $path = $activemq::config_path, + $server_config_show_diff = $activemq::server_config_show_diff, + $system_user = $activemq::system_user, + $system_group = $activemq::system_group, + $install_from_binary = $activemq::install_from_binary, + $log_path = $activemq::log_path, ) { # Resource defaults File { - owner => 'activemq', - group => 'activemq', + owner => $system_user, + group => $system_group, mode => '0644', - notify => Service['activemq'], - require => Package[$package], + notify => Class['activemq::service'], + require => Class['activemq::packages'], } if $server_config_show_diff != 'UNSET' { - if versioncmp($settings::puppetversion, '3.2.0') >= 0 { + if versioncmp($::puppetversion, '3.2.0') >= 0 { File { show_diff => $server_config_show_diff } } else { warning('show_diff not supported in puppet prior to 3.2, ignoring') } } - $server_config_real = $server_config - - if $::osfamily == 'Debian' { + if $::osfamily == 'Debian' and !$install_from_binary { $available = "/etc/activemq/instances-available/${instance}" $path_real = "${available}/activemq.xml" @@ -49,20 +50,26 @@ ensure => link, target => $available, } - } - else { + } else { validate_re($path, '^/') $path_real = $path } + if $install_from_binary { + file { $log_path: + ensure => directory, + } + } + # The configuration file itself. file { 'activemq.xml': ensure => file, path => $path_real, - owner => 'activemq', - group => 'activemq', + owner => $system_user, + group => $system_group, mode => '0600', - content => $server_config_real, + content => $server_config, + notify => Class['activemq::service'], } } diff --git a/manifests/init.pp b/manifests/init.pp index a5aeeaf..be332e4 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -25,6 +25,11 @@ # } # class activemq( + $install_from_binary = $activemq::params::install_from_binary, + $home = $activemq::params::home, + $log_path = $activemq::params::log_path, + $system_user = $activemq::params::system_user, + $system_group = $activemq::params::system_group, $version = $activemq::params::version, $package = $activemq::params::package, $ensure = $activemq::params::ensure, @@ -44,35 +49,37 @@ validate_re($version, '^present$|^latest$|^[~+._0-9a-zA-Z:-]+$') validate_bool($webconsole) - $package_real = $package - $version_real = $version - $ensure_real = $ensure - $webconsole_real = $webconsole - $mq_admin_username_real = $mq_admin_username - $mq_admin_password_real = $mq_admin_password - $mq_cluster_username_real = $mq_cluster_username - $mq_cluster_password_real = $mq_cluster_password - $mq_cluster_brokers_real = $mq_cluster_brokers - - if $mq_admin_username_real == 'admin' { - warning '$mq_admin_username is set to the default value. This should be changed.' + if $server_config == 'UNSET' { + if $mq_admin_username == $activemq::params::mq_admin_username { + warning '$mq_admin_username is set to the default value. This should be changed.' + } + if $mq_admin_password == $activemq::params::mq_admin_password { + warning '$mq_admin_password is set to the default value. This should be changed.' + } + if size($mq_cluster_brokers) > 0 and $mq_cluster_username == $activemq::params::mq_cluster_username { + warning '$mq_cluster_username is set to the default value. This should be changed.' + } + if size($mq_cluster_brokers) > 0 and $mq_cluster_password == $activemq::params::mq_cluster_password { + warning '$mq_cluster_password is set to the default value. This should be changed.' + } } - if $mq_admin_password_real == 'admin' { - warning '$mq_admin_password is set to the default value. This should be changed.' + if $home != $activemq::params::home and !$install_from_binary { + fail 'home must not be set when install_from_binary=false(default)' } - if size($mq_cluster_brokers_real) > 0 and $mq_cluster_username_real == 'amq' { - warning '$mq_cluster_username is set to the default value. This should be changed.' + if $log_path != $activemq::params::log_path and !$install_from_binary { + fail 'log_path must not be set when install_from_binary=false(default)' } - if size($mq_cluster_brokers_real) > 0 and $mq_cluster_password_real == 'secret' { - warning '$mq_cluster_password is set to the default value. This should be changed.' + $config_path = $install_from_binary ? { + true => "${home}/conf/activemq.xml", + default => '/etc/activemq/activemq.xml', } # Since this is a template, it should come _after_ all variables are set for # this class. - $server_config_real = $server_config ? { + $server_config_content = $server_config ? { 'UNSET' => template("${module_name}/activemq.xml.erb"), default => $server_config, } @@ -83,23 +90,13 @@ notify => Class['activemq::service'], } - class { 'activemq::packages': - version => $version_real, - package => $package_real, - notify => Class['activemq::service'], - } + class { 'activemq::packages': } + ~> + class { 'activemq::service': } class { 'activemq::config': - instance => $instance, - package => $package_real, - server_config => $server_config_real, - server_config_show_diff => $server_config_show_diff, - require => Class['activemq::packages'], - notify => Class['activemq::service'], - } - - class { 'activemq::service': - ensure => $ensure_real, + require => Class['activemq::packages'], + notify => Class['activemq::service'], } anchor { 'activemq::end': diff --git a/manifests/packages.pp b/manifests/packages.pp index b774e5e..cd27ddd 100644 --- a/manifests/packages.pp +++ b/manifests/packages.pp @@ -11,30 +11,112 @@ # Sample Usage: # class activemq::packages ( - $version, - $package + $version = $activemq::version, + $package = $activemq::package, + $install_from_binary = $activemq::install_from_binary, + $system_user = $activemq::system_user, + $system_group = $activemq::system_group, + $activemq_home = $activemq::home, + $config_path = $activemq::config_path, + $log_path = $activemq::log_path, ) { validate_re($version, '^[~+._0-9a-zA-Z:-]+$') + validate_bool($install_from_binary) - $version_real = $version - $package_real = $package - - package { $package_real: - ensure => $version_real, - notify => Service['activemq'], + unless $install_from_binary { + package { $package: + ensure => $version, + notify => Class['activemq::service'], + } } + if $install_from_binary { + include staging + + file { '/etc/init.d/activemq': + ensure => file, + content => template("${module_name}/init/default/activemq"), + owner => 'root', + group => 'root', + mode => '0755', + } + + # Manage user and group only if installed from source, it is managed by + # packaging system otherwise + group { $system_group: + ensure => 'present', + system => true, + } + + user { $system_user: + ensure => 'present', + gid => $system_group, + home => $activemq_home, + managehome => false, + system => true, + shell => '/bin/false', + require => Group[$system_group], + } + + validate_absolute_path($activemq_home) + validate_re( + $package, + '^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$', + "Expected to `package' parameter be a valid HTTP URI, when + `install_from_binary' is true." + ) + + file { $activemq_home: + ensure => directory, + owner => $system_user, + group => $system_group, + require => User[$system_user], + } + + $filename = regsubst($package, '.*/(.*)', '\1') + + if ! defined(Staging::File[$filename]) { + staging::file { $filename: + source => $package, + timeout => 0, + } + } + + staging::extract { $filename: + source => "${::staging::path}/activemq/${filename}", + target => $activemq_home, + require => [Staging::File[$filename], File[$activemq_home]], + unless => "test \"\$(ls -A ${activemq_home})\"", + strip => 1, + user => $system_user, + group => $system_group, + } + + file_line { 'audit.file': + path => "${activemq_home}/conf/log4j.properties", + line => "log4j.appender.audit.file=${log_path}/audit.log", + match => '^log4j\.appender\.audit\.file.*', + require => [Staging::Extract[$filename]], + } + + file_line { 'logfile': + path => "${activemq_home}/conf/log4j.properties", + line => "log4j.appender.logfile.file=${log_path}/activemq.log", + match => '^log4j\.appender\.logfile\.file.*', + require => [Staging::Extract[$filename]], + } + # Has been reworked in 5.9 and no longer needed - if $::osfamily == 'RedHat' and ($version == 'present' or versioncmp($version, '5.9') < 0) { + } elsif $::osfamily == 'RedHat' and ($version == 'present' or versioncmp($version, '5.9') < 0) { + # JJM Fix the activemq init script always exiting with status 0 # FIXME This should be corrected in the upstream packages file { '/etc/init.d/activemq': ensure => file, - path => '/etc/init.d/activemq', - content => template("${module_name}/init/activemq"), - owner => '0', - group => '0', + content => template("${module_name}/init/redhat/activemq"), + owner => 'root', + group => 'root', mode => '0755', } } diff --git a/manifests/params.pp b/manifests/params.pp index ca1aa8d..05565d6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,12 +1,14 @@ # Private class activemq::params { + $install_from_binary = false + $home = '/opt/apache-activemq' + $log_path = '/var/log/activemq' $version = 'present' $package = 'activemq' $ensure = 'running' $instance = 'activemq' $server_config = 'UNSET' $server_config_show_diff = 'UNSET' - $service_enable = true $mq_broker_name = $::fqdn $mq_admin_username = 'admin' $mq_admin_password = 'admin' @@ -17,10 +19,21 @@ # Debian does not include the webconsole case $::osfamily { 'Debian': { - $webconsole = false + $webconsole = $install_from_binary } default: { $webconsole = true } } + # OpenBSD system user/group differs + case $::osfamily { + 'OpenBSD': { + $system_user = '_activemq' + $system_group = '_activemq' + } + default: { + $system_user = 'activemq' + $system_group = 'activemq' + } + } } diff --git a/manifests/service.pp b/manifests/service.pp index 9a4092b..fd4653e 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -11,21 +11,21 @@ # Sample Usage: # class activemq::service( - $ensure, - $service_enable = $::activemq::params::service_enable + $ensure = $activemq::ensure, ) { # Arrays cannot take anonymous arrays in Puppet 2.6.8 $v_ensure = [ '^running$', '^stopped$' ] validate_re($ensure, $v_ensure) - validate_bool($service_enable) - - $ensure_real = $ensure + $enable = $ensure ? { + 'running' => true, + default => false, + } service { 'activemq': - enable => $service_enable, - ensure => $ensure_real, + ensure => $ensure, + enable => $enable, hasstatus => true, hasrestart => true, require => Class['activemq::packages'], diff --git a/metadata.json b/metadata.json index 631763e..8ad4b88 100644 --- a/metadata.json +++ b/metadata.json @@ -63,6 +63,7 @@ ], "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 0.1.6"}, - {"name":"puppetlabs/java","version_requirement":">= 0.1.0"} + {"name":"puppetlabs/java","version_requirement":">= 0.1.0"}, + {"name":"nanliu/staging","version_requirement":">= 0.4.1 < 2.0.0"} ] } diff --git a/spec/classes/activemq_spec.rb b/spec/classes/activemq_spec.rb index e50cd78..685ce17 100644 --- a/spec/classes/activemq_spec.rb +++ b/spec/classes/activemq_spec.rb @@ -1,6 +1,13 @@ require 'spec_helper' describe 'activemq' do + let(:params) do + { + 'mq_admin_username' => 'admin', + 'mq_admin_password' => 'admin', + } + end + it "should compile" do should contain_class('activemq') end @@ -9,6 +16,7 @@ # debian-style multi-instance configurations it { should contain_file('activemq.xml') } + describe "#webconsole" do context "with the default template" do describe "true" do @@ -28,27 +36,90 @@ end end - context "/etc/init.d/activemq" do - it { should_not contain_file('/etc/init.d/activemq') } - context "RedHat" do - let(:facts) { {:osfamily => 'RedHat'} } - it { should contain_file('/etc/init.d/activemq') } + describe '#service' do + context "running" do + it { should contain_service('activemq').with_enable('true') } + end + + context "stoped" do + let (:params) { { 'ensure' => 'stopped' } } + it { should contain_service('activemq').with_enable('false') } + end + end + + + describe '#packages'do + + context "#install_from_binary = false (default)" do + it { should contain_package('activemq') } + + context "/etc/init.d/activemq" do + it { should_not contain_file('/etc/init.d/activemq') } + + context "RedHat" do + let(:facts) { {:osfamily => 'RedHat'} } + it { should contain_file('/etc/init.d/activemq') } + end + + context 'RedHat version <= 5.9' do + let(:facts) { {:osfamily => 'RedHat'} } + let(:params) { {:version => '5.8.5'} } + it { should contain_file('/etc/init.d/activemq') } + end + + context 'RedHat version >= 5.9' do + let(:facts) { {:osfamily => 'RedHat'} } + let(:params) { {:version => '5.9'} } + it { should_not contain_file('/etc/init.d/activemq') } + end + end end - context 'RedHat version <= 5.9' do - let(:facts) { {:osfamily => 'RedHat'} } - let(:params) { {:version => '5.8.5'} } + context "#install_from_binary = true" do + let(:params) do + { + :install_from_binary => true, + :package => 'http://www.eu.apache.org/dist/activemq/' \ + '5.13.0/apache-activemq-5.13.0-bin.tar.gz', + :system_user => 'activemq1', + :system_group => 'activemq2', + :home => '/tmp/activemq' + } + end + + it { should_not contain_package('activemq') } it { should contain_file('/etc/init.d/activemq') } + it { should contain_user(params[:system_user]).with_system(true) } + it { should contain_group(params[:system_group]).with_system(true) } + it { should contain_file(params[:home]).with_ensure('directory').with_owner(params[:system_user]) } + it { should contain_staging__file('apache-activemq-5.13.0-bin.tar.gz').with_source(params[:package]) } + it { should contain_staging__extract('apache-activemq-5.13.0-bin.tar.gz').with_target(params[:home])} + end - context 'RedHat version >= 5.9' do - let(:facts) { {:osfamily => 'RedHat'} } - let(:params) { {:version => '5.9'} } - it { should_not contain_file('/etc/init.d/activemq') } + end + + + describe '#config' do + context "#install_from_binary = false (default)" do + + end + + context "#install_from_binary = true" do + let(:params) do + { + :install_from_binary => true, + :package => 'http://download.nextag.com/apache/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz', + :home => '/var/tmp/activemq' + } + end + + it { should contain_file('activemq.xml').with_path("#{params[:home]}/conf/activemq.xml") } end end + describe "#instance" do context "Debian" do let(:facts) { {:osfamily => 'Debian'} } diff --git a/templates/activemq.xml.erb b/templates/activemq.xml.erb index 8d6fada..6d93274 100755 --- a/templates/activemq.xml.erb +++ b/templates/activemq.xml.erb @@ -6,7 +6,7 @@ http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"> -<% if @webconsole_real -%> +<% if @webconsole -%> file:${activemq.base}/conf/credentials.properties @@ -23,19 +23,19 @@ -<% if @mq_cluster_brokers_real.length > 1 -%> +<% if @mq_cluster_brokers.length > 1 -%> - <%- @mq_cluster_brokers_real.each do |broker| -%> + <%- @mq_cluster_brokers.each do |broker| -%> <%- if broker != mq_broker_name -%> -<% if @mq_cluster_brokers_real.length > 1 -%> - +<% if @mq_cluster_brokers.length > 1 -%> + <% end -%> - + @@ -109,7 +109,7 @@ -<% if @webconsole_real -%> +<% if @webconsole -%> <% end -%> diff --git a/templates/init/default/activemq b/templates/init/default/activemq new file mode 100755 index 0000000..dd5787b --- /dev/null +++ b/templates/init/default/activemq @@ -0,0 +1,94 @@ +#!/bin/sh +# ------------------------------------------------------------------------ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ------------------------------------------------------------------------ +# +# This script controls standalone Apache ActiveMQ service processes. +# To ensure compatibility to macosx and cygwin we do not utilize +# lsb standard infrastructure for controlling daemons like +# "start-stop-daemon". +# +# See also http://activemq.apache.org/activemq-command-line-tools-reference.html +# for additional commandline arguments +# +# Authors: +# Marc Schoechlin +# Adapted by Puppet Labs +# Shrinked to a wrapper over the init script that cames with a package to +# comply with the standard. + +# ------------------------------------------------------------------------ + +# activemq Apache ActiveMQ Service +# +# chkconfig: 345 24 76 +# +# description: Apache ActiveMQ Service +# +### BEGIN INIT INFO +# Provides: activemq +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start daemon at boot time +# Description: Enable service provided by daemon. +### END INIT INFO +# CONFIGURATION +ACTIVEMQ_PROCESS="activemq" +ACTIVEMQ_HOME='<%= @activemq_home -%>' +ACTIVEMQ_CONF='<%= @config_path -%>' +ACTIVEMQ_BASE="$ACTIVEMQ_HOME" +ACTIVEMQ_USER='<%= @system_user -%>' +ACTIVEMQ_BIN="${ACTIVEMQ_HOME}/bin/${ACTIVEMQ_PROCESS}" + + +show_help() { + cat << EOF +Tasks provided by the sysv init script: + restart - stop running instance (if there is one), start new instance + console - start broker in foreground, useful for debugging purposes + status - check if activemq process is running + +EOF + exit $RET +} + +# ------------------------------------------------------------------------ +# MAIN + +# show help +if [ -z "$1" ];then + show_help +fi + +case "$1" in + status) + su -s '/bin/sh' -c "${ACTIVEMQ_BIN} status" - $ACTIVEMQ_USER + ;; + restart) + $0 stop + $0 start + ;; + start) + su -s '/bin/sh' -c "${ACTIVEMQ_BIN} start" - $ACTIVEMQ_USER + ;; + console) + su -s '/bin/sh' -c "${ACTIVEMQ_BIN} console" - $ACTIVEMQ_USER + ;; + stop) + su -s '/bin/sh' -c "${ACTIVEMQ_BIN} stop" - $ACTIVEMQ_USER +esac diff --git a/templates/init/activemq b/templates/init/redhat/activemq similarity index 100% rename from templates/init/activemq rename to templates/init/redhat/activemq