【问题标题】:Is there a way to start a sonarqube server with an external sonar.properties file?有没有办法使用外部 sonar.properties 文件启动 sonarqube 服务器?
【发布时间】:2015-05-11 04:54:32
【问题描述】:

我想知道是否有办法使用外部 sonar.properties 和 wrapper.conf 文件启动 SonarQube (5.0.1) 服务器。

我正在寻找类似于 apache "-f" 选项的东西 -

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

谢谢。

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

正如下面的答案中提到的,我尝试使用环境变量引用属性。这适用于某些属性。前任。 sonar.jdbc.username & sonar.jdbc.password

它不适用于我作为具有多个环境变量的属性值。

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

这是我得到的例外 -

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.').

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

我也尝试过只有一个环境变量 -

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

得到这个异常 -

--> 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

如果我对 mysql 主机 url 进行硬编码,这将有效。

跟URL格式化有关,还在调试中……

【问题讨论】:

    标签: sonarqube sonarqube-5.0


    【解决方案1】:

    在 UBUNTU 中:是的,您可以提供外部文件。如果您在 sonarqube bin 文件夹中看到 sonar.sh 文件

    #! /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="."
    

    您可以在WRAPPER_CONF= 此处定义包装文件的路径,对于 sonar.properties,您可以在 sonarqube conf 文件夹中创建文件链接并将其重定向到您保存文件的路径。还有一个更艰难的选择是编辑上面的 start.sh 文件以接受这些参数作为标志。 (例如,-sp 用于声纳属性,-wc 用于包装器配置)

    【讨论】:

    • 创建指向 sonar.properties 的文件链接就像更改 rpm。我正在寻找一种无需接触 rpm 文件结构的解决方案。感谢您的意见,我将测试此选项。
    • 我的问题是特定于 sonar.properties 文件的,感谢您对 wrapper conf 的输入。使用符号链接构建 sonqrqube rpm 对我不起作用,因为目标会根据环境(dev/qa/prod 等)而变化。
    【解决方案2】:

    sonar.properties 中的值可以通过引用环境变量来外部化。

    sonarqube/5.0.1/conf/sonar.properties 头文件 >

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

    看起来这种方法需要最少的文件操作,并解决了我不想硬编码属性值的问题,因为它们会根据环境发生变化。

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2017-03-21
      • 2023-04-10
      • 1970-01-01
      • 2013-06-23
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2011-05-23
      相关资源
      最近更新 更多