From 77a974c051fbd7a907218c75a800497380152cce Mon Sep 17 00:00:00 2001 From: neillturner Date: Fri, 3 Jul 2015 14:05:21 +0100 Subject: [PATCH] joshbeard updates --- .fixtures.yml | 7 +- .gitignore | 3 + .puppet-lint.rc | 5 ++ .travis.yml | 63 ++++++++++-------- CONTRIBUTORS | 5 ++ Gemfile | 63 ++++++++++++++---- Modulefile | 13 ---- README.markdown | 16 +++-- Rakefile | 86 ++++++++++++++++++++++++- manifests/config.pp | 21 ++++-- manifests/init.pp | 16 +++-- manifests/install.pp | 99 +++++++++++++++++++---------- manifests/params.pp | 81 ++++++++++++----------- manifests/service.pp | 10 +-- metadata.json | 37 +++++++++++ spec/classes/crowd_spec.rb | 59 +++++++++-------- templates/crowd-init.properties.erb | 6 +- templates/etc/init.d/crowd.erb | 68 ++++++++++++++++++++ templates/jdbc.properties.erb | 6 +- templates/openidserver.xml.erb | 12 ++-- templates/setenv.sh.erb | 7 ++ 21 files changed, 493 insertions(+), 190 deletions(-) create mode 100644 .puppet-lint.rc create mode 100644 CONTRIBUTORS delete mode 100644 Modulefile create mode 100644 metadata.json create mode 100644 templates/etc/init.d/crowd.erb create mode 100644 templates/setenv.sh.erb diff --git a/.fixtures.yml b/.fixtures.yml index cbfd8a1..7b584f8 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,7 +1,6 @@ fixtures: repositories: - stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git" - wget: "git://github.com/maestrodev/puppet-wget.git" - deploy: "git://github.com/mkrakowitzer/puppet-deploy.git" + stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" + staging: "https://github.com/nanliu/puppet-staging" symlinks: - crowd: "#{source_dir}" \ No newline at end of file + crowd: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 1b736f1..969d4f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ +.bundle +.bundler .tmp .idea .swp Gemfile.lock +spec/fixtures diff --git a/.puppet-lint.rc b/.puppet-lint.rc new file mode 100644 index 0000000..4c18e01 --- /dev/null +++ b/.puppet-lint.rc @@ -0,0 +1,5 @@ +--fail-on-warnings +--with-filename +--no-80chars-check +--no-documentation-check +--no-class_inherits_from_params_class-check diff --git a/.travis.yml b/.travis.yml index 08a65c8..caf5700 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,40 @@ --- -branches: - only: - - master 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" +sudo: false +bundler_args: --without system_tests +script: + - "bundle exec puppet --version" + - "bundle exec rake validate" + - "bundle exec rake lint" + - "bundle exec rake spec SPEC_OPTS='--color --format documentation'" + - '[ "$PUPPET_GEM_VERSION" == ">= 3.7.0" ] && bundle exec rake future || exit 0' matrix: - exclude: - - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="~> 2.7.0" - - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="~> 2.7.0" - - 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" + fast_finish: true + allow_failures: + - env: PUPPET_GEM_VERSION="~> 4.0" ORDERING="random" STRICT_VARIABLES="yes" + - env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" + include: + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" + - rvm: 2.1 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" + - rvm: 2.1 + env: PUPPET_GEM_VERSION="~> 3.0" ORDERING="random" STRICT_VARIABLES="yes" FUTURE_PARSER="yes" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 4.0" ORDERING="random" STRICT_VARIABLES="yes" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 4.0" ORDERING="random" STRICT_VARIABLES="yes" + - rvm: 2.1 + env: PUPPET_GEM_VERSION="~> 4.0" ORDERING="random" STRICT_VARIABLES="yes" notifications: - email: false \ No newline at end of file + email: false diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..19ac1c8 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,5 @@ +Calum Lacroix, calum.lacroix@macmillan.com +Josh Beard, jbeard@usgs.gov +Josh Beard, josh@signalboxes.net +Martin Jackson, mjackson@equalexperts.com +Victor J. C. Geyer, victor@geyer.io diff --git a/Gemfile b/Gemfile index a29eac1..e373081 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,51 @@ -source 'https://rubygems.org' -puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7'] - -gem 'puppet', puppetversion - -group :test do - gem 'rake', '>= 0.9.0' - gem 'rspec', '>= 2.8.0' - gem 'rspec-puppet', '>= 0.1.1' - gem 'puppetlabs_spec_helper', '>= 0.4.1' - gem 'puppet-lint' -end \ No newline at end of file +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +def location_for(place, fake_version = nil) + if place =~ /^(git:[^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + +group :development, :unit_tests do + gem 'rake', :require => false + gem 'rspec-core', '3.1.7', :require => false + gem 'rspec-puppet', '~> 2.1', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'simplecov', :require => false + gem 'puppet_facts', :require => false + gem 'json', :require => false + gem 'metadata-json-lint', :require => false +end + +beaker_version = ENV['BEAKER_VERSION'] +beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] +group :system_tests do + if beaker_version + gem 'beaker', *location_for(beaker_version) + end + if beaker_rspec_version + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end + gem 'serverspec', :require => false +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/Modulefile b/Modulefile deleted file mode 100644 index 80e1687..0000000 --- a/Modulefile +++ /dev/null @@ -1,13 +0,0 @@ -name 'actionjack-crowd' -version '0.1.1' -source 'https://github.com/actionjack/puppet-crowd' -author 'actionjack' -license 'Apache License, Version 2.0' -summary 'Atlassian Crowd Puppet Module' -description "This puppet module is used to install and configure the crowd application. -Atlassian Crowd is a Single Sign-On (SSO) and Identity Management service." -project_page 'https://github.com/actionjack/puppet-crowd' - -dependency 'mkrakowitzer/deploy', '>= 0.0.1' -dependency 'maestrodev/wget', '>= 1.2.2' -dependency 'puppetlabs/stdlib', '>= 2.1.0' diff --git a/README.markdown b/README.markdown index 8ee1bd4..e636bac 100644 --- a/README.markdown +++ b/README.markdown @@ -1,11 +1,13 @@ # Atlassian Crowd Puppet Module -[![Build Status](https://travis-ci.org/actionjack/puppet-crowd.png?branch=master)](https://travis-ci.org/actionjack/puppet-crowd) +[![Build Status](https://travis-ci.org/joshbeard/puppet-crowd.png?branch=master)](https://travis-ci.org/joshbeard/puppet-crowd) This puppet module is used to install and configure the crowd application. Atlassian Crowd is a Single Sign-On (SSO) and Identity Management service. https://www.atlassian.com/software/crowd/overview + Forked from [https://github.com/actionjack/puppet-crowd](https://github.com/actionjack/puppet-crowd) + * * * ## Configuration @@ -16,8 +18,7 @@ Current dependencies are: * puppetlabs/stdlib - * mkrakowitzer/deploy - * maestrodev/wget + * nanliu/staging or puppetcommunity/staging ## Usage @@ -27,7 +28,8 @@ class {'crowd': } ## Documentation - This module is written in puppetdoc compliant format so details on configuration and usage can be found by executing: + This module is written in puppetdoc compliant format so details on + configuration and usage can be found by executing: ```bash $ puppet doc manifest/init.pp @@ -35,15 +37,17 @@ $ puppet doc manifest/init.pp ## Pull Requests - * Please submit a pull request or issue on [GitHub](https://github.com/actionjack/puppet-crowd) + * Please submit a pull request or issue on + [GitHub](https://github.com/joshbeard/puppet-crowd) -##Limitations +## Limitations This module has been built on and tested against Puppet 2.7 and higher. The module has been tested on: * Ubuntu 12.04 + * EL 6 The module has been tested against the following database(s): diff --git a/Rakefile b/Rakefile index f9c0cc1..0e65fb1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,86 @@ require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-syntax/tasks/puppet-syntax' require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.send('disable_class_inherits_from_params_class') -PuppetLint.configuration.send("disable_80chars") -PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" \ No newline at end of file +repo_dir = File.dirname(__FILE__) + +ignore_paths = [ + 'pkg/**/*.pp', + 'spec/**/*.pp', + 'tests/**/*.pp', +] + + +Rake::Task[:lint].clear +PuppetLint::RakeTask.new :lint do |config| + # Pattern of files to ignore + config.ignore_paths = ignore_paths + + # List of checks to disable + config.disable_checks = [ + '80chars', + 'class_inherits_from_params_class', + 'documentation', + ] + + # Should the task fail if there were any warnings, defaults to false + config.fail_on_warnings = true + + # Print out the context for the problem, defaults to false + config.with_context = true + + # Format string for puppet-lint's output (see the puppet-lint help output + # for details + config.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" + + # Compare module layout relative to the module root + # config.relative = true +end + +PuppetSyntax.exclude_paths = ignore_paths + +task :default => [ + :syntax, + :lint, + :spec, +] + +## Why not +task :future do |args| + PuppetSyntax.future_parser = true + Rake::Task[:syntax].invoke +end + +desc "Populate CONTRIBUTORS file" +task :contributors do + system("git log --format='%aN, %aE' | sort -u > CONTRIBUTORS") +end + +namespace :init do + task :bundler do + puts "=> Running 'bundle install'" + sh("bundle", "install") + end + + task :hooks do + puts "=> Copying git hooks to ./.git/hooks/" + sh("cp -rf #{repo_dir}/.githooks/* #{repo_dir}/.git/hooks") + end +end + +task :init do + Rake::Task['init:bundler'].invoke + Rake::Task['init:hooks'].invoke + + puts + puts "======================================================================" + puts "Repo initialized" + puts + puts "You should now have a development environment setup." + puts "Execute 'rake -T' to see the available rake tasks." + puts " For example: rake syntax" + puts + puts "pre-commit hooks for Git were also initialized. Whenever you commit," + puts "your changes will be validated against puppet syntax, puppet-lint," + puts "and Ruby validation (erb, yaml, json)." +end diff --git a/manifests/config.pp b/manifests/config.pp index d548842..b7d9dc9 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -5,21 +5,32 @@ require crowd File { - owner => $crowd::user, - group => $crowd::group, + owner => $crowd::user, + group => $crowd::group, mode => '0644', require => Class['crowd::install'], + notify => Class['crowd::service'], } - file {"${crowd::webappdir}/crowd-webapp/WEB-INF/classes/crowd-init.properties": + if ($crowd::java_home == undef) { + fail('Please set a value for the java_home parameter.') + } + + file { "${crowd::webappdir}/apache-tomcat/bin/setenv.sh": + ensure => 'file', + content => template('crowd/setenv.sh.erb'), + mode => '0755', + } + + file { "${crowd::webappdir}/crowd-webapp/WEB-INF/classes/crowd-init.properties": content => template('crowd/crowd-init.properties.erb'), } - file {"${crowd::webappdir}/apache-tomcat/conf/Catalina/localhost/openidserver.xml": + file { "${crowd::webappdir}/apache-tomcat/conf/Catalina/localhost/openidserver.xml": content => template('crowd/openidserver.xml.erb'), } - file {"${crowd::webappdir}/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties": + file { "${crowd::webappdir}/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties": content => template('crowd/jdbc.properties.erb'), } } diff --git a/manifests/init.pp b/manifests/init.pp index d2f02e6..3bad203 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,8 +3,6 @@ # # This module is used to install Crowd. # -# This module requires mkrakowitzer-deploy and maestrodev-wget -# # Format modeled on from @brycejohnson & @mkrakowitzer 's / puppet-jira module # # === Parameters @@ -56,13 +54,19 @@ $idjdbcversion = $crowd::params::idjdbcversion, # Misc Settings - $downloadURL = $crowd::params::downloadURL, + $download_url = $crowd::params::download_url, + $service_provider = $crowd::params::service_provider, + $service_enable = $crowd::params::service_enable, + $java_home = $crowd::params::java_home, + $jvm_xms = $crowd::params::jvm_xms, + $jvm_xmx = $crowd::params::jvm_xmx, + $jvm_opts = $crowd::params::jvm_opts, ) inherits crowd::params { - $webappdir = "${installdir}/atlassian-${product}-${version}-standalone" - $dburl = "jdbc:${db}://${dbserver}:${dbport}/${dbname}" - $iddburl = "jdbc:${iddb}://${iddbserver}:${iddbport}/${iddbname}" + $webappdir = "${installdir}/atlassian-${product}-${version}-standalone" + $dburl = "jdbc:${db}://${dbserver}:${dbport}/${dbname}" + $iddburl = "jdbc:${iddb}://${iddbserver}:${iddbport}/${iddbname}" include crowd::install include crowd::config diff --git a/manifests/install.pp b/manifests/install.pp index 98ae9a6..15ba2fe 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -4,58 +4,91 @@ require crowd + $_download_url = regsubst($::crowd::download_url, '\/$', '') + File { - owner => $crowd::user, - group => $crowd::group, + owner => $crowd::user, + group => $crowd::group, + } + + file { $crowd::installdir: + ensure => 'directory', } user { $crowd::user: - comment => 'Crowd daemon account', - shell => '/bin/true', - home => $crowd::homedir, - managehome => true, - } -> + comment => 'Crowd daemon account', + shell => '/sbin/nologin', + home => $crowd::homedir, + managehome => false, + } file { $crowd::homedir: ensure => 'directory', - recurse => true, - } -> + owner => $crowd::user, + group => $crowd::group, + mode => '0750', + require => File[$crowd::installdir], + } - file { $crowd::installdir: + case $crowd::service_provider { + upstart: { + file { '/etc/init/crowd.conf': + content => template('crowd/etc/init/crowd.conf.erb'), + mode => '0644', + } + } + init: { + file { '/etc/init.d/crowd': + ensure => 'file', + owner => 'root', + group => 'root', + content => template('crowd/etc/init.d/crowd.erb'), + mode => '0700' + } + } + default: { + warning("No init script provided for ${crowd::service_provider} provider.") + } + } + + file { "${crowd::installdir}/atlassian-${crowd::product}-${crowd::version}-standalone": ensure => 'directory', - } -> + } + + staging::file { "atlassian-${crowd::product}-${crowd::version}.${crowd::format}": + source => "${_download_url}/atlassian-${crowd::product}-${crowd::version}.${crowd::format}", + require => File["${crowd::installdir}/atlassian-${crowd::product}-${crowd::version}-standalone"], + } - deploy::file { "atlassian-${crowd::product}-${crowd::version}.${crowd::format}": + staging::extract { "atlassian-${crowd::product}-${crowd::version}.${crowd::format}": target => "${crowd::installdir}/atlassian-${crowd::product}-${crowd::version}-standalone", - url => $crowd::downloadURL, - strip => true, + strip => '1', + user => $crowd::user, + group => $crowd::group, + creates => "${crowd::installdir}/atlassian-${crowd::product}-${crowd::version}-standalone/apache-tomcat", notify => Exec["chown_${crowd::webappdir}"], - } -> - - - exec { "chown_${crowd::webappdir}": - command => "/bin/chown -R ${crowd::user}:${crowd::group} ${crowd::webappdir}", - refreshonly => true, - subscribe => User[$crowd::user] - } -> - - file { '/etc/init/crowd.conf': - content => template('crowd/etc/init/crowd.conf.erb'), - mode => '0644', - } -> + require => Staging::File["atlassian-${crowd::product}-${crowd::version}.${crowd::format}"], + } file { '/var/log/crowd': ensure => 'directory', } if $crowd::db == 'mysql' { - wget::fetch { 'mysql java connector': - source => "${crowd::mavenrepopath}/${crowd::jdbcversion}/mysql-connector-java-${crowd::jdbcversion}.jar", - destination => "${crowd::webappdir}/apache-tomcat/lib/mysql-connector-java-${crowd::jdbcversion}.jar", - timeout => 0, - verbose => true, - require => Exec["chown_${crowd::webappdir}"] + staging::file { 'mysql java connector': + source => "${crowd::mavenrepopath}/${crowd::jdbcversion}/mysql-connector-java-${crowd::jdbcversion}.jar", + target => "${crowd::webappdir}/apache-tomcat/lib/mysql-connector-java-${crowd::jdbcversion}.jar", + before => Exec["chown_${crowd::webappdir}"], } } + exec { "chown_${crowd::webappdir}": + command => "chown -R ${crowd::user}:${crowd::group} ${crowd::webappdir}", + unless => "find ${crowd::webappdir} ! -type l \\( ! -user ${crowd::user} -type f \\) -o \\( ! -group ${crowd::group} \\) -a \\( -type f \\)| wc -l | awk '{print \$1}' | grep -qE '^0'", + path => '/bin:/usr/bin', + subscribe => User[$crowd::user], + require => Staging::Extract["atlassian-${crowd::product}-${crowd::version}.${crowd::format}"], + } + + } diff --git a/manifests/params.pp b/manifests/params.pp index b7907a9..c780d48 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,61 +1,68 @@ # Class crowd::params # class crowd::params { - $version = '2.7.0' - $user = 'crowd' - $group = 'crowd' - $product = 'crowd' - $format = 'tar.gz' - $installdir = '/opt/crowd' - $homedir = '/var/crowd-home' - $db = 'mysql' - $dbuser = 'crowdadm' - $dbpassword = 'mypassword' - $dbserver = 'localhost' - $dbname = 'crowd' - $mavenrepopath = 'http://repo1.maven.org/maven2/mysql/mysql-connector-java' - $downloadURL = 'http://www.atlassian.com/software/crowd/downloads/binary/' + $version = '2.8.3' + $user = 'crowd' + $uid = undef + $group = 'crowd' + $product = 'crowd' + $service_provider = 'init' + $service_enable = true + $format = 'tar.gz' + $installdir = '/opt/crowd' + $homedir = '/var/crowd-home' + $db = 'mysql' + $dbuser = 'crowdadm' + $dbpassword = 'mypassword' + $dbserver = 'localhost' + $dbname = 'crowd' + $mavenrepopath = 'http://repo1.maven.org/maven2/mysql/mysql-connector-java' + $download_url = 'http://www.atlassian.com/software/crowd/downloads/binary/' + $java_home = undef + $jvm_xms = '256m' + $jvm_xmx = '512m' + $jvm_opts = '' -case $db { + case $db { 'mysql': { - $dbport = '3306' - $dbdriver = 'com.mysql.jdbc.Driver' - $jdbcversion = '5.1.26' - $dbtype = 'mysql5' + $dbport = '3306' + $dbdriver = 'com.mysql.jdbc.Driver' + $jdbcversion = '5.1.26' + $dbtype = 'mysql5' } 'postgres': { - $dbport = '5432' - $dbdriver = 'org.postgresql.Driver' - $dbtype = 'postgres72' - $jdbcversion = undef + $dbport = '5432' + $dbdriver = 'org.postgresql.Driver' + $dbtype = 'postgres72' + $jdbcversion = undef } default: { warning("Database type ${db} is not supported") } } - $iddb = 'mysql' - $iddbuser = 'idcrowdadm' - $iddbpassword = 'mypassword' - $iddbserver = 'localhost' - $iddbname = 'crowdiddb' + $iddb = 'mysql' + $iddbuser = 'idcrowdadm' + $iddbpassword = 'mypassword' + $iddbserver = 'localhost' + $iddbname = 'crowdiddb' case $iddb { 'mysql': { - $iddbport = '3306' - $iddbdriver = 'com.mysql.jdbc.Driver' - $idjdbcversion = '5.1.26' - $iddbtype = 'mysql5' + $iddbport = '3306' + $iddbdriver = 'com.mysql.jdbc.Driver' + $idjdbcversion = '5.1.26' + $iddbtype = 'mysql5' } 'postgres': { - $iddbport = '5432' - $iddbdriver = 'org.postgresql.Driver' - $iddbtype = 'postgres72' - $idjdbcversion = undef + $iddbport = '5432' + $iddbdriver = 'org.postgresql.Driver' + $iddbtype = 'postgres72' + $idjdbcversion = undef } default: { warning("Database type ${iddb} is not supported") } } -} \ No newline at end of file +} diff --git a/manifests/service.pp b/manifests/service.pp index 49396f1..8991bb5 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,10 +1,10 @@ -# Class crowd::install +# Class crowd::service # class crowd::service { - service { 'crowd': - ensure => 'running', - provider => 'upstart', - require => Class['crowd::config'], + ensure => 'running', + enable => $crowd::service_enable, + provider => $crowd::service_provider, + require => Class['crowd::config'], } } diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..bcffb09 --- /dev/null +++ b/metadata.json @@ -0,0 +1,37 @@ +{ + "name": "joshbeard-crowd", + "version": "0.1.8", + "author": "joshbeard", + "summary": "Atlassian Crowd Puppet Module", + "license": "Apache-2.0", + "source": "https://github.com/joshbeard/puppet-crowd", + "project_page": "https://github.com/joshbeard/puppet-crowd", + "issues_url": "https://github.com/joshbeard/puppet-crowd/issues", + "dependencies": [ + { + "name": "puppetlabs-stdlib", + "version_requirement": ">= 1.0.0" + }, + { + "name": "nanliu-staging", + "version_requirement": ">= 1.0.3" + } + ], + "operatingsystem_support": [ + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + } + ] +} diff --git a/spec/classes/crowd_spec.rb b/spec/classes/crowd_spec.rb index 1b98f46..d6bc19b 100644 --- a/spec/classes/crowd_spec.rb +++ b/spec/classes/crowd_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'crowd', :type => :class do - context 'As a Web Operations Engineer' do - context 'When I install the crowd base class on Ubuntu' do + context 'Basic install' do + context 'on Ubuntu' do let :facts do { :osfamily => 'Debian', :operatingsystem => 'Ubuntu' @@ -10,7 +10,8 @@ end let :params do { - :db => 'mysql' + :db => 'mysql', + :java_home => '/usr/java/default', } end @@ -22,13 +23,13 @@ should contain_file('/var/crowd-home').with( :ensure => 'directory' ) end it 'should start the crowd service using the crowd user' do - should contain_file('/etc/init/crowd.conf').with_content(/setuid\scrowd/) + should contain_file('/etc/init.d/crowd') end it 'should start the crowd service using the crowd group' do - should contain_file('/etc/init/crowd.conf').with_content(/setgid\scrowd/) + should contain_file('/etc/init.d/crowd') end it 'should have the correct base directory configured in the upstart script' do - should contain_file('/etc/init/crowd.conf').with_content(/env\sBASEDIR=.opt.crowd.atlassian-crowd-2.7.0-standalone.apache-tomcat/) + should contain_file('/etc/init.d/crowd') end it 'should create a directory for log output' do should contain_file('/var/log/crowd').with( :ensure => 'directory' ) @@ -37,53 +38,57 @@ should contain_file('/opt/crowd').with(:ensure => 'directory') end it 'should download and install the Atlassian Crowd application' do - should contain_deploy__file('atlassian-crowd-2.7.0.tar.gz').with( - :target => '/opt/crowd/atlassian-crowd-2.7.0-standalone', - :url => 'http://www.atlassian.com/software/crowd/downloads/binary/', - :strip => true, - :notify => 'Exec[chown_/opt/crowd/atlassian-crowd-2.7.0-standalone]' + should contain_staging__file('atlassian-crowd-2.8.3.tar.gz').with( + :source => 'http://www.atlassian.com/software/crowd/downloads/binary/atlassian-crowd-2.8.3.tar.gz' + ) + should contain_staging__extract('atlassian-crowd-2.8.3.tar.gz').with( + :target => '/opt/crowd/atlassian-crowd-2.8.3-standalone', + :strip => '1', + :user => 'crowd', + :group => 'crowd', + :creates => '/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat' ) end it 'should set the ownership of the application directory to the crowd user' do - should contain_exec('chown_/opt/crowd/atlassian-crowd-2.7.0-standalone').with( - :command => '/bin/chown -R crowd:crowd /opt/crowd/atlassian-crowd-2.7.0-standalone' + should contain_exec('chown_/opt/crowd/atlassian-crowd-2.8.3-standalone').with( + :command => 'chown -R crowd:crowd /opt/crowd/atlassian-crowd-2.8.3-standalone' ) end it 'should download and install the MySQL java connector for Crowd' do - should contain_wget__fetch('mysql java connector').with( - :source => 'http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.26/mysql-connector-java-5.1.26.jar', - :destination => '/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/lib/mysql-connector-java-5.1.26.jar' + should contain_staging__file('mysql java connector').with( + :source => 'http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.26/mysql-connector-java-5.1.26.jar', + :target => '/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/lib/mysql-connector-java-5.1.26.jar' ) end it 'should hava a crowd-init.properties file that points to the crowd user home directory' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/crowd-webapp/WEB-INF/classes/crowd-init.properties').with_content(/crowd.home=\/var\/crowd-home/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/crowd-webapp/WEB-INF/classes/crowd-init.properties').with_content(/crowd.home=\/var\/crowd-home/) end it 'should have a crowd-init.properties file that is world readable' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/crowd-webapp/WEB-INF/classes/crowd-init.properties').with( :mode => '0644') + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/crowd-webapp/WEB-INF/classes/crowd-init.properties').with( :mode => '0644') end it 'should have a username configured to access the Crowd ID Database' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/username="idcrowdadm"/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/username="idcrowdadm"/) end it 'should have a password configured to access the Crowd ID Database' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/password="mypassword"/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/password="mypassword"/) end it 'should define a mysql jdbc driver as the primary driver class'do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/driverClassName="com.mysql.jdbc.Driver"/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/driverClassName="com.mysql.jdbc.Driver"/) end it 'should have a valid jdbc connection string to a locally hosted crowd ID mysql database' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/url="jdbc:mysql:\/\/localhost:3306\/crowdiddb\?autoReconnect=true&useUnicode=true&characterEncoding=utf8"/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/url="jdbc:mysql:\/\/localhost:3306\/crowdiddb\?autoReconnect=true&useUnicode=true&characterEncoding=utf8"/) end it 'should have a valid mysql validation query' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/validationQuery="Select\s1"/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with_content(/validationQuery="Select\s1"/) end it 'should have a openidserver.xml file that is world readable' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with( :mode => '0644') + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/apache-tomcat/conf/Catalina/localhost/openidserver.xml').with( :mode => '0644') end it 'should have the hibernate dialect configured for MySQL Innodb' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties').with_content(/hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect/) + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties').with_content(/hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect/) end it 'should have a jdbc.properties file what it world readable' do - should contain_file('/opt/crowd/atlassian-crowd-2.7.0-standalone/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties').with( :mode => '0644') + should contain_file('/opt/crowd/atlassian-crowd-2.8.3-standalone/crowd-openidserver-webapp/WEB-INF/classes/jdbc.properties').with( :mode => '0644') end it 'should have the crowd service running' do should contain_service('crowd').with({ :ensure => 'running'}) @@ -92,4 +97,4 @@ end end end -end \ No newline at end of file +end diff --git a/templates/crowd-init.properties.erb b/templates/crowd-init.properties.erb index e90907e..020b265 100644 --- a/templates/crowd-init.properties.erb +++ b/templates/crowd-init.properties.erb @@ -3,6 +3,6 @@ # Any changes made here will be lost. ################################################## -<% if @homedir -%> -crowd.home=<%= @homedir %> -<% end -%> \ No newline at end of file +<% if scope.lookupvar('crowd::homedir') -%> +crowd.home=<%= scope.lookupvar('crowd::homedir') %> +<% end -%> diff --git a/templates/etc/init.d/crowd.erb b/templates/etc/init.d/crowd.erb new file mode 100644 index 0000000..0dc7279 --- /dev/null +++ b/templates/etc/init.d/crowd.erb @@ -0,0 +1,68 @@ +#!/bin/sh +# +# Crowd startup script +# +# chkconfig: 2345 80 05 +# +# description: Atlassian Crowd + +### BEGIN INIT INFO +# Provides: crowd +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2345 +# Default-Stop: 016 +# Short-Description: Start and stop the Atlassian Crowd service +# Description: Provides the crowd authentication service +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +RUN_AS_USER="<%= scope.lookupvar('crowd::user') %>" +CATALINA_HOME="<%= scope.lookupvar('crowd::webappdir') %>/apache-tomcat" +exec="${CATALINA_HOME}/bin/startup.sh" +pidfile="${CATALINA_HOME}/work/crowd.pid" + +crowd_start() { + [ -x $exec ] || exit 5 + echo -n $"Starting crowd: " + daemon --user "${RUN_AS_USER}" "${exec}" + retval=$? + echo + return $retval +} + +crowd_stop() { + echo -n $"Stopping crowd: " + killproc -p $pidfile + retval=$? + echo + return $retval +} + +crowd_status() { + status -p $pidfile crowd + retval=$? + echo + return $retval +} + +case "$1" in + start) + crowd_start + ;; + stop) + crowd_stop + ;; + status) + crowd_status + ;; + restart) + crowd_stop + sleep 10 + crowd_start + ;; + *) + echo "Usage: $0 {start|stop|status|restart}" +esac diff --git a/templates/jdbc.properties.erb b/templates/jdbc.properties.erb index a44939f..a21680f 100644 --- a/templates/jdbc.properties.erb +++ b/templates/jdbc.properties.erb @@ -3,11 +3,11 @@ # Any changes made here will be lost. ################################################## hibernate.max_fetch_depth=1 -<% if @iddb == 'mysql' -%> -hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect +<% if scope.lookupvar('crowd::iddb') == 'mysql' -%> +hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect <% end -%> hibernate.show_sql=false hibernate.jdbc.batch_size=0 hibernate.transaction.factory_class=org.hibernate.transaction.JDBCTransactionFactory hibernate.connection.datasource=java\:comp/env/jdbc/CrowdIDDS -hibernate.format_sql=true \ No newline at end of file +hibernate.format_sql=true diff --git a/templates/openidserver.xml.erb b/templates/openidserver.xml.erb index 97de245..1bcbbef 100644 --- a/templates/openidserver.xml.erb +++ b/templates/openidserver.xml.erb @@ -1,15 +1,15 @@ + username="<%= scope.lookupvar('crowd::iddbuser') %>" + password="<%= scope.lookupvar('crowd::iddbpassword') %>" + driverClassName="<%= scope.lookupvar('crowd::iddbdriver') %>" + url="<%= scope.lookupvar('crowd::iddburl') %>?autoReconnect=true&useUnicode=true&characterEncoding=utf8" + <% if scope.lookupvar('crowd::iddb') == 'mysql' %> validationQuery="Select 1" <% end %> /> - \ No newline at end of file + diff --git a/templates/setenv.sh.erb b/templates/setenv.sh.erb new file mode 100644 index 0000000..b945818 --- /dev/null +++ b/templates/setenv.sh.erb @@ -0,0 +1,7 @@ +JAVA_HOME="<%= scope.lookupvar('crowd::java_home') %>" +JAVA_OPTS="-Xms<%= scope.lookupvar('crowd::jvm_xms') %> -Xmx<%= scope.lookupvar('crowd::jvm_xmx') %> <%= scope.lookupvar('crowd::jvm_opts') %> -XX:MaxPermSize=256m -Dfile.encoding=UTF-8 $JAVA_OPTS" +CATALINA_PID="<%= scope.lookupvar('crowd::webappdir') %>/apache-tomcat/work/crowd.pid" + +export JAVA_HOME +export JAVA_OPTS +export CATALINA_PID