Configure SonarQube to start as a service in MacOS
After installing SonarQube and setting up a dedicated database, the last step for you is probably to configure it as a service so that it starts with the operating system. If you haven't installed SonarQube yet, we recommend reading the following posts.
- SonarQube Installation
- Configuring PostgreSQL in SonarQube
If you want to configure SonarQube to start on Linux, you can read the following tutorial.
- Configuring SonarQube to Start as a Service on Linux
Launchd
The first thing you should know about starting SonarQube as a service is that Elasticsearch, a Java component used by SQ, does not allow root startup. Because of this, the service must be created in /Library/LaunchAgents
and not in /System/Library/LaunchAgents
. Given this, you can create a file for the service in this folder and add the following content to it.
sudo vim /Library/LaunchAgents/org.sonarqube.server.plist
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.sonarqube.server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/sonarqube8/bin/macosx-universal-64/sonar.sh</string>
<string>console</string>
</array>
<key>KeepAlive</key>
<true></true>
</dict>
</plist>
Note that you must replace the path where you have the SonarQube executable (sonar.sh
).
To load the service configuration, you can run the following command.
sudo launchctl load /Library/LaunchAgents/org.sonarqube.server.plist
If you want this service to start with the operating system, you must add it to the startup.
sudo launchctl load -w /Library/LaunchAgents/org.sonarqube.server.plist
To start the service, simply run the following command.
sudo launchctl start org.sonarqube.server