diff --git a/README b/README index 12f4ba7..fbf88a3 100644 --- a/README +++ b/README @@ -27,39 +27,40 @@ Module requirements Usage -class { "maven::maven" : } -> -class { "sonar" : - version => "2.11", +class { 'maven::maven' : } -> +class { 'sonar::server' : + version => '2.11', } - or - $jdbc = { - url => "jdbc:derby://localhost:1527/sonar;create=true", - driver_class_name => "org.apache.derby.jdbc.ClientDriver", - validation_query => "values(1)", - username => "sonar", - password => "sonar", + url => 'jdbc:derby://localhost:1527/sonar;create=true', + driver_class_name => 'org.apache.derby.jdbc.ClientDriver', + validation_query => 'values(1)', + username => 'sonar', + password => 'sonar', } -class { "maven::maven" : } -> -class { "sonar" : - arch => "linux-x86-64", - version => "2.11", - user => "sonar", - group => "sonar", - service => "sonar", - installroot => "/usr/local", - home => "/var/local/sonar", - download_url => "http://dist.sonar.codehaus.org" +class { 'maven::maven' : } -> +class { 'sonar::server' : + arch => 'linux-x86-64', + version => '2.11', + user => 'sonar', + group => 'sonar', + service => 'sonar', + installroot => '/usr/local', + home => '/var/local/sonar', + download_url => 'http://dist.sonar.codehaus.org' jdbc => $jdbc, - log_folder => "/var/local/sonar/logs", + log_folder => '/var/local/sonar/logs', } # Install a Sonar plugin -plugin { "sonar-twitter-plugin" : - groupid => "org.codehaus.sonar-plugins", - artifactid => "sonar-twitter-plugin", - version => "0.1", - notify => Service["sonar"], +sonar::plugin { 'sonar-twitter-plugin' : + groupid => 'org.codehaus.sonar-plugins', + artifactid => 'sonar-twitter-plugin', + version => '0.1', + sonar_home => '/var/local/sonar', + notify => Service['sonar'], } diff --git a/manifests/move_to_home.pp b/manifests/move_to_home.pp new file mode 100644 index 0000000..b3b3f80 --- /dev/null +++ b/manifests/move_to_home.pp @@ -0,0 +1,11 @@ +# copy folders susceptible to change from installation folder to /var/local/sonar and symlink +define sonar::move_to_home($sonar_home) { + file { "${sonar_home}/${name}": + ensure => directory, + } -> + + file { "${sonar::installdir}/${name}": + ensure => link, + target => "${sonar_home}/${name}", + } +} diff --git a/manifests/patch.pp b/manifests/patch.pp index b37fb5b..56f9e01 100644 --- a/manifests/patch.pp +++ b/manifests/patch.pp @@ -30,11 +30,11 @@ # patch => template("patch"), # } # -define patch($cwd = '.', $patch, $fuzz = 2) { +define sonar::patch( $patch, $cwd = '.', $fuzz = 2) { $patch_file = "${cwd}/patch_${name}.patch" - package { "patch": + package { 'patch': ensure => installed, } -> @@ -42,10 +42,10 @@ content => $patch, } -> exec { "patch_${name}": - path => "/bin:/usr/bin", - command => "patch -F ${fuzz} -b -p0 < ${patch_file} && touch ${patch_file}.applied", - cwd => $cwd, + path => '/bin:/usr/bin', + command => "patch -F ${fuzz} -b -p0 < ${patch_file} && touch ${patch_file}.applied", + cwd => $cwd, logoutput => true, - creates => "${patch_file}.applied", + creates => "${patch_file}.applied", } } diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 3c8ea54..139a16a 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -16,9 +16,11 @@ # # A puppet definition for Sonar plugin installation # -define plugin($groupid = "org.codehaus.sonar-plugins", $artifactid, $version, $ensure = present) { +define sonar::plugin( + $artifactid, $version, $sonar_home, + $groupid = 'org.codehaus.sonar-plugins', $ensure = present) { - $plugin_dir = "${sonar::home}/extensions/plugins" + $plugin_dir = "${sonar_home}/extensions/plugins" $plugin_name = "${artifactid}-${version}.jar" $plugin = "${plugin_dir}/${plugin_name}" @@ -27,11 +29,11 @@ # copy to a temp file as Maven can run as a different user and not have rights to copy to # sonar plugin folder maven { "/tmp/${plugin_name}": - groupid => $groupid, + groupid => $groupid, artifactid => $artifactid, - version => $version, - before => File[$plugin], - require => File[$plugin_dir], + version => $version, + before => File[$plugin], + require => File[$plugin_dir], } file { $plugin: ensure => $ensure, diff --git a/manifests/init.pp b/manifests/server.pp similarity index 55% rename from manifests/init.pp rename to manifests/server.pp index dc9393a..d779a71 100644 --- a/manifests/init.pp +++ b/manifests/server.pp @@ -12,73 +12,73 @@ # See the License for the specific language governing permissions and # limitations under the License. -class sonar( $version, $user = "sonar", $group = "sonar", $user_system = true, - $service = "sonar", $installroot = "/usr/local", $home = "/var/local/sonar", - $port = 9000, $download_url = "http://dist.sonar.codehaus.org", - $arch = "", $ldap = {}, +class sonar::server ( + $version = '2.13.1', + $user = 'sonar', + $group = 'sonar', + $user_system = true, + $service = 'sonar', $installroot = '/usr/local', $home = '/var/local/sonar', + $port = 9000, $download_url = 'http://dist.sonar.codehaus.org', + $arch = '', $ldap = {}, $jdbc = { - url => "jdbc:derby://localhost:1527/sonar;create=true", - driver_class_name => "org.apache.derby.jdbc.ClientDriver", - validation_query => "values(1)", - username => "sonar", - password => "sonar", + url => 'jdbc:derby://localhost:1527/sonar;create=true', + driver_class_name => 'org.apache.derby.jdbc.ClientDriver', + validation_query => 'values(1)', + username => 'sonar', + password => 'sonar', }, - $log_folder = "/var/local/sonar/logs", $profile = false) { + $log_folder = '/var/local/sonar/logs', $profile = false) { - Exec { path => "/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin" } - File { owner => $user, group => $group } + Exec { + path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin' + } + File { + owner => $user, + group => $group + } # wget from https://github.com/maestrodev/puppet-wget include wget # calculate in what folder is the binary to use for this architecture $arch1 = $::kernel ? { - "windows" => "windows", - "sunos" => "solaris", - "darwin" => "macosx", - default => "linux", + 'windows' => 'windows', + 'sunos' => 'solaris', + 'darwin' => 'macosx', + default => 'linux', } - if $arch1 != "macosx" { + if $arch1 != 'macosx' { $arch2 = $::architecture ? { - "x86_64" => "x86-64", - default => "x86-32", + 'x86_64' => 'x86-64', + default => 'x86-32', } } else { $arch2 = $::architecture ? { - "x86_64" => "universal-64", - default => "universal-32", + 'x86_64' => 'universal-64', + default => 'universal-32', } } - $bin_folder = $arch ? { "" => "${arch1}-${arch2}", default => $arch } + $bin_folder = $arch ? { '' => "${arch1}-${arch2}", default => $arch } $installdir = "${installroot}/${service}" $tmpzip = "/usr/local/src/${service}-${version}.zip" $script = "${installdir}/bin/${bin_folder}/sonar.sh" - # copy folders susceptible to change from installation folder to /var/local/sonar and symlink - define move_to_home() { - file { "${sonar::home}/${name}": - ensure => directory, - } -> - file { "${sonar::installdir}/${name}": - ensure => link, - target => "${sonar::home}/${name}", - } - } - user { "$user": + user { $user: ensure => present, home => $home, managehome => false, system => $user_system, } -> - group { "$group": + group { $group: ensure => present, system => $user_system, } -> - wget::fetch { "download": - source => "${download_url}/sonar-${version}.zip", - destination => $tmpzip, + wget::fetch { + 'download-sonar': + source => "${download_url}/sonar-${version}.zip", + destination => $tmpzip, } -> @@ -89,7 +89,7 @@ # Sonar home file { $home: ensure => directory, - mode => 0700, + mode => '0700', } -> file { "${installroot}/sonar-${version}": ensure => directory, @@ -98,29 +98,32 @@ ensure => link, target => "${installroot}/sonar-${version}", } -> - move_to_home { "data": } -> - move_to_home { "extras": } -> - move_to_home { "extensions": } -> - move_to_home { "logs": } -> - + sonar::move_to_home { 'data': + sonar_home => $home } -> + sonar::move_to_home { 'extras': + sonar_home => $home } -> + sonar::move_to_home { 'extensions': + sonar_home => $home } -> + sonar::move_to_home { 'logs': + sonar_home => $home } # ===== Install Sonar ===== - exec { "untar": + exec { 'untar': command => "unzip -o ${tmpzip} -d ${installroot} && chown -R ${user}:${group} ${installroot}/sonar-${version}", creates => "${installroot}/sonar-${version}/bin", } -> - exec { "run_as_user": + exec { 'run_as_user': command => "mv -f ${script} ${script}.bak && sed -e 's/#RUN_AS_USER=/RUN_AS_USER=${user}/' ${script}.bak > ${script}", unless => "grep RUN_AS_USER=${user} ${script}", } -> - exec { "pid_dir": + exec { 'pid_dir': command => "mv -f ${script} ${script}.bak && sed -e 's@PIDDIR=\"\\.\"@PIDDIR=\"${sonar::home}/logs\"@' ${script}.bak > ${script}", unless => "grep PIDDIR=\\\"${sonar::home}/logs\\\" ${script}", } -> file { $script: - mode => 755, - require => Exec["run_as_user"], # to override puppet autorequirement + mode => '0755', + require => Exec['run_as_user'], # to override puppet autorequirement } -> file { "/etc/init.d/${service}": ensure => link, @@ -129,43 +132,45 @@ # Sonar configuration files file { "${installdir}/conf/sonar.properties": - content => template("sonar/sonar.properties.erb"), - require => Exec["untar"], - notify => Service[$service], + content => template('sonar/sonar.properties.erb'), + require => Exec['untar'], + replace => false, + notify => Service[$service], } -> # The plugins directory. Useful to later reference it from the plugin definition file { "${home}/extensions/plugins": ensure => directory, } -> - plugin { "sonar-ldap-plugin" : - artifactid => "sonar-ldap-plugin", - version => "1.0", - ensure => empty($ldap) ? {true => absent, false => present}, - notify => Service[$service], + sonar::plugin { 'sonar-ldap-plugin' : + ensure => empty($ldap) ? {true => absent, false => present}, + artifactid => 'sonar-ldap-plugin', + version => '1.0', + sonar_home => $home, + notify => Service[$service], } -> service { $service: - name => $service, - ensure => running, + ensure => running, + name => $service, hasrestart => true, - hasstatus => true, - enable => true, + hasstatus => true, + enable => true, } # we need to patch the init.d scripts until Sonar 2.12 # https://github.com/SonarSource/sonar/pull/15 - if $version in ["2.5", "2.6", "2.10", "2.11"] { - patch { "initd": - cwd => $installdir, - patch => template("sonar/sonar-${version}.patch"), - require => Exec["untar"], - before => Service[$service], + if $version in ['2.5', '2.6', '2.10', '2.11'] { + sonar::patch { 'initd': + cwd => $installdir, + patch => template("sonar/sonar-${version}.patch"), + require => Exec['untar'], + before => Service[$service], } # set the right log location, not needed in Sonar 2.12+ file { "${installdir}/conf/logback.xml": - content => template("sonar/logback.xml.erb"), - require => Exec["untar"], + content => template('sonar/logback.xml.erb'), + require => Exec['untar'], notify => Service[$service], } }