From db2e9b588050809416a58cecb30d31f9fc0aac0f Mon Sep 17 00:00:00 2001 From: "Diego F. Duarte" Date: Tue, 13 Oct 2015 10:34:29 -0300 Subject: [PATCH 1/2] Commit updates - Chef-Sonar --- Berksfile | 3 + Gemfile | 18 ++++ README.rdoc | 23 +++++ Thorfile | 12 +++ Vagrantfile | 90 ++++++++++++++++++ attributes/default.rb | 47 ++++------ chefignore | 94 +++++++++++++++++++ files/default/sonar-init | 86 +++++++++++++++++ metadata.rb | 36 ++++--- recipes/database_mysql.rb | 65 ++++++++++++- recipes/default.rb | 61 +++++++----- recipes/proxy_apache.rb | 2 +- recipes/proxy_nginx.rb | 2 +- templates/default/apache_site.erb | 10 ++ .../default/create_mysql_database.sql.erb | 4 +- templates/default/nginx_site.erb | 28 ++++++ templates/default/sonar.properties.erb | 21 ++--- templates/default/sv-bootsonar-log-run.erb | 2 + templates/default/sv-bootsonar-run.erb | 4 + .../integration/default/serverspec/db_spec.rb | 18 ++++ .../default/serverspec/main_spec.rb | 22 +++++ 21 files changed, 558 insertions(+), 90 deletions(-) create mode 100644 Berksfile create mode 100644 Gemfile create mode 100644 README.rdoc create mode 100644 Thorfile create mode 100644 Vagrantfile create mode 100644 chefignore create mode 100644 files/default/sonar-init create mode 100644 templates/default/apache_site.erb create mode 100644 templates/default/nginx_site.erb create mode 100644 templates/default/sv-bootsonar-log-run.erb create mode 100644 templates/default/sv-bootsonar-run.erb create mode 100644 test/integration/default/serverspec/db_spec.rb create mode 100644 test/integration/default/serverspec/main_spec.rb diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..967b9a7 --- /dev/null +++ b/Berksfile @@ -0,0 +1,3 @@ +source "https://supermarket.chef.io" + +metadata diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..19e399d --- /dev/null +++ b/Gemfile @@ -0,0 +1,18 @@ +source 'https://rubygems.org' + +gem 'berkshelf' + +# Uncomment these lines if you want to live on the Edge: +# +# group :development do +# gem "berkshelf", github: "berkshelf/berkshelf" +# gem "vagrant", github: "mitchellh/vagrant", tag: "v1.6.3" +# end +# +# group :plugins do +# gem "vagrant-berkshelf", github: "berkshelf/vagrant-berkshelf" +# gem "vagrant-omnibus", github: "schisamo/vagrant-omnibus" +# end + +gem "test-kitchen" +gem "kitchen-vagrant" diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..5371ab8 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,23 @@ += DESCRIPTION: + +This cookbook basically translates the install instructions from http://docs.codehaus.org/display/SONAR/Install+Sonar#InstallSonar-Server into chef DSL. + += 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. + += ATTRIBUTES: + +See attributes/default.rb for details. + += USAGE: + +The cookbook installs sonar with derby database (default). +Inlcude a proxy_* recipe to your run_list to access sonar over a proxy server. + += Todos + +* Implement different Database backends like MySql +* Implement plugin recipes eg. http://docs.codehaus.org/display/SONAR/PHP+Plugin \ No newline at end of file diff --git a/Thorfile b/Thorfile new file mode 100644 index 0000000..7a0c0ff --- /dev/null +++ b/Thorfile @@ -0,0 +1,12 @@ +# encoding: utf-8 + +require 'bundler' +require 'bundler/setup' +require 'berkshelf/thor' + +begin + require "kitchen/thor_tasks" + Kitchen::ThorTasks.new +rescue LoadError + puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV["CI"] +end diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..af98caf --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,90 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = '2' + +Vagrant.require_version '>= 1.5.0' + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + config.vm.hostname = 'chef-sonar-berkshelf' + + # Set the version of chef to install using the vagrant-omnibus plugin + # NOTE: You will need to install the vagrant-omnibus plugin: + # + # $ vagrant plugin install vagrant-omnibus + # + if Vagrant.has_plugin?("vagrant-omnibus") + config.omnibus.chef_version = 'latest' + end + + # Every Vagrant virtual environment requires a box to build off of. + # If this value is a shorthand to a box in Vagrant Cloud then + # config.vm.box_url doesn't need to be specified. + config.vm.box = 'chef/ubuntu-14.04' + + + # Assign this VM to a host-only network IP, allowing you to access it + # via the IP. Host-only networks can talk to the host machine as well as + # any other machines on the same network, but cannot be accessed (through this + # network interface) by any external networks. + config.vm.network :private_network, type: 'dhcp' + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider :virtualbox do |vb| + # # Don't boot with headless mode + # vb.gui = true + # + # # Use VBoxManage to customize the VM. For example to change memory: + # vb.customize ["modifyvm", :id, "--memory", "1024"] + # end + # + # View the documentation for the provider you're using for more + # information on available options. + + # The path to the Berksfile to use with Vagrant Berkshelf + # config.berkshelf.berksfile_path = "./Berksfile" + + # Enabling the Berkshelf plugin. To enable this globally, add this configuration + # option to your ~/.vagrant.d/Vagrantfile file + config.berkshelf.enabled = true + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to exclusively install and copy to Vagrant's shelf. + # config.berkshelf.only = [] + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to skip installing and copying to Vagrant's shelf. + # config.berkshelf.except = [] + + config.vm.provision :chef_solo do |chef| + chef.json = { + mysql: { + server_root_password: 'rootpass', + server_debian_password: 'debpass', + server_repl_password: 'replpass' + } + } + + chef.run_list = [ + 'recipe[chef-sonar::default]' + ] + end +end diff --git a/attributes/default.rb b/attributes/default.rb index d802e6d..822d871 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,36 +1,27 @@ # 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']['mirror'] = "http://dist.sonar.codehaus.org" +include_attribute "java" + +node.override['java']['accept_license_agreement'] = true +node.override['java']['oracle']['accept_oracle_download_terms'] = true +node.override['java']['jdk_version'] = '7' +node.override['java']['install_flavor'] = 'oracle' +default['sonar']['dir'] = "/opt/sonar" +default['sonar']['version'] = "5.1.2" +default['sonar']['checksum'] = "795d0dd0a56b4d10966178160b950e20" +default['sonar']['os_kernel'] = "linux-x86-64" # 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_context'] = "/" -default['sonar']['web_template'] = "default" +default['sonar']['web_host'] = "127.0.0.1" +default['sonar']['web_port'] = "9000" +default['sonar']['web_domain'] = node['fqdn'] +default['sonar']['web_context'] = "/" # 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)" - -# Wrapper settings eg. for performance improvements -# @see http://docs.codehaus.org/display/SONAR/Performances -default['sonar']['java_additional'] = "-server" -default['sonar']['java_initmemory'] = "256" -default['sonar']['java_maxmemory'] = "512" -default['sonar']['java_maxpermsize'] = "128m" -default['sonar']['java_command'] = "java" -default['sonar']['logfile_maxsize'] = "0" -default['sonar']['syslog_loglevel'] = "NONE" - -default['sonar']['options'] = {} +default['sonar']['jdbc_username'] = "sonar" +default['sonar']['jdbc_password'] = "password-changemepls" +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)" diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..138a808 --- /dev/null +++ b/chefignore @@ -0,0 +1,94 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING +CHANGELOG* + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/files/default/sonar-init b/files/default/sonar-init new file mode 100644 index 0000000..de9dc94 --- /dev/null +++ b/files/default/sonar-init @@ -0,0 +1,86 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: +### END INIT INFO + +SCRIPT="/opt/sonar/bin/linux-x86-64/sonar.sh" +RUNAS="root" +NAME="SonarQube" + +PIDFILE=/var/log/$NAME.pid +LOGFILE=/var/log/$NAME.log + +start() { + if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting service…' >&2 + local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!" + su -c "$CMD" $RUNAS > "$PIDFILE" + echo 'Service started' >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping service…' >&2 + kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" + echo 'Service stopped' >&2 +} + +uninstall() { + echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " + local SURE + read SURE + if [ "$SURE" = "yes" ]; then + stop + rm -f "$PIDFILE" + echo "Notice: log file was not removed: '$LOGFILE'" >&2 + update-rc.d -f remove + rm -fv "$0" + fi +} + +status() { + printf "%-50s" "Checking $NAME..." + if [ -f $PIDFILE ]; then + PID=$(cat $PIDFILE) + if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then + printf "%s\n" "The process appears to be dead but pidfile still exists" + else + echo "Running, the PID is $PID" + fi + else + printf "%s\n" "Service not running" + fi +} + + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + uninstall) + uninstall + ;; + restart) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|status|restart|uninstall}" +esac diff --git a/metadata.rb b/metadata.rb index 838ec8e..d9dc4dc 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,9 +1,10 @@ +name "chef-sonar" maintainer "Christian Trabold" maintainer_email "info@christian-trabold.de" license "Apache 2.0" description "Installs/Configures sonar" -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.4" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) +version "1.0.0" 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." @@ -13,25 +14,20 @@ supports os end -%w{ java }.each do |cb| - depends cb -end - -attribute "sonar/dir", - :display_name => "Sonar directory", - :description => "Path to sonar", - :default => "/opt/sonar" +#%w{ java }.each do |cb| +# depends cb +#end attribute "sonar/version", :display_name => "Sonar version", - :description => "The version will be used to download the sources for the given version from 'http://dist.sonar.codehaus.org/sonar-#version#.zip'", - :default => "2.11" - -attribute "sonar/checksum", - :display_name => "MD5 Checksum", - :description => "MD5 Checksum of download file" + :description => "The version will be used to download the sources for the given version from sonar website", + :default => "5.1.2" -attribute "sonar/os_kernel", - :display_name => "System architecture", - :description => "Choose which CPU your running sonar on. This modifies the start-script to your architecture.", - :default => "linux-x86-32" +depends 'maven' +depends 'java' +depends 'nginx' +depends 'apache2' +depends 'mysql' +depends 'database' +depends 'mysql2_chef_gem' +depends 'runit' diff --git a/recipes/database_mysql.rb b/recipes/database_mysql.rb index ba193ab..087cb93 100644 --- a/recipes/database_mysql.rb +++ b/recipes/database_mysql.rb @@ -1,17 +1,78 @@ +=begin + include_recipe "mysql::server" # Setup sonar user grants_path = "/opt/sonar/extras/database/mysql/create_database.sql" -template grants_path do +template "/opt/sonar/extras/database/mysql/create_database.sql" do + path grants_path source "create_mysql_database.sql.erb" owner "root" group "root" mode "0600" action :create - notifies :restart, resources(:service => "sonar") end execute "mysql-install-application-privileges" do command "/usr/bin/mysql -u root #{node[:mysql][:server_root_password].empty? ? '' : '-p' }#{node[:mysql][:server_root_password]} < #{grants_path}" end + +# Create database with mysql LWRP +#mysql_database "sonar" do +# host "localhost" +# username "root" +# password node[:mysql][:server_root_password] +# database "sonar" +# action :create_db +#end + +=end + +# create connection info as an external ruby hash + + +mysql_connection_info = { + :host => '127.0.0.1', + :username => 'root', + :password => 'myp4ssw0rd' +} + +mysql_service 'default' do + port '3306' + version '5.6' + initial_root_password 'myp4ssw0rd' + action [:create, :start] +end + +package 'ruby-dev' do + action :install +end + +package 'make' do + action :install +end + + + +mysql2_chef_gem 'default' do + action :install +end + +mysql_database 'sonar' do + connection( + :host => '127.0.0.1', + :username => 'root', + :password => 'myp4ssw0rd' + ) + action :create +end + +mysql_database_user node['sonar']['jdbc_username'] do + connection mysql_connection_info + password node['sonar']['jdbc_password'] + database_name 'sonar' + host '%' #some applications need this parameter set to all. But, you can change to 127.0.0.1, if desirable. + privileges [:all] + action :grant +end diff --git a/recipes/default.rb b/recipes/default.rb index 27f19a5..730a0c9 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,32 +17,31 @@ # limitations under the License. # -include_recipe "java" +include_recipe 'apt' +include_recipe 'ark' +include_recipe 'java' +include_recipe "maven" +include_recipe "chef-sonar::database_mysql" +include_recipe 'runit::default' package "unzip" remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do - source "#{node['sonar']['mirror']}/sonar-#{node['sonar']['version']}.zip" + #source "http://downloads.sonarsource.com/sonarqube/sonarqube-#{node['sonar']['version']}.zip" + source "https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-#{node['sonar']['version']}.zip" mode "0644" - checksum "#{node['sonar']['checksum']}" - not_if { ::File.exists?("/opt/sonar-#{node['sonar']['version']}.zip") } +# 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']}/") } + not_if {File.directory?("/opt/sonar-#{node['sonar']['version']}/")} end link "/opt/sonar" do - to "/opt/sonar-#{node['sonar']['version']}" + to "/opt/sonarqube-#{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" - action :start -end template "sonar.properties" do path "/opt/sonar/conf/sonar.properties" @@ -50,17 +49,31 @@ owner "root" group "root" mode 0644 - variables( - :options => node['sonar']['options'] - ) - notifies :restart, resources(:service => "sonar") + # notifies :restart, resources(:service => "sonar") end -template "wrapper.conf" do - path "/opt/sonar/conf/wrapper.conf" - source "wrapper.conf.erb" - owner "root" - group "root" - mode 0644 - notifies :restart, resources(:service => "sonar") +cookbook_file '/etc/init.d/sonar-init' do + source 'sonar-init' + owner 'root' + group 'root' + mode '0644' +end + +execute 'Transform_Sonar_Service_to_executable' do + command 'chmod +x /etc/init.d/sonar-init' + user 'root' + action :run 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 +end + +runit_service "bootsonar" + +include_recipe "chef-sonar::proxy_nginx" diff --git a/recipes/proxy_apache.rb b/recipes/proxy_apache.rb index 1d2075c..51102c4 100644 --- a/recipes/proxy_apache.rb +++ b/recipes/proxy_apache.rb @@ -40,7 +40,7 @@ template "sonar_server.conf" do path "#{node[:nginx][:dir]}/sites-enabled/" - source "apache_site_#{node['sonar']['web_template']}.erb" + source "apache_site.erb" owner "root" group "root" mode 0644 diff --git a/recipes/proxy_nginx.rb b/recipes/proxy_nginx.rb index c6f509d..7ec6245 100644 --- a/recipes/proxy_nginx.rb +++ b/recipes/proxy_nginx.rb @@ -21,7 +21,7 @@ template "sonar_server.conf" do path "#{node[:nginx][:dir]}/sites-available/sonar_server.conf" - source "nginx_site_#{node['sonar']['web_template']}.erb" + source "nginx_site.erb" owner "root" group "root" mode 0644 diff --git a/templates/default/apache_site.erb b/templates/default/apache_site.erb new file mode 100644 index 0000000..4e70d88 --- /dev/null +++ b/templates/default/apache_site.erb @@ -0,0 +1,10 @@ +ProxyRequests Off +ProxyPreserveHost On + + 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 + \ No newline at end of file diff --git a/templates/default/create_mysql_database.sql.erb b/templates/default/create_mysql_database.sql.erb index a332df4..cd3c7d3 100644 --- a/templates/default/create_mysql_database.sql.erb +++ b/templates/default/create_mysql_database.sql.erb @@ -7,5 +7,7 @@ CREATE DATABASE IF NOT EXISTS sonar CHARACTER SET utf8 COLLATE utf8_general_ci; +CREATE USER '<%= node['sonar']['jdbc_username'] %>' IDENTIFIED BY '<%= node['sonar']['jdbc_password'] %>'; +GRANT ALL ON sonar.* TO '<%= node['sonar']['jdbc_username'] %>'@'%' IDENTIFIED BY '<%= node['sonar']['jdbc_password'] %>'; GRANT ALL ON sonar.* TO '<%= node['sonar']['jdbc_username'] %>'@'localhost' IDENTIFIED BY '<%= node['sonar']['jdbc_password'] %>'; -FLUSH PRIVILEGES; +FLUSH PRIVILEGES; \ No newline at end of file diff --git a/templates/default/nginx_site.erb b/templates/default/nginx_site.erb new file mode 100644 index 0000000..432d992 --- /dev/null +++ b/templates/default/nginx_site.erb @@ -0,0 +1,28 @@ +# the server directive is nginx's virtual host directive +server { + # port to listen on. Can also be set to an IP:PORT + listen 80; + + # sets the domain[s] that this vhost server requests for + server_name <%= node['sonar']['web_domain'] %>; + + error_page 401 /error.php?c=401; + error_page 403 /error.php?c=403; + error_page 404 /error.php?c=404; + error_page 500 /error.php?c=500; + error_page 502 503 504 /error.php?c=50x; + + location =/error.php { + root /var/www/metrics.typo3.org/; + } + + location / { + proxy_pass http://<%= node['sonar']['web_host'] %>:<%= node['sonar']['web_port'] %>; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + } + + error_log <%= node['nginx']['log_dir'] %>/sonar-error.log; + access_log <%= node['nginx']['log_dir'] %>/sonar-access.log; +} diff --git a/templates/default/sonar.properties.erb b/templates/default/sonar.properties.erb index f403e35..9cc17ee 100644 --- a/templates/default/sonar.properties.erb +++ b/templates/default/sonar.properties.erb @@ -41,6 +41,7 @@ sonar.web.context: <%= node['sonar']['web_context'] %> # Permissions to create tables and indexes must be granted to JDBC user. # The schema must be created first. sonar.jdbc.username: <%= node['sonar']['jdbc_username'] %> +sonar.jdbc.user: <%= node['sonar']['jdbc_username'] %> sonar.jdbc.password: <%= node['sonar']['jdbc_password'] %> #----- Embedded database Derby @@ -48,9 +49,9 @@ sonar.jdbc.password: <%= node['sonar']['jdbc_password'] %> # sonar server and the maven plugin must be executed on the same host. # Comment the following lines to deactivate the default embedded database. -sonar.jdbc.url: <%= node['sonar']['jdbc_url'] %> -sonar.jdbc.driverClassName: <%= node['sonar']['jdbc_driverClassName'] %> -sonar.jdbc.validationQuery: <%= node['sonar']['jdbc_validationQuery'] %> +#sonar.jdbc.url: jdbc:derby://localhost:1527/sonar;create=true +#sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver +#sonar.jdbc.validationQuery: values(1) # directory containing Derby database files. By default it's the /data directory in the sonar installation. #sonar.embeddedDatabase.dataDir: @@ -62,9 +63,10 @@ sonar.jdbc.validationQuery: <%= node['sonar']['jdbc_validationQue #----- MySQL 5.x/6.x # Comment the embedded database and uncomment the following properties to use MySQL. The validation query is optional. -#sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 -#sonar.jdbc.driverClassName: com.mysql.jdbc.Driver -#sonar.jdbc.validationQuery: select 1 +sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 +#sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar +sonar.jdbc.driverClassName: com.mysql.jdbc.Driver +sonar.jdbc.validationQuery: select 1 #----- Oracle 10g/11g @@ -137,10 +139,3 @@ sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 #http.proxyUser= #http.proxyPassword= -# More options from Chef - -<% if @options -%> -<% @options.sort.map do | option, value | -%> -<%= option %>: <%= value %> -<% end -%> -<% end -%> diff --git a/templates/default/sv-bootsonar-log-run.erb b/templates/default/sv-bootsonar-log-run.erb new file mode 100644 index 0000000..22cc1a6 --- /dev/null +++ b/templates/default/sv-bootsonar-log-run.erb @@ -0,0 +1,2 @@ +#!/bin/sh +exec svlogd -tt ./main \ No newline at end of file diff --git a/templates/default/sv-bootsonar-run.erb b/templates/default/sv-bootsonar-run.erb new file mode 100644 index 0000000..b28e76d --- /dev/null +++ b/templates/default/sv-bootsonar-run.erb @@ -0,0 +1,4 @@ +#!/bin/sh + +exec 2>&1 +exec /opt/sonar/bin/linux-x86-64/sonar.sh start \ No newline at end of file diff --git a/test/integration/default/serverspec/db_spec.rb b/test/integration/default/serverspec/db_spec.rb new file mode 100644 index 0000000..783e3d7 --- /dev/null +++ b/test/integration/default/serverspec/db_spec.rb @@ -0,0 +1,18 @@ +require 'serverspec' + +describe package('mysql-server'), :if => os[:family] == 'ubuntu' do + it { should be_installed } + it { should be_running } +end + +describe port(3306) do + it { should be_listening} +end + +describe service('mysql') do + it { should be enabled } +end + +describe command("mysql -u root -pac4success -h 127.0.0.1 --port 3306 -e 'use sonar'") do + its(:stdout) { should eq 0 } +end diff --git a/test/integration/default/serverspec/main_spec.rb b/test/integration/default/serverspec/main_spec.rb new file mode 100644 index 0000000..46e4893 --- /dev/null +++ b/test/integration/default/serverspec/main_spec.rb @@ -0,0 +1,22 @@ +require 'serverspec' + +describe file('/opt/sonar/conf/sonar.properties') do + it { should contain /Generated by Chef/ } +end + +ports = [80, 9000, 9001] + +ports.each do |port| + describe port(port) do + it { should be_listening } + end +end + +describe host('google.com') do + it { should be_resolvable } +end + +describe command('/opt/sonar/bin/linux-x86-64/sonar.sh status') do + its(:stdout) {should match /SonarQube/} +end + From a0dc74dc791bc9bfe9110bbdf4dd760311493d54 Mon Sep 17 00:00:00 2001 From: "Diego F. Duarte" Date: Tue, 13 Oct 2015 10:36:21 -0300 Subject: [PATCH 2/2] fixing a last-time error --- test/integration/default/serverspec/db_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/default/serverspec/db_spec.rb b/test/integration/default/serverspec/db_spec.rb index 783e3d7..15d4258 100644 --- a/test/integration/default/serverspec/db_spec.rb +++ b/test/integration/default/serverspec/db_spec.rb @@ -13,6 +13,6 @@ it { should be enabled } end -describe command("mysql -u root -pac4success -h 127.0.0.1 --port 3306 -e 'use sonar'") do +describe command("mysql -u root -pmyp4ssw0rd -h 127.0.0.1 --port 3306 -e 'use sonar'") do its(:stdout) { should eq 0 } end