Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Commit 14a4eb0

Browse files
committed
Merge pull request #42 from maestrodev/feature/properly_clean_up_old_versions_of_plugins_and_sonarqube
Properly cleanup old versions of SonarQube and plugins
2 parents 8414db4 + dd03c9d commit 14a4eb0

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

manifests/init.pp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
sonarqube::move_to_home { 'extensions': } ->
126126
sonarqube::move_to_home { 'logs': } ->
127127

128-
# ===== Install Sonar =====
128+
# ===== Install SonarQube =====
129129

130130
exec { 'untar':
131131
command => "unzip -o ${tmpzip} -d ${installroot} && chown -R ${user}:${group} ${installroot}/${package_name}-${version} && chown -R ${user}:${group} ${real_home}",
@@ -159,6 +159,21 @@
159159
}
160160
}
161161

162+
file { '/tmp/cleanup-old-plugin-versions.sh':
163+
content => template("${module_name}/cleanup-old-plugin-versions.sh.erb"),
164+
mode => '0755',
165+
}
166+
->
167+
file { '/tmp/cleanup-old-sonarqube-versions.sh':
168+
content => template("${module_name}/cleanup-old-sonarqube-versions.sh.erb"),
169+
mode => '0755',
170+
}
171+
->
172+
exec { 'remove-old-versions-of-sonarqube':
173+
command => "/tmp/cleanup-old-sonarqube-versions.sh ${installroot} ${version}",
174+
path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin',
175+
}
176+
162177
# The plugins directory. Useful to later reference it from the plugin definition
163178
file { $plugin_dir:
164179
ensure => directory,

manifests/plugin.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
before => File[$plugin],
3737
require => File[$sonarqube::plugin_dir],
3838
}
39+
->
3940
exec { "remove-old-versions-of-${artifactid}":
40-
command => "rm -f ${sonarqube::plugin_dir}/${artifactid}*.jar",
41+
command => "/tmp/cleanup-old-plugin-versions.sh ${sonarqube::plugin_dir} ${artifactid} ${version}",
4142
path => '/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin',
4243
}
4344
->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/sh
2+
3+
pushd $1
4+
for file in $(ls | grep $2)
5+
do
6+
if [ "$file" != "$2-$3.jar" ]
7+
then
8+
rm -f "$file"
9+
fi
10+
done
11+
popd
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /bin/sh
2+
3+
pushd $1
4+
for directory in $(ls | grep "sonarqube-")
5+
do
6+
if [ "$directory" != "sonarqube-$2" ]
7+
then
8+
rm -rf "$directory"
9+
fi
10+
done
11+
popd

templates/sonar.sh.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#-----------------------------------------------------------------------------
2121
# These settings can be modified to fit the needs of your application
2222

23-
# Default values for the Application variables, below.
24-
#
23+
# Default values for the Application variables, below.
24+
#
2525
# NOTE: The build for specific applications may override this during the resource-copying
2626
# phase, to fill in a concrete name and avoid the use of the defaults specified here.
2727
DEF_APP_NAME="sonar"
@@ -313,7 +313,7 @@ checkUser() {
313313
exit 1
314314
fi
315315
fi
316-
316+
317317
if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
318318
then
319319
# Already running as the configured user. Avoid password prompts by not calling su.
@@ -330,7 +330,7 @@ checkUser() {
330330
then
331331
if [ "X$1" != "X" ]
332332
then
333-
# Resolve the primary group
333+
# Resolve the primary group
334334
RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
335335
if [ "X$RUN_AS_GROUP" = "X" ]
336336
then
@@ -416,7 +416,7 @@ console() {
416416
exit 1
417417
fi
418418
}
419-
419+
420420
start() {
421421
echo "Starting $APP_LONG_NAME..."
422422
getpid
@@ -435,9 +435,9 @@ start() {
435435
echo "Started $APP_LONG_NAME."
436436
else
437437
echo "Failed to start $APP_LONG_NAME."
438-
fi
438+
fi
439439
}
440-
440+
441441
stopit() {
442442
echo "Stopping $APP_LONG_NAME..."
443443
getpid

0 commit comments

Comments
 (0)