Skip to content

Commit

Permalink
(nexus-repository) Removes ProgramDir before Copying Files
Browse files Browse the repository at this point in the history
The upgrade to JRE exposed that the package was simply copying new files over the old ones, which can break things when old files combine with new.

This change solidifies the package logic to backup SSL configuration if it's present, and specifically removes the program directory before re-copying the latest files.

This should ensure that Nexus can start, after the upgrade.
  • Loading branch information
JPRuskin committed Sep 4, 2024
1 parent 8e4b010 commit 67b9cbf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions automatic/nexus-repository/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Nexus product does not have a built-in web gallery for components.

This package supports the following parameters:

* `/Fqdn` - The fqdn that matches the subject you are using for your Nexus instance SSL certificate.
* `/Port` - Specify what port Nexus should listen on. Defaults to `8081`.
* `/BackupSslConfig` - Ensures that the ssl configuration survives an upgrade.
* `/BackupLocation` - Species the path to backup ssl configuration to during upgrade. Defaults to `~/NexusSSLBackup`.
* `/Fqdn` - The fully-qualified domain name that matches the subject you are using for your Nexus instance SSL certificate.
* `/Port` - Specify what port Nexus should listen on. Defaults to `8081`, or whatever was previously configured.
* `/BackupSslConfig` - Ensures that the SSL configuration survives an upgrade, if it's otherwise undetected.
* `/BackupLocation` - Specifies the path to backup the SSL configuration to during upgrade. Defaults to `~/NexusSSLBackup`.

You can pass parameters as follows:

Expand All @@ -38,6 +38,8 @@ You can pass parameters as follows:
This means that you will need to migrate your database from OrientDb, if you are using it.
See [here](https://help.sonatype.com/en/orient-3-70-java-8-or-11.html) for further details,
or check out the nexus-repository-migrator package.
Versions after this will also overwrite rather than merge the program directory, i.e. `$env:ProgramFiles/nexus`,
and back-up HTTPS configuration and the keystore from there if it is configured.

- **ATTENTION BREAKING CHANGE FOR UPGRADES FROM VERSIONS BEFORE 3.3.2.02**
Nexus no longer provided a setup.exe for installing Nexus Repository 3.x on Windows.
Expand Down
10 changes: 6 additions & 4 deletions automatic/nexus-repository/nexus-repository.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Nexus product does not have a built-in web gallery for components.
This package supports the following parameters:
* `/Fqdn` - The fqdn that matches the subject you are using for your Nexus instance SSL certificate.
* `/Port` - Specify what port Nexus should listen on. Defaults to `8081`.
* `/BackupSslConfig` - Ensures that the ssl configuration survives an upgrade.
* `/BackupLocation` - Species the path to backup ssl configuration to during upgrade. Defaults to `~/NexusSSLBackup`.
* `/Fqdn` - The fully-qualified domain name that matches the subject you are using for your Nexus instance SSL certificate.
* `/Port` - Specify what port Nexus should listen on. Defaults to `8081`, or whatever was previously configured.
* `/BackupSslConfig` - Ensures that the SSL configuration survives an upgrade, if it's otherwise undetected.
* `/BackupLocation` - Specifies the path to backup the SSL configuration to during upgrade. Defaults to `~/NexusSSLBackup`.
You can pass parameters as follows:
Expand All @@ -45,6 +45,8 @@ You can pass parameters as follows:
This means that you will need to migrate your database from OrientDb, if you are using it.
See [here](https://help.sonatype.com/en/orient-3-70-java-8-or-11.html) for further details,
or check out the nexus-repository-migrator package.
Versions after this will also overwrite rather than merge the program directory, i.e. `$env:ProgramFiles/nexus`,
and back-up HTTPS configuration and the keystore from there if it is configured.
- **ATTENTION BREAKING CHANGE FOR UPGRADES FROM VERSIONS BEFORE 3.3.2.02**
Nexus no longer provided a setup.exe for installing Nexus Repository 3.x on Windows.
Expand Down
12 changes: 6 additions & 6 deletions automatic/nexus-repository/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $NexusPort = if ($pp.ContainsKey("Port")) {
Write-Host "/Port was used, Nexus will listen on port $($PP['Port'])."
} elseif ($CurrentConfig.'application-port-ssl' -gt 0) {
$CurrentConfig.'application-port-ssl'
$SslConfigured = $true
Write-Host "Nexus is configured to use application-port-ssl, Nexus will listen on port $($CurrentConfig.'application-port-ssl')"
} elseif ($CurrentConfig.'application-port' -gt 0) {
$CurrentConfig.'application-port'
Expand All @@ -55,7 +56,7 @@ if ((Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
Get-Service $ServiceName | Stop-Service -Force
}

if ($pp.ContainsKey("BackupSslConfig") -or $CurrentConfig.'application-port-ssl' -gt 0) {
if ($pp.ContainsKey("BackupSslConfig") -or $SslConfigured) {
if ($pp.ContainsKey("BackupLocation")) {
Backup-NexusSSL -BackupLocation $pp["BackupLocation"]
} else {
Expand All @@ -80,10 +81,9 @@ Install-ChocolateyZipPackage @PackageArgs

Write-Host "Copying files to '$TargetFolder' with overwrite"
if (Test-Path "$TargetFolder") {
Copy-Item "$ExtractFolder\$nexusversionedfolder\*" "$TargetFolder" -Force -Recurse
} else {
Copy-Item "$ExtractFolder\$nexusversionedfolder" "$TargetFolder" -Force -Recurse
Remove-Item "$TargetFolder" -Force -Recurse
}
Copy-Item "$ExtractFolder\$nexusversionedfolder" "$TargetFolder" -Force -Recurse

# Create the Nexus data directory, if it doesn't exist
if (!(Test-Path "$TargetDataFolder")) {
Expand All @@ -103,7 +103,7 @@ $processArgs = @{

$null = Start-ChocolateyProcessAsAdmin @processArgs

if ($pp.ContainsKey("BackupSslConfig") -or $CurrentConfig.'application-port-ssl' -gt 0) {
if ($pp.ContainsKey("BackupSslConfig") -or $SslConfigured) {
if ($pp.ContainsKey("BackupLocation")) {
Restore-NexusSSL -BackupLocation $pp['BackupLocation']
} else {
Expand All @@ -112,7 +112,7 @@ if ($pp.ContainsKey("BackupSslConfig") -or $CurrentConfig.'application-port-ssl'
}

# Update Port in Configuration before starting the service
if ($NexusPort -ne '8081') {
if ($NexusPort -ne '8081' -and -not $SslConfigured) {
if (Test-Path "$NexusConfigFile") {
Write-Host "Configuring Nexus to listen on port $NexusPort."
(Get-Content "$NexusConfigFile") -replace "^#\s*application-port=.*$", "application-port=$NexusPort" |
Expand Down

0 comments on commit 67b9cbf

Please sign in to comment.