From d4be11c93d40c93b100cbb8c8ec5b76a87878ec5 Mon Sep 17 00:00:00 2001 From: "ilja.bobkevic" Date: Thu, 9 Jan 2014 16:15:24 +0100 Subject: [PATCH 1/3] Add redhat/centos package support. Update to sonar 4.0. 1. Use RPM for centos/redhat 2. Create initd file when installing zip 3. Update templates to match sonar 4.0 4. Minor bug fixes --- attributes/default.rb | 13 +- files/default/sonar_initd | 18 ++ metadata.rb | 6 +- recipes/_source.rb | 46 ++++++ recipes/default.rb | 38 ++--- recipes/proxy_nginx.rb | 4 +- templates/default/sonar.properties.erb | 218 ++++++++++++------------- templates/default/wrapper.conf.erb | 39 +++-- 8 files changed, 221 insertions(+), 161 deletions(-) create mode 100644 files/default/sonar_initd create mode 100644 recipes/_source.rb diff --git a/attributes/default.rb b/attributes/default.rb index d802e6d..8e25d85 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,9 +1,10 @@ # 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']['version'] = "4.0" +default['sonar']['checksum'] = "01e036c265bac46105515eb8a753bc02208c9a22b198bc846acf2e752ea133e5" +default['sonar']['os_kernel'] = "#{node['os']}-#{node['kernel']['machine'].gsub('_', '-')}" 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'. @@ -11,7 +12,7 @@ # 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" @@ -19,9 +20,7 @@ # @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 diff --git a/files/default/sonar_initd b/files/default/sonar_initd new file mode 100644 index 0000000..a293232 --- /dev/null +++ b/files/default/sonar_initd @@ -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 $* diff --git a/metadata.rb b/metadata.rb index 838ec8e..7a047df 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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.5" 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 diff --git a/recipes/_source.rb b/recipes/_source.rb new file mode 100644 index 0000000..a6ed5c7 --- /dev/null +++ b/recipes/_source.rb @@ -0,0 +1,46 @@ +# +# 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" + +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 node['sonar']['dir'] do + to "/opt/sonar-#{node['sonar']['version']}" +end + +link File.join(node['sonar']['dir'], 'bin', node['sonar']['os_kernel'], 'sonar.sh') do + to '/usr/bin/sonar' +end + +cookbook_file 'sonar_initd' do + path '/etc/init.d/sonar' + mode 00755 + action :create +end diff --git a/recipes/default.rb b/recipes/default.rb index 27f19a5..cbdb977 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -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. @@ -19,29 +20,15 @@ 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']}/") } +if node['sonar']['install_package'] + package 'sonar' +else + include_recipe 'sonar::_source' end -link "/opt/sonar" do - to "/opt/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" - action :start +service 'sonar' do + supports :status => true, :restart => true + action [ :enable, :start ] end template "sonar.properties" do @@ -49,7 +36,7 @@ source "sonar.properties.erb" owner "root" group "root" - mode 0644 + mode 0444 variables( :options => node['sonar']['options'] ) @@ -61,6 +48,11 @@ 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']['dir'], 'logs')} /var/log/sonar" + not_if { File.exists?('/var/log/sonar') } +end diff --git a/recipes/proxy_nginx.rb b/recipes/proxy_nginx.rb index c6f509d..1bd53fe 100644 --- a/recipes/proxy_nginx.rb +++ b/recipes/proxy_nginx.rb @@ -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 \ No newline at end of file +end diff --git a/templates/default/sonar.properties.erb b/templates/default/sonar.properties.erb index f403e35..b181b77 100644 --- a/templates/default/sonar.properties.erb +++ b/templates/default/sonar.properties.erb @@ -1,125 +1,117 @@ -# Generated by Chef. Local modifications will be overwritten. - -#-------------------------------------------------------- +# This file must contain only ISO 8859-1 characters +# see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream) +# # To use an environment variable, use the following syntax : ${env:NAME_OF_ENV_VARIABLE} -# For example : -# sonar.jdbc.url: ${env:SONAR_JDBC_URL} +# For example: +# sonar.jdbc.url= ${env:SONAR_JDBC_URL} # # # See also the file conf/wrapper.conf for JVM advanced settings -#--------------------------------------------------------- - - -#--------------------------------------------------------- -# WEB SETTINGS - STANDALONE MODE ONLY -# These settings are ignored when the war file is deployed to a JEE server. -#--------------------------------------------------------- -# Listen host/port and context path (for example / or /sonar). Default values are 0.0.0.0:9000/. -sonar.web.host: <%= node['sonar']['web_host'] %> -sonar.web.port: <%= node['sonar']['web_port'] %> -sonar.web.context: <%= node['sonar']['web_context'] %> -# Log HTTP requests. Deactivated by default. -#sonar.web.jettyRequestLogs: ../../logs/jetty-yyyy_mm_dd.request.log - -# Apache mod_jk connector. Supported only in standalone mode. -# Uncomment to activate AJP13 connector. -#sonar.ajp13.port: 8009 - - -#--------------------------------------------------------- +#-------------------------------------------------------------------------------------------------- # DATABASE # -# IMPORTANT : the embedded database Derby is used by default. -# It is recommended for tests only. Please use an other database -# for production environment (MySQL, Oracle, Postgresql, -# SQLServer) -# -#--------------------------------------------------------- +# IMPORTANT: the embedded H2 database is used by default. It is recommended for tests only. +# Please use a production-ready database. Supported databases are MySQL, Oracle, PostgreSQL +# and Microsoft SQLServer. -#----- Credentials -# Permissions to create tables and indexes must be granted to JDBC user. +# Permissions to create tables, indices and triggers must be granted to JDBC user. # The schema must be created first. -sonar.jdbc.username: <%= node['sonar']['jdbc_username'] %> -sonar.jdbc.password: <%= node['sonar']['jdbc_password'] %> - -#----- Embedded database Derby -# Note : it does accept connections from remote hosts, so the -# 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'] %> - -# directory containing Derby database files. By default it's the /data directory in the sonar installation. -#sonar.embeddedDatabase.dataDir: -# derby embedded database server listening port, defaults to 1527 -#sonar.derby.drda.portNumber: 1527 - -# uncomment to accept connections from remote hosts. Ba default it only accepts localhost connections. -#sonar.derby.drda.host: 0.0.0.0 - -#----- 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 - - -#----- Oracle 10g/11g -# To use Oracle database : -# - Copy the JDBC driver to extensions/jdbc-driver/oracle. -# - Comment the embedded database and uncomment the following properties. The validation query is optional. -#sonar.jdbc.url: jdbc:oracle:thin:@localhost/XE -#sonar.jdbc.driverClassName: oracle.jdbc.driver.OracleDriver -#sonar.jdbc.validationQuery: select 1 from dual - -# Activate if more than one Sonar Oracle schemas on the data server (for example different versions installed). -# In that case, use the same property during maven analysis (-Dsonar.hibernate.default_schema=xxx) -#sonar.hibernate.default_schema: sonar - -#----- PostgreSQL 8.x, 9.x -# Uncomment the following properties to use PostgreSQL. The validation query is optional. -#sonar.jdbc.url: jdbc:postgresql://localhost/sonar -#sonar.jdbc.driverClassName: org.postgresql.Driver -#sonar.jdbc.validationQuery: select 1 - - -#----- Microsoft SQLServer -# The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net -# The validation query is optional. -#sonar.jdbc.url: jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor -#sonar.jdbc.driverClassName: net.sourceforge.jtds.jdbc.Driver -#sonar.jdbc.validationQuery: select 1 - +sonar.jdbc.username=<%= node['sonar']['jdbc_username'] %> +sonar.jdbc.password=<%= node['sonar']['jdbc_password'] %> +sonar.jdbc.url=<%= node['sonar']['jdbc_url'] %> +<%- if node['sonar']['jdbc_schema'] -%> +sonar.jdbc.schema=<%= node['sonar']['jdbc_schema'] %> +<%- end -%> #----- Connection pool settings -sonar.jdbc.maxActive: 10 -sonar.jdbc.maxIdle: 5 -sonar.jdbc.minIdle: 2 -sonar.jdbc.maxWait: 5000 -sonar.jdbc.minEvictableIdleTimeMillis: 600000 -sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 - - -#----- JDBC Datasource bounded to JNDI -# When sonar webapp is deployed into a JEE server, the JDBC datasource can be configured into the JEE server and registered into JNDI. -# In such a case Sonar uses this datasource to connect to database. -# If you activate this feature, then the properties starting with "sonar.jdbc." can be commented, except "sonar.jdbc.dialect". -# The JDBC driver must still be deployed into the directory /extensions/jdbc-driver. -#sonar.jdbc.jndiName: jdbc/sonar - -# Values are : mysql, mssql, derby, oracle, postgresql -#sonar.jdbc.dialect= - - -#--------------------------------------------------------- +sonar.jdbc.maxActive=20 +sonar.jdbc.maxIdle=5 +sonar.jdbc.minIdle=2 +sonar.jdbc.maxWait=5000 +sonar.jdbc.minEvictableIdleTimeMillis=600000 +sonar.jdbc.timeBetweenEvictionRunsMillis=30000 + +#-------------------------------------------------------------------------------------------------- +# WEB SERVER + +# Binding IP address. For servers with more than one IP address, this property specifies which +# address will be used for listening on the specified ports. +# By default, ports will be used on all IP addresses associated with the server. +<%- if node['sonar']['web_host'] -%> +sonar.web.host=<%= node['sonar']['web_host'] %> +<%- end -%> + +# Web context. When set, it must start with forward slash (for example /sonarqube). +# The default value is root context (empty value). +<%- if node['sonar']['web_context'] -%> +sonar.web.context=<%= node['sonar']['web_context'] %> +<%- end -%> + +# TCP port for incoming HTTP connections. Disabled when value is -1. +<%- if node['sonar']['web_port'] -%> +sonar.web.port=<%= node['sonar']['web_port'] %> +<%- end -%> + +# TCP port for incoming HTTPS connections. Disabled when value is -1 (default). +#sonar.web.https.port=-1 + +# HTTPS - the alias used to for the server certificate in the keystore. +# If not specified the first key read in the keystore is used. +#sonar.web.https.keyAlias= + +# HTTPS - the password used to access the server certificate from the +# specified keystore file. The default value is "changeit". +#sonar.web.https.keyPass=changeit + +# HTTPS - the pathname of the keystore file where is stored the server certificate. +# By default, the pathname is the file ".keystore" in the user home. +# If keystoreType doesn't need a file use empty value. +#sonar.web.https.keystoreFile= + +# HTTPS - the password used to access the specified keystore file. The default +# value is the value of sonar.web.https.keyPass. +#sonar.web.https.keystorePass= + +# HTTPS - the type of keystore file to be used for the server certificate. +# The default value is JKS (Java KeyStore). +#sonar.web.https.keystoreType=JKS + +# HTTPS - the name of the keystore provider to be used for the server certificate. +# If not specified, the list of registered providers is traversed in preference order +# and the first provider that supports the keystore type is used (see sonar.web.https.keystoreType). +#sonar.web.https.keystoreProvider= + +# The maximum number of connections that the server will accept and process at any given time. +# When this number has been reached, the server will not accept any more connections until +# the number of connections falls below this value. The operating system may still accept connections +# based on the sonar.web.connections.acceptCount property. The default value is 50 for each +# enabled connector. +#sonar.web.http.maxThreads=50 +#sonar.web.https.maxThreads=50 + +# The minimum number of threads always kept running. The default value is 5 for each +# enabled connector. +#sonar.web.http.minThreads=5 +#sonar.web.https.minThreads=5 + +# The maximum queue length for incoming connection requests when all possible request processing +# threads are in use. Any requests received when the queue is full will be refused. +# The default value is 25 for each enabled connector. +#sonar.web.http.acceptCount=25 +#sonar.web.https.acceptCount=25 + +# Access logs are generated in the file logs/access.log. This file is rolled over when it's 5Mb. +# An archive of 3 files is kept in the same directory. +# Access logs are enabled by default. +#sonar.web.accessLogs.enable=true + + +#-------------------------------------------------------------------------------------------------- # UPDATE CENTER -#--------------------------------------------------------- # The Update Center requires an internet connection to request http://update.sonarsource.org -# It is activated by default: +# It is enabled by default. #sonar.updatecenter.activate=true # HTTP proxy (default none) @@ -137,7 +129,15 @@ sonar.jdbc.timeBetweenEvictionRunsMillis: 30000 #http.proxyUser= #http.proxyPassword= -# More options from Chef +#-------------------------------------------------------------------------------------------------- +# NOTIFICATIONS + +# Delay (in seconds) between processing of notification queue +sonar.notifications.delay=60 + +#-------------------------------------------------------------------------------------------------- +# OTHER OPTIONS +#-------------------------------------------------------------------------------------------------- <% if @options -%> <% @options.sort.map do | option, value | -%> diff --git a/templates/default/wrapper.conf.erb b/templates/default/wrapper.conf.erb index 54a7c6c..28509f7 100644 --- a/templates/default/wrapper.conf.erb +++ b/templates/default/wrapper.conf.erb @@ -1,10 +1,15 @@ # Java Additional Parameters wrapper.java.additional.1=-Djava.awt.headless=true wrapper.java.additional.2=-XX:MaxPermSize=<%= node['sonar']['java_maxpermsize'] %> +wrapper.java.additional.3=-XX:+HeapDumpOnOutOfMemoryError +wrapper.java.additional.4=-Dfile.encoding=UTF-8 +wrapper.java.additional.5=-Djruby.management.enabled=false # RECOMMENDED : uncomment if Java Virtual Machine is a JDK but not a JRE. To know which JVM you use, execute # 'java -version'. JDK displays 'Server VM'. -wrapper.java.additional.3=<%= node['sonar']['java_additional'] %> +<%- if node['sonar']['java_additional'] -%> +wrapper.java.additional.6=<%= node['sonar']['java_additional'] %> +<%- end -%> # Initial Java Heap Size (in MB) wrapper.java.initmemory=<%= node['sonar']['java_initmemory'] %> @@ -29,8 +34,8 @@ wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp # Java Classpath (include wrapper.jar) Add class path elements as # needed starting from 1 wrapper.java.classpath.1=../../lib/*.jar -wrapper.java.classpath.2=../../ -wrapper.java.classpath.3=../../extensions/jdbc-driver/derby/*.jar +wrapper.java.classpath.2=../../conf +wrapper.java.classpath.3=../../extensions/jdbc-driver/h2/*.jar wrapper.java.classpath.4=../../extensions/jdbc-driver/mysql/*.jar wrapper.java.classpath.5=../../extensions/jdbc-driver/oracle/*.jar wrapper.java.classpath.6=../../extensions/jdbc-driver/postgresql/*.jar @@ -44,21 +49,16 @@ wrapper.app.parameter.1=org.sonar.application.StartServer #******************************************************************** # Profiling and debbuging - for development only -# If wrapper.java.additional.3=-server is not commented, parameter ids should start from 4 instead of 3. +# If wrapper.java.additional.6=-server is not commented, parameter ids should start from 7 instead of 6. #******************************************************************** # Java remote debugging -#wrapper.java.additional.3=-agentlib:jdwp=transport=dt_socket,server=y,address=8000 - -# JProfiler 5 -#wrapper.java.additional.3=-Xint -#wrapper.java.additional.4=-agentlib:jprofilerti=port=8849 -#wrapper.java.additional.5=-Xbootclasspath/a:/Applications/jprofiler5/bin/agent.jar +#wrapper.java.additional.6=-agentlib:jdwp=transport=dt_socket,server=y,address=8000 # JMX remote monitoring on Sun JVM (warning, security is disabled) -#wrapper.java.additional.3=-Dcom.sun.management.jmxremote -#wrapper.java.additional.4=-Dcom.sun.management.jmxremote.port=9005 -#wrapper.java.additional.5=-Dcom.sun.management.jmxremote.authenticate=false -#wrapper.java.additional.6=-Dcom.sun.management.jmxremote.ssl=false +#wrapper.java.additional.6=-Dcom.sun.management.jmxremote +#wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=9005 +#wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false +#wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false #******************************************************************** # Wrapper Logging Properties @@ -67,13 +67,13 @@ wrapper.app.parameter.1=org.sonar.application.StartServer wrapper.console.format=PM # Log Level for console output. (See docs for log levels) -wrapper.console.loglevel=NONE +wrapper.console.loglevel=INFO # Log file to use for wrapper output logging. wrapper.logfile=../../logs/sonar.log # Format of output for the log file. (See docs for formats) -wrapper.logfile.format=LPTM +wrapper.logfile.format=M # Log Level for log file output. (See docs for log levels) wrapper.logfile.loglevel=INFO @@ -82,7 +82,9 @@ wrapper.logfile.loglevel=INFO # the log is rolled. Size is specified in bytes. The default value # of 0, disables log rolling. May abbreviate with the 'k' (kb) or # 'm' (mb) suffix. For example: 10m = 10 megabytes. +<%- if node['sonar']['logfile_maxsize'] -%> wrapper.logfile.maxsize=<%= node['sonar']['logfile_maxsize'] %> +<%- end -%> # Maximum number of rolled log files which will be allowed before old # files are deleted. The default value of 0 implies no limit. @@ -97,6 +99,9 @@ wrapper.syslog.loglevel=<%= node['sonar']['syslog_loglevel'] %> # Title to use when running as a console wrapper.console.title=Sonar +# Disallow start of multiple instances of an application at the same time on Windows +wrapper.single_invocation=true + #******************************************************************** # Wrapper Windows NT/2000/XP Service Properties #******************************************************************** @@ -125,4 +130,4 @@ wrapper.ntservice.interactive=false #******************************************************************** # restart the process if CPU is heavily loaded during 240 seconds. -wrapper.ping.timeout=240 \ No newline at end of file +wrapper.ping.timeout=240 From 60839a001f80d6f73e454382cf36c186903249a4 Mon Sep 17 00:00:00 2001 From: "ilja.bobkevic" Date: Fri, 10 Jan 2014 13:51:32 +0100 Subject: [PATCH 2/3] Use equals sign in the template. Symlink /etc/sonar --- recipes/default.rb | 5 +++++ templates/default/sonar.properties.erb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/recipes/default.rb b/recipes/default.rb index cbdb977..f9776d6 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -56,3 +56,8 @@ command "ln -s #{File.join(node['sonar']['dir'], 'logs')} /var/log/sonar" not_if { File.exists?('/var/log/sonar') } end + +execute 'symlink-sonar-conf-directory' do + command "ln -s #{File.join(node['sonar']['dir'], 'conf')} /etc/sonar" + not_if { File.exists?('/etc/sonar') } +end diff --git a/templates/default/sonar.properties.erb b/templates/default/sonar.properties.erb index b181b77..f31c477 100644 --- a/templates/default/sonar.properties.erb +++ b/templates/default/sonar.properties.erb @@ -141,6 +141,6 @@ sonar.notifications.delay=60 <% if @options -%> <% @options.sort.map do | option, value | -%> -<%= option %>: <%= value %> +<%= option %>=<%= value %> <% end -%> <% end -%> From 6b4fbd75e53da20c9ab7ae83ad647c8fe3383423 Mon Sep 17 00:00:00 2001 From: "ilja.bobkevic" Date: Mon, 13 Jan 2014 17:06:29 +0100 Subject: [PATCH 3/3] Fix issues related to the name change 1. Change name of the zip file and directory to match the name change to sonarqube 2. Add/update attributes to parametrize the setup --- attributes/default.rb | 10 ++++++++-- files/default/tests/minitest/default_test.rb | 2 +- metadata.rb | 2 +- recipes/_source.rb | 19 +++++++++++-------- recipes/database_mysql.rb | 2 +- recipes/default.rb | 8 ++++---- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 8e25d85..2513535 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,8 +1,14 @@ # General settings -default['sonar']['dir'] = "/opt/sonar" +default['sonar']['name'] = "sonarqube" default['sonar']['version'] = "4.0" -default['sonar']['checksum'] = "01e036c265bac46105515eb8a753bc02208c9a22b198bc846acf2e752ea133e5" 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 diff --git a/files/default/tests/minitest/default_test.rb b/files/default/tests/minitest/default_test.rb index e89ad17..aef46d7 100644 --- a/files/default/tests/minitest/default_test.rb +++ b/files/default/tests/minitest/default_test.rb @@ -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? diff --git a/metadata.rb b/metadata.rb index 7a047df..d8a32d7 100644 --- a/metadata.rb +++ b/metadata.rb @@ -3,7 +3,7 @@ license "Apache 2.0" description "Installs/Configures sonar" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.5" +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." diff --git a/recipes/_source.rb b/recipes/_source.rb index a6ed5c7..293162c 100644 --- a/recipes/_source.rb +++ b/recipes/_source.rb @@ -20,22 +20,25 @@ package "unzip" -remote_file "/opt/sonar-#{node['sonar']['version']}.zip" do - source "#{node['sonar']['mirror']}/sonar-#{node['sonar']['version']}.zip" +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?("/opt/sonar-#{node['sonar']['version']}.zip") } + not_if { ::File.exists?(zip_file_path) } end -execute "unzip /opt/sonar-#{node['sonar']['version']}.zip -d /opt/" do - not_if { ::File.directory?("/opt/sonar-#{node['sonar']['version']}/") } +execute "unzip #{zip_file_path} -d #{node['sonar']['install_dir']}" do + not_if { ::File.directory?(sonar_dir) } end -link node['sonar']['dir'] do - to "/opt/sonar-#{node['sonar']['version']}" +link node['sonar']['home'] do + to sonar_dir end -link File.join(node['sonar']['dir'], 'bin', node['sonar']['os_kernel'], 'sonar.sh') do +link File.join(node['sonar']['bin_dir'], 'sonar.sh') do to '/usr/bin/sonar' end diff --git a/recipes/database_mysql.rb b/recipes/database_mysql.rb index ba193ab..42a9b2f 100644 --- a/recipes/database_mysql.rb +++ b/recipes/database_mysql.rb @@ -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" diff --git a/recipes/default.rb b/recipes/default.rb index f9776d6..93f82ae 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -32,7 +32,7 @@ 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" @@ -44,7 +44,7 @@ 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" @@ -53,11 +53,11 @@ end execute 'symlink-sonar-logs-directory' do - command "ln -s #{File.join(node['sonar']['dir'], 'logs')} /var/log/sonar" + 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']['dir'], 'conf')} /etc/sonar" + command "ln -s #{File.join(node['sonar']['conf_dir'])} /etc/sonar" not_if { File.exists?('/etc/sonar') } end