If there are multiple versions of Java installed on your server, you may need to explicitly define which version of Java is used.
+#### Linux / macOS
To change the Java JVM used by SonarQube, edit _$SONARQUBE-HOME/bin/{platform_OS}/sonar.sh_ and update the following line:
```
JAVA_CMD="java"
```
+#### Windows
+To change the Java JVM used by SonarQube, edit > _$SONARQUBE-HOME\bin\windows-x86-64\SonarService.xml_ and update the following line:
+
+```
+<executable>java</executable>
+```
+
### Advanced Installation Features
- Running SonarQube as a Service on [Windows](/setup/operate-server/) or [Linux](/setup/operate-server/)
## Running SonarQube as a Service on Windows
-### Installing SonarQube as a service
-
-[[warning]]
-| When installing SonarQube as a service on Windows, the path to the executable should be quoted to prevent unquoted service path attacks.
+### Install or Uninstall SonarQube as a Service
```
-> sc create SonarQube binPath= "\"%SONAR_HOME%\bin\windows-x86-64\wrapper.exe\" -s \"%SONAR_HOME%\conf\wrapper.conf\""
+> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe install
+> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe uninstall
```
### Start or Stop the Service
```
-> "%SONAR_HOME%\bin\windows-x86-64\StartNTService.bat"
-> "%SONAR_HOME%\bin\windows-x86-64\StopNTService.bat"
+> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe start
+```
+**Note:** By default, the service will use the Java executable available on the Windows PATH. This setting can be changed in `%SONAR_HOME%\bin\windows-x86-64\SonarService.xml`, by updating the `<executable>`.
+```
+> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe stop
+```
+**Note:** `> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe stop` does a graceful shutdown where no new analysis report processing can start, but the tasks in progress are allowed to finish. The time a stop will take depends on the processing time of the tasks in progress. You'll need to kill all SonarQube processes manually to force a stop.
+
+### Service Status
+Check if the SonarQube service is running
+```
+> %SONAR_HOME%\bin\windows-x86-64\SonarService.exe status
```
-**Note:** `> "%SONAR_HOME%\bin\windows-x86-64\StopNTService.bat"` does a graceful shutdown where no new analysis report processing can start, but the tasks in progress are allowed to finish. The time a stop will take depends on the processing time of the tasks in progress. You'll need to kill all SonarQube processes manually to force a stop.
## Running SonarQube Manually on Linux
- For Linux it depends how you implemented the service
- For Windows you can update your service by running:
```
-sc config SonarQube binPath= "\"$NEW_SONAR_HOME\bin\windows-x86-64\wrapper.exe\" -s \"$NEW_SONAR_HOME\conf\wrapper.conf\""
+> sc delete SonarQube
+> $NEW_SONAR_HOME\bin\windows-x86-64\SonarService.exe install
```
### Rebuilding indexes
from(file('src/main/assembly')) {
exclude 'conf/sonar.properties'
exclude 'conf/wrapper.conf'
+ exclude 'bin/windows-x86-64/SonarService.xml'
+ exclude 'bin/windows-x86-64/StartSonar.bat'
exclude 'elasticsearch-patch'
exclude 'bin/linux-x86-64/sonar.sh'
exclude 'bin/macosx-universal-64/sonar.sh'
])
}
+ into("${archiveDir}/bin/windows-x86-64/") {
+ from file('src/main/assembly/bin/windows-x86-64/SonarService.xml')
+ from file('src/main/assembly/bin/windows-x86-64/StartSonar.bat')
+ filter(ReplaceTokens, tokens: [
+ 'sqversion': version
+ ])
+ }
+
into("${archiveDir}/elasticsearch/") {
from file('src/main/assembly/elasticsearch-patch')
include 'bin/elasticsearch'
--- /dev/null
+<service>
+ <!-- Path to the Java executable -->
+ <executable>java</executable>
+
+ <!-- DO NOT EDIT THE FOLLOWING SECTIONS -->
+ <arguments>
+ -Xms8m -Xmx32m
+ -Djava.awt.headless=true
+ --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
+ --add-opens=java.base/java.lang=ALL-UNNAMED
+ --add-opens=java.base/java.nio=ALL-UNNAMED
+ --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
+ --add-opens=java.management/sun.management=ALL-UNNAMED
+ --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED
+ -cp "..\..\lib\sonar-application-@sqversion@.jar" "org.sonar.application.App"
+ </arguments>
+
+ <id>SonarQube</id>
+ <name>SonarQube</name>
+ <description>SonarQube</description>
+
+ <logpath>../../logs</logpath>
+ <log mode="none"/>
+
+</service>
\ No newline at end of file
+++ /dev/null
-@echo off
-setlocal
-
-rem Copyright (c) 1999, 2006 Tanuki Software Inc.
-rem
-rem Java Service Wrapper general NT service start script
-rem
-
-if "%OS%"=="Windows_NT" goto nt
-echo This script only works with NT-based versions of Windows.
-goto :eof
-
-:nt
-rem
-rem Find the application home.
-rem
-rem %~dp0 is location of current script under NT
-set _REALPATH=%~dp0
-
-rem Decide on the wrapper binary.
-set _WRAPPER_BASE=wrapper
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe
-if exist "%_WRAPPER_EXE%" goto conf
-echo Unable to locate a Wrapper executable using any of the following names:
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-echo %_REALPATH%%_WRAPPER_BASE%.exe
-pause
-goto :eof
-
-rem
-rem Find the wrapper.conf
-rem
-:conf
-set _WRAPPER_CONF="%~f1"
-if not %_WRAPPER_CONF%=="" goto startup
-set _WRAPPER_CONF="%_REALPATH%..\..\conf\wrapper.conf"
-
-rem
-rem Start the Wrapper NT service.
-rem
-:startup
-"%_WRAPPER_EXE%" -t %_WRAPPER_CONF%
-if not errorlevel 1 goto :eof
-pause
-
-@echo off
-setlocal
-
-rem Copyright (c) 1999, 2006 Tanuki Software Inc.
-rem
-rem Java Service Wrapper general startup script
-rem
-
-rem
-rem Resolve the real path of the wrapper.exe
-rem For non NT systems, the _REALPATH and _WRAPPER_CONF values
-rem can be hard-coded below and the following test removed.
-rem
-if "%OS%"=="Windows_NT" goto nt
-echo This script only works with NT-based versions of Windows.
-goto :eof
-
-:nt
-rem
-rem Find the application home.
-rem
-rem %~dp0 is location of current script under NT
-set _REALPATH=%~dp0
-
-rem Decide on the wrapper binary.
-set _WRAPPER_BASE=wrapper
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe
-if exist "%_WRAPPER_EXE%" goto conf
-echo Unable to locate a Wrapper executable using any of the following names:
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-echo %_REALPATH%%_WRAPPER_BASE%.exe
-pause
-goto :eof
-
-rem
-rem Find the wrapper.conf
-rem
-:conf
-set _WRAPPER_CONF="%~f1"
-if not %_WRAPPER_CONF%=="" goto startup
-set _WRAPPER_CONF="%_REALPATH%..\..\conf\wrapper.conf"
-
-rem
-rem Start the Wrapper
-rem
-:startup
-"%_WRAPPER_EXE%" -c %_WRAPPER_CONF%
-if not errorlevel 1 goto :eof
-pause
-
+@rem SonarQube\r
+@rem Copyright (C) 2009-2022 SonarSource SA\r
+@rem mailto:info AT sonarsource DOT com\r
+@rem\r
+@rem This program is free software; you can redistribute it and/or\r
+@rem modify it under the terms of the GNU Lesser General Public\r
+@rem License as published by the Free Software Foundation; either\r
+@rem version 3 of the License, or (at your option) any later version.\r
+@rem\r
+@rem This program is distributed in the hope that it will be useful,\r
+@rem but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+@rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+@rem Lesser General Public License for more details.\r
+@rem\r
+@rem You should have received a copy of the GNU Lesser General Public License\r
+@rem along with this program; if not, write to the Free Software Foundation,\r
+@rem Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
+\r
+@echo off\r
+setlocal\r
+\r
+rem Path to the Java executable\r
+set JAVA_EXE="java"\r
+\r
+\r
+rem DO NOT EDIT THE FOLLOWING SECTIONS\r
+call :check_if_sonar_is_running FAIL || goto:eof\r
+\r
+%JAVA_EXE% -Xms8m -Xmx32m^\r
+ -Djava.awt.headless=true^\r
+ --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED^\r
+ --add-opens=java.base/java.lang=ALL-UNNAMED^\r
+ --add-opens=java.base/java.nio=ALL-UNNAMED^\r
+ --add-opens=java.base/sun.nio.ch=ALL-UNNAMED^\r
+ --add-opens=java.management/sun.management=ALL-UNNAMED^\r
+ --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED^\r
+ -cp "..\..\lib\sonar-application-@sqversion@.jar" "org.sonar.application.App"\r
+\r
+goto:eof\r
+\r
+:check_if_sonar_is_running\r
+set "SQ_PROCESS="\r
+where jps >nul 2>nul\r
+if %errorlevel% equ 0 (\r
+ rem give priority to jps command if present\r
+ for /f "tokens=1" %%i in ('jps -l ^| findstr "org.sonar.application.App"') do set "SQ_PROCESS=%%i"\r
+) else (\r
+ rem fallback to wmic command\r
+ for /f "tokens=2" %%i in ('wmic process where "name='java.exe' and commandline like '%%org.sonar.application.App%%'" get name^, processid 2^>nul ^| findstr "java"') do set "SQ_PROCESS=%%i"\r
+)\r
+\r
+if not [%SQ_PROCESS%]==[] (\r
+ echo ERROR: Another instance of the SonarQube application is already running with PID %SQ_PROCESS%\r
+ exit /b 1\r
+)\r
+goto:eof\r
+\r
+endlocal\r
+\r
+++ /dev/null
-@echo off
-setlocal
-
-rem Copyright (c) 1999, 2006 Tanuki Software Inc.
-rem
-rem Java Service Wrapper general NT service stop script
-rem
-
-if "%OS%"=="Windows_NT" goto nt
-echo This script only works with NT-based versions of Windows.
-goto :eof
-
-:nt
-rem
-rem Find the application home.
-rem
-rem %~dp0 is location of current script under NT
-set _REALPATH=%~dp0
-
-rem Decide on the wrapper binary.
-set _WRAPPER_BASE=wrapper
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-if exist "%_WRAPPER_EXE%" goto conf
-set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe
-if exist "%_WRAPPER_EXE%" goto conf
-echo Unable to locate a Wrapper executable using any of the following names:
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
-echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
-echo %_REALPATH%%_WRAPPER_BASE%.exe
-pause
-goto :eof
-
-rem
-rem Find the wrapper.conf
-rem
-:conf
-set _WRAPPER_CONF="%~f1"
-if not %_WRAPPER_CONF%=="" goto startup
-set _WRAPPER_CONF="%_REALPATH%..\..\conf\wrapper.conf"
-
-rem
-rem Stop the Wrapper NT service.
-rem
-:startup
-"%_WRAPPER_EXE%" -p %_WRAPPER_CONF%
-if not errorlevel 1 goto :eof
-pause
-
--- /dev/null
+This bundle contains Windows Service Wrapper scripts and binaries version 2.11.0 published
+under the following license:
+
+ MIT License
+
+ Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees, Inc., Oleg Nenashev and other contributors
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
+ https://github.com/winsw/winsw/blob/master/LICENSE.txt