Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
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
49 changes: 25 additions & 24 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
11 changes: 11 additions & 0 deletions manifests/move_to_home.pp
Original file line number Diff line number Diff line change
@@ -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}",
}
}
12 changes: 6 additions & 6 deletions manifests/patch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@
# 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,
} ->

file { $patch_file:
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",
}
}
14 changes: 8 additions & 6 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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,
Expand Down
141 changes: 73 additions & 68 deletions manifests/init.pp → manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} ->


Expand All @@ -89,7 +89,7 @@
# Sonar home
file { $home:
ensure => directory,
mode => 0700,
mode => '0700',
} ->
file { "${installroot}/sonar-${version}":
ensure => directory,
Expand All @@ -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,
Expand All @@ -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],
}
}
Expand Down