Launch SonarQube as a Service
setup environment variables:
export SONAR_VERSION=6.4
export SONARQUBE_HOME=/opt/sonarqube
export SONARQUBE_JDBC_USERNAME=sonar
export SONARQUBE_JDBC_PASSWORD=sonar
export SONARQUBE_JDBC_URL=
install gpg & unzip:
sudo dnf install -y gpg unzip
run setup.sh in sudo:
#! /bin/sh -
# set server encryption
set -x
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F1182E81C792928921DBCAB4CFCA4A29D26468DE
# fetch, unzip and deploy the server
cd /opt
curl -o sonarqube.zip -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION .zip
curl -o sonarqube.zip.asc -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION .zip.asc
gpg --batch --verify sonarqube.zip.asc sonarqube.zip
unzip sonarqube.zip
mv sonarqube-$SONAR_VERSION sonarqube
set up a systemd unit for Sonar service
[Unit]
Description =SonarQube Server
Documentation =https://docs.sonarqube.org/display/SONAR/Documentation
After =network.target network-online.target
Wants =network-online.target
[Service]
Type =forking
ExecStart =/opt/sonarqube/bin/linux-x86-64/sonar.sh start
ExecStop =/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
ExecReload =/opt/sonarqube/bin/linux-x86-64/sonar.sh restart
PIDFile =/opt/sonarqube/bin/linux-x86-64/SonarQube.pid
run systemctl to launch the service
sudo systemctl daemon-reload
sudo systemctl start sonar
- hosts : sonarqube
environment :
SONAR_VERSION : 6.4
SONARQUBE_HOME : /opt/sonarqube
SONARQUBE_JDBC_USERNAME : sonar
SONARQUBE_JDBC_PASSWORD : sonar
remote_user : root
become : yes
tasks :
- name : install dependencies
dnf :
name : " {{ item }}"
state : present
with_items :
- gpg
- unzip
- java-1.8.0-openjdk.x86_64
- java-1.8.0-openjdk-devel.x86_64
- libselinux-python
- name : import gpg keys
command : " {{ item }}"
with_items :
- gpg --keyserver ha.pool.sks-keyservers.net --recv-keys F1182E81C792928921DBCAB4CFCA4A29D26468DE
- touch /root/.gpgset
args :
creates : /root/.gpgset
- name : fetch and deploy sonar server
shell : " {{ item }}"
args :
chdir : /opt
creates : /opt/sonarqube
with_items :
- curl -o sonarqube.zip -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip
- curl -o sonarqube.zip.asc -fSL https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-$SONAR_VERSION.zip.asc
- gpg --batch --verify sonarqube.zip.asc sonarqube.zip
- unzip sonarqube.zip
- mv sonarqube-$SONAR_VERSION sonarqube
- name : set sonar service unit
copy :
src : ./sonar.service
dest : /etc/systemd/system
- name : start sonar server
systemd :
name : sonar
state : started
daemon_reload : yes