4
votes

I want to know if there is a way to start a SonarQube (5.0.1) server with an external sonar.properties and wrapper.conf files.

I am looking at something similar to apache "-f" option -

/apache2/bin/apachectl -f /path/to/httpd.conf

Thanks.

========================================================

As mentioned in the answer below, I tried to reference the properties with environment variables. This works for certain properties. ex. sonar.jdbc.username & sonar.jdbc.password

It did not work for me for as a property value that has multiple environment variables.

Ex. sonar.jdbc.url=jdbc:mysql://${env:MYSQL_HOST}:${env:MYSQL_PORT}/sonar= ?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true

Here is the exception I am getting -

2015.03.17 11:48:33 INFO  web[o.s.c.p.Database]  Create JDBC datasource for=  jdbc:mysql://${env:MYSQL_HOST}:${env:MYSQL_PORT}/sonar?useUnicode=3Dtrue&c=
haracterEncoding=3Dutf8&rewriteBatchedStatements=3Dtrue
2015.03.17 11:48:33 ERROR web[o.a.c.c.C.[.[.[/sonar]]  Exception sending co= ntext initialized event to listener instance of class org.sonar.server.plat= form.PlatformServletContextListener
java.lang.IllegalStateException: Can not connect to database. Please check = connectivity and settings (see the properties prefixed by 'sonar.jdbc.').

==========================================================

I also tried with having only one env variable -

$echo $MYSQL_DB_URL
jdbc:mysql://devdbXXX:6000/sonar?useUnicode=true

Getting this exception -

--> Wrapper Started as Daemon
Launching a JVM...
Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
  Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.


WrapperSimpleApp: Encountered an error running main: org.sonar.process.MessageException: Bad format of JDBC URL: ${env:MYSQL_DB_URL}
org.sonar.process.MessageException: Bad format of JDBC URL: ${env:MYSQL_DB_URL}
<-- Wrapper Stopped

This works if I hardcode the mysql host url.

Something to do with URL formatting, Still debugging...

2

2 Answers

4
votes

In UBUNTU: Yes you can give an external file. If you see the sonar.sh file in sonarqube bin folder

#! /bin/sh

#
# Copyright (c) 1999, 2006 Tanuki Software Inc.
#
# Java Service Wrapper sh script.  Suitable for starting and stopping
#  wrapped Java applications on UNIX platforms.
#

#-----------------------------------------------------------------------------
# These settings can be modified to fit the needs of your application

# Default values for the Application variables, below. 
# 
# NOTE: The build for specific applications may override this during the resource-copying
# phase, to fill in a concrete name and avoid the use of the defaults specified here.
DEF_APP_NAME="SonarQube"
DEF_APP_LONG_NAME="SonarQube"

# Application
APP_NAME="${DEF_APP_NAME}"
APP_LONG_NAME="${DEF_APP_LONG_NAME}"

# Wrapper
WRAPPER_CMD="./wrapper"
WRAPPER_CONF="../../conf/wrapper.conf"

# Priority at which to run the wrapper.  See "man nice" for valid priorities.
#  nice is only used if a priority is specified.
PRIORITY=

# Location of the pid file.
PIDDIR="."

You can define the path of wrapper file here WRAPPER_CONF= and for sonar.properties you can create a file link in sonarqube conf folder and redirect it to the path you have saved the file. Also a tougher option is to edit the above start.sh file to accept these parameters as flags. (Eg -sp for sonar properties and -wc for wrapper conf)

1
votes

Values in the sonar.properties can be externalized by referencing from environment variables.

sonarqube/5.0.1/conf/sonar.properties header >

# Property values can:
 # - reference an environment variable, for example sonar.jdbc.url= ${env:SONAR_JDBC_URL}

Looks like this approach needs least file manipulation and solves the problem where I do not want to hardcode the property values as they are changing as per the environment.