Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node value for Apache Proxy #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
34 changes: 31 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ This cookbook basically translates the install instructions from http://docs.cod
= REQUIREMENTS:

* java + jdk
* A database cookbook like 'mysql' if you like to run sonar in production.
The built in derby database is not recommended for production.
* A database cookbook like 'mysql' if you like to run sonar in production. The built in derby database is not recommended for production. However, make sure 'bind-address' value is correctly configured in the MySQL side. Recommended configuration to work with this Sonar recipe:

node['mysql']['bind_address'] = 'localhost'

= ATTRIBUTES:

Expand All @@ -17,9 +18,36 @@ See attributes/default.rb for details.
The cookbook installs sonar with derby database (default).
Inlcude a proxy_* recipe to your run_list to access sonar over a proxy server.

A possible role definition, given as example, to put into roles/metrics-server.rb :

name "metrics-server"

description "Roles for a Metrics server"

# List of recipes and roles to apply. Requires Chef 0.8, earlier versions use 'recipes()'.
run_list "recipe[mysql::server]",
"recipe[apache2]",
"recipe[sonar]",
"recipe[sonar::database_mysql]",
"recipe[sonar::proxy_apache]"

# Attributes applied no matter what the node has set already.
override_attributes 'sonar' => {
'web_domain' => 'metrics.example.com',
'dir' => '/usr/share',
'version' => '2.13.1',
'os_kernel' => 'linux-x86-64',
'jdbc_username' => "sonar",
'jdbc_password' => "sonar",
'jdbc_url' => "jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8",
'jdbc_driverClassName' => "com.mysql.jdbc.Driver",
'jdbc_validationQuery' => "select 1"
}, 'mysql' => {
'bind_address' => 'localhost'
}

= Todos

* Implement 'dir' attribute to make installation path more flexible
* Implement different Database backends like MySql
* Implement plugin recipes eg. http://docs.codehaus.org/display/SONAR/PHP+Plugin
Download jars to plugin folder, restart Sonar
9 changes: 6 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# General settings
default['sonar']['dir'] = "/opt/sonar"
default['sonar']['version'] = "2.11"
default['sonar']['checksum'] = "9d05e25ca79c33d673004444d89c8770"
default['sonar']['dir'] = "/opt"
default['sonar']['version'] = "2.13.1"
default['sonar']['checksum'] = "37e0502e07e197b8e3a382c64fac8e1d"
default['sonar']['os_kernel'] = "linux-x86-32"
default['sonar']['mirror'] = "http://dist.sonar.codehaus.org"

Expand Down Expand Up @@ -30,3 +30,6 @@
default['sonar']['java_command'] = "java"
default['sonar']['logfile_maxsize'] = "0"
default['sonar']['syslog_loglevel'] = "NONE"

# Sonar Plugin settings
default['sonar']['plugin_php']['url'] = 'http://repository.codehaus.org/org/codehaus/sonar-plugins/php/sonar-php-plugin/1.0/sonar-php-plugin-1.0.jar'
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
attribute "sonar/dir",
:display_name => "Sonar directory",
:description => "Path to sonar",
:default => "/opt/sonar"
:default => "/opt"

attribute "sonar/version",
:display_name => "Sonar version",
Expand Down
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']['dir']}/sonar/extras/database/mysql/create_database.sql"

template grants_path do
source "create_mysql_database.sql.erb"
Expand Down
24 changes: 12 additions & 12 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@

package "unzip"

remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do
remote_file "#{node['sonar']['dir']}/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")}
not_if {File.exists?("#{node['sonar']['dir']}/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']}/")}
execute "unzip #{node['sonar']['dir']}/sonar-#{node['sonar']['version']}.zip -d #{node['sonar']['dir']}/" do
not_if {File.directory?("#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}/")}
end

link "/opt/sonar" do
to "/opt/sonar-#{node['sonar']['version']}"
link "#{node['sonar']['dir']}/sonar" do
to "#{node['sonar']['dir']}/sonar-#{node['sonar']['version']}"
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"
stop_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh stop"
start_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh start"
status_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh status"
restart_command "sh #{node['sonar']['dir']}/sonar/bin/#{node['sonar']['os_kernel']}/sonar.sh restart"
action :start
end

template "sonar.properties" do
path "/opt/sonar/conf/sonar.properties"
path "#{node['sonar']['dir']}/sonar/conf/sonar.properties"
source "sonar.properties.erb"
owner "root"
group "root"
Expand All @@ -54,7 +54,7 @@
end

template "wrapper.conf" do
path "/opt/sonar/conf/wrapper.conf"
path "#{node['sonar']['dir']}/sonar/conf/wrapper.conf"
source "wrapper.conf.erb"
owner "root"
group "root"
Expand Down
86 changes: 86 additions & 0 deletions recipes/plugin_php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#
# Cookbook Name:: sonar
# Recipe:: default
#
# Copyright 2012, Fabien Udriot
#
# 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.
#

include_recipe "php"

# INSTALL PHP MODULE FROM PACKAGE
package "php5-mysql"
package "php5-xdebug"
package "make"

# UPGRADE PEAR
php_pear "PEAR" do
action :upgrade
end

# REGISTER NEW PEAR CHANNELS
['pear.phpqatools.org', 'pear.symfony-project.com', 'pear.phpunit.de', 'pear.phpmd.org', 'pear.pdepend.org', 'components.ez.no', 'pear.typo3.org'].each do |channel|
php_pear_channel channel do
#action [:discover, :update]
action :discover
end
end

# INSTALL PACKAGE
php_pear "phpqatools" do
channel "pear.phpqatools.org"
options "--alldeps"
action :install
end

php_pear "PHP_CodeSniffer" do
channel "pear.php.net"
options "--alldeps"
action :install
end

php_pear "PHPUnit" do
channel "pear.phpunit.de"
options "--alldeps"
action :install
end

php_pear "PHP_PMD" do
channel "pear.phpmd.org"
options "--alldeps"
action :install
end

php_pear "PHPCS_TYPO3_SniffPool" do
channel "pear.typo3.org"
options "--alldeps"
action :install
end

php_pear "PHPCS_TYPO3v4_Standard" do
channel "pear.typo3.org"
options "--alldeps"
action :install
end

bash "install-plugin-php" do
code <<-EOH
(cd #{node['sonar']['dir']}/sonar/extensions/plugins; wget #{node['sonar']['plugin_php']['url']})
EOH
notifies :restart, resources(:service => "sonar")
end

#service "sonar" do
# action :restart
#end
12 changes: 7 additions & 5 deletions recipes/proxy_apache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
include_recipe "apache2"

template "sonar_server.conf" do
path "#{node[:nginx][:dir]}/sites-enabled/"
path "#{node[:apache][:dir]}/sites-available/sonar"
source "apache_site.erb"
owner "root"
group "root"
Expand All @@ -48,10 +48,12 @@

if node['sonar']['enable_mod_proxy_ajp'] == true
include_recipe "apache2::mod_proxy_ajp"
else
else
include_recipe "apache2::mod_proxy"
end

apache_site "sonar_server.conf" do
enable :true
end
apache_site "sonar" do
enable true
notifies :restart, resources(:service => "apache2")
end

24 changes: 17 additions & 7 deletions templates/default/apache_site.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
ServerName <%= node['sonar']['web_domain'] %>
ServerAdmin admin@<%= node['sonar']['web_domain'] %>
ProxyPass / http://<%= node['sonar']['web_host'] %>:<%= node['sonar']['web_port'] %>/
ProxyPassReverse / http://<%= node['sonar']['web_host'] %>:<%= node['sonar']['web_port'] %>/
ErrorLog logs/<%= node['sonar']['web_domain'] %>/sonar/error.log
CustomLog logs/<%= node['sonar']['web_domain'] %>/sonar/access.log common
</VirtualHost>
ProxyRequests Off

# Local reverse proxy authorization override
# Most unix distribution deny proxy by default
# (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)
<Proxy http://<%= node['sonar']['web_domain'] %>:9000/*>
Order deny,allow
Allow from all
</Proxy>

ProxyPreserveHost On
ProxyPass / http://<%= node['sonar']['web_domain'] %>:<%= node['sonar']['web_port'] %>/
ProxyPassReverse / http://<%= node['sonar']['web_domain'] %>:<%= node['sonar']['web_port'] %>/

ErrorLog /var/log/apache2/sonar.error.log
CustomLog /var/log/apache2/sonar.access.log common
</VirtualHost>
Loading