Skip to content
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
21 changes: 13 additions & 8 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
# General settings
default['sonar']['dir'] = "/opt/sonar"
default['sonar']['version'] = "2.11"
default['sonar']['checksum'] = "9d05e25ca79c33d673004444d89c8770"
default['sonar']['os_kernel'] = "linux-x86-32"
default['sonar']['name'] = "sonarqube"
default['sonar']['version'] = "4.0"
default['sonar']['os_kernel'] = "#{node['os']}-#{node['kernel']['machine'].gsub('_', '-')}"
default['sonar']['install_dir'] = "/opt"
default['sonar']['home'] = File.join(node['sonar']['install_dir'], node['sonar']['name'])
default['sonar']['conf_dir'] = File.join(node['sonar']['home'], 'conf')
default['sonar']['log_dir'] = File.join(node['sonar']['home'], 'logs')
default['sonar']['bin_dir'] = File.join(node['sonar']['home'], 'bin', node['sonar']['os_kernel'])
default['sonar']['zip_file'] = "#{node['sonar']['name']}-#{node['sonar']['version']}.zip"
default['sonar']['checksum'] = "01e036c265bac46105515eb8a753bc02208c9a22b198bc846acf2e752ea133e5"
default['sonar']['mirror'] = "http://dist.sonar.codehaus.org"
default['sonar']['install_package'] = false

# Web settings
# The default listen port is 9000, the default context path is / and Sonar listens by default to all network interfaces : '0.0.0.0'.
# Once launched, the Sonar web server is available on http://localhost:9000. Parameters can be changed into the file conf/sonar.properties.
# Here is an example to listen to http://localhost:80/sonar:
default['sonar']['web_host'] = "0.0.0.0"
default['sonar']['web_port'] = "9000"
default['sonar']['web_domain'] = "sonar.example.com"
default['sonar']['web_domain'] = node['fqdn']
default['sonar']['web_context'] = "/"
default['sonar']['web_template'] = "default"

# Database settings
# @see conf/sonar.properties for examples for different databases
default['sonar']['jdbc_username'] = "sonar"
default['sonar']['jdbc_password'] = "sonar"
default['sonar']['jdbc_url'] = "jdbc:derby://localhost:1527/sonar;create=true"
default['sonar']['jdbc_driverClassName'] = "org.apache.derby.jdbc.ClientDriver"
default['sonar']['jdbc_validationQuery'] = "values(1)"
default['sonar']['jdbc_url'] = "jdbc:h2:tcp://localhost:9092/sonar"

# Wrapper settings eg. for performance improvements
# @see http://docs.codehaus.org/display/SONAR/Performances
Expand Down
18 changes: 18 additions & 0 deletions files/default/sonar_initd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO

/usr/bin/sonar $*
2 changes: 1 addition & 1 deletion files/default/tests/minitest/default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

describe "installs" do
it "installs the files to the correct folder" do
directory(node['sonar']['dir']).must_exist
directory(node['sonar']['home']).must_exist
end

# TODO ct 2012-06-27 How to check sonar process?
Expand Down
6 changes: 3 additions & 3 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
license "Apache 2.0"
description "Installs/Configures sonar"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.4"
version "0.0.6"
recipe "sonar", "Includes the recipe to download and configure a sonar server"
recipe "sonar::database_mysql", "Includes the recipe to install MySql-Server and create a database for sonar"
recipe "sonar::proxy_apache", "Includes the recipe to install Apache-Webserver and proxy modules to access sonar. Creates a host for sonar."
recipe "sonar::proxy_nginx", "Includes the recipe to install Nginx-Webserver and configures proxy to access sonar. Creates a host for sonar."

%w{ debian ubuntu }.each do |os|
%w{ debian ubuntu redhat centos }.each do |os|
supports os
end

%w{ java }.each do |cb|
%w{ java nginx }.each do |cb|
depends cb
end

Expand Down
49 changes: 49 additions & 0 deletions recipes/_source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# Cookbook Name:: sonar
# Recipe:: _source
#
# Copyright 2011, Christian Trabold
# Copyright 2014, Ilja Bobkevic
#
# Licensed 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.
#

package "unzip"

zip_file_path = File.join(node['sonar']['install_dir'], node['sonar']['zip_file'])
sonar_dir = File.join(node['sonar']['install_dir'], "#{node['sonar']['name']}-#{node['sonar']['version']}")

remote_file zip_file_path do
source "#{node['sonar']['mirror']}/#{node['sonar']['zip_file']}"
mode "0644"
checksum "#{node['sonar']['checksum']}"
not_if { ::File.exists?(zip_file_path) }
end

execute "unzip #{zip_file_path} -d #{node['sonar']['install_dir']}" do
not_if { ::File.directory?(sonar_dir) }
end

link node['sonar']['home'] do
to sonar_dir
end

link File.join(node['sonar']['bin_dir'], 'sonar.sh') do
to '/usr/bin/sonar'
end

cookbook_file 'sonar_initd' do
path '/etc/init.d/sonar'
mode 00755
action :create
end
2 changes: 1 addition & 1 deletion recipes/database_mysql.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include_recipe "mysql::server"

# Setup sonar user
grants_path = "/opt/sonar/extras/database/mysql/create_database.sql"
grants_path = "#{node['sonar']['home']}/extras/database/mysql/create_database.sql"

template grants_path do
source "create_mysql_database.sql.erb"
Expand Down
47 changes: 22 additions & 25 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Recipe:: default
#
# Copyright 2011, Christian Trabold
# Copyright 2014, Ilja Bobkevic
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,48 +20,44 @@

include_recipe "java"

package "unzip"

remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do
source "#{node['sonar']['mirror']}/sonar-#{node['sonar']['version']}.zip"
mode "0644"
checksum "#{node['sonar']['checksum']}"
not_if { ::File.exists?("/opt/sonar-#{node['sonar']['version']}.zip") }
end

execute "unzip /opt/sonar-#{node['sonar']['version']}.zip -d /opt/" do
not_if { ::File.directory?("/opt/sonar-#{node['sonar']['version']}/") }
end

link "/opt/sonar" do
to "/opt/sonar-#{node['sonar']['version']}"
if node['sonar']['install_package']
package 'sonar'
else
include_recipe 'sonar::_source'
end

service "sonar" do
stop_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh stop"
start_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh start"
status_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh status"
restart_command "sh /opt/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh restart"
action :start
service 'sonar' do
supports :status => true, :restart => true
action [ :enable, :start ]
end

template "sonar.properties" do
path "/opt/sonar/conf/sonar.properties"
path File.join(node['sonar']['conf_dir'], 'sonar.properties')
source "sonar.properties.erb"
owner "root"
group "root"
mode 0644
mode 0444
variables(
:options => node['sonar']['options']
)
notifies :restart, resources(:service => "sonar")
end

template "wrapper.conf" do
path "/opt/sonar/conf/wrapper.conf"
path File.join(node['sonar']['conf_dir'], 'wrapper.conf')
source "wrapper.conf.erb"
owner "root"
group "root"
mode 0644
mode 0444
notifies :restart, resources(:service => "sonar")
end

execute 'symlink-sonar-logs-directory' do
command "ln -s #{File.join(node['sonar']['log_dir'])} /var/log/sonar"
not_if { File.exists?('/var/log/sonar') }
end

execute 'symlink-sonar-conf-directory' do
command "ln -s #{File.join(node['sonar']['conf_dir'])} /etc/sonar"
not_if { File.exists?('/etc/sonar') }
end
4 changes: 2 additions & 2 deletions recipes/proxy_nginx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
source "nginx_site_#{node['sonar']['web_template']}.erb"
owner "root"
group "root"
mode 0644
mode 0444
end

nginx_site "sonar_server.conf" do
enable :true
end
end
Loading