Skip to content

Moving a connector

This guide aims to help our customers move the installation of a connector from a Windows server to another Windows server. We will use the connector JiraConnector in our examples below.

Recommendations

We recommend that you use variables instead of hard values (as in the steps below) to make it easier for your. Recommended variables are service, connectorRootDirectory, tomcatRootDirectory and tomcatBinDirectory but feel free to read thru this guide and use variables where you see fit.

Find connector Windows service

As we intend to move the connector, we need to stop and uninstall its Windows service. There is a number of ways to finding the correct service, we suggest you search for it with wildcard against its Name such as *easit* and *connectorName* or a more generic approach would be against its display name, *tomcat*.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    PS C:\Users\admin> Get-Service -DisplayName *tomcat*

    Status   Name               DisplayName
    ------   ----               -----------
    Running  EasitGO            Apache Tomcat 9.0 EasitGO
    Running  EPR-dev            Apache Tomcat 9.0 EPR-dev
    Running  JiraConnector      Apache Tomcat 9.0 JiraConnector

    # Save the service as a variable
    PS C:\Users\admin> $service = Get-Service -Name 'JiraConnector'
    PS C:\Users\admin>

Now that we have found the connectors service, we can use that to find what directory its installed in and its Java options.

1
2
3
4
5
6
7
8
9
    PS C:\Users\admin> Get-Service -Name $service.Name | Select-Object -Property BinaryPathName

    BinaryPathName
    --------------
    D:\Easit\JiraConnector\tomcat\bin\Tomcat9.exe //RS//JiraConnector

    PS C:\Users\admin> $connectorRootDirectory = 'D:\Easit\JiraConnector'
    PS C:\Users\admin> $tomcatRootDirectory = 'D:\Easit\JiraConnector\tomcat'
    PS C:\Users\admin> $tomcatBinDirectory = 'D:\Easit\JiraConnector\tomcat\bin'

From the result above we now know that the service is installed in D:\Easit\JiraConnector\tomcat and the root directory for the connector is D:\Easit\JiraConnector

Backup Tomcat settings

Before we remove the Windows service, we need to save the Tomcat settings such as memory allocation and java options.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    PS C:\Users\admin> $registryRoot = 'HKLM:\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0'
    PS C:\Users\admin> $connectorRegistryRoot = Join-Path -Path $registryRoot -ChildPath $service.Name
    PS C:\Users\admin> $connectorJavaOptRegistryRoot = Join-Path -Path $connectorRegistryRoot -ChildPath 'Parameters\Java'
    PS C:\Users\admin> $tomcatSettings = Get-ItemProperty -Path "$connectorJavaOptRegistryRoot"
    PS C:\Users\admin> $tomcatSettings.Jvm
    D:\Easit\JiraConnector\tomcat\jre\bin\server\jvm.dll
    PS C:\Users\admin> $tomcatJvm = 'D:\Easit\JiraConnector\tomcat\jre'
    PS C:\Users\admin> foreach ($setting in $tomcatSettings) {
        $setting | Out-File -Path "$tomcatBinDirectory\tomcatSettings.txt" -Append
    }
    PS C:\Users\admin> foreach ($option in $tomcatSettings.Options) {
        $option | Out-File -Path "$tomcatBinDirectory\tomcatSettings.txt" -Append
    }
    PS C:\Users\admin>

Stop and uninstall the service

We start by changing our current directory to D:\Easit\JiraConnector\tomcat\bin, stopping the service and verify that it is no longer running.

1
2
3
4
5
6
7
8
9
    PS D:\Users\admin> Set-Location -Path "$tomcatBinDirectory"
    PS D:\Easit\JiraConnector\tomcat\bin> Stop-Service -Name $service.Name
    PS D:\Easit\JiraConnector\tomcat\bin> Get-Service -Name $service.Name

    Status   Name               DisplayName
    ------   ----               -----------
    Stopped  JiraConnector      Apache Tomcat 9.0 JiraConnector

    PS D:\Easit\JiraConnector\tomcat\bin>

Once we have that we are ready to remove the service. This will only remove the service and its corresponding EXE file. We start by finding a file named service.bat that comes with the Apache Tomcat package. This file helps us to remove the service correctly.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    PS D:\Easit\JiraConnector\tomcat\bin> Get-ChildItem -Path '.\*' -Include "service.bat"

        Directory: D:\Easit\JiraConnector\tomcat\bin

    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a---          2023-09-17    21:42           9144 service.bat

    # If $env:JAVA_HOME already have a value, please take note of it for later
    PS D:\Easit\JiraConnector\tomcat\bin> if ([String]::IsNullOrEmpty("$env:JAVA_HOME")) {
        "JAVA_HOME is null";$oldJavaHome='null'
    } else {
        "$env:JAVA_HOME";$oldJavaHome = "$env:JAVA_HOME"
    }
    PS D:\Easit\JiraConnector\tomcat\bin> $env:JAVA_HOME = "$tomcatJvm"
    PS D:\Easit\JiraConnector\tomcat\bin> $removeParameters = @{
        FilePath = (Get-ChildItem -Path '.\*' -Include "service.bat").FullName
        PassThru = $true
        NoNewWindow = $true
        Wait = $true
    }
    # This command will remove the Windows service
    PS D:\Easit\JiraConnector\tomcat\bin> Start-Process @removeParameters -ArgumentList "remove","$($service.Name)"

Now we have uninstalled / removed the connectors Windows service and can remove its corresponding EXE file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    PS D:\Easit\JiraConnector\tomcat\bin> Get-ChildItem -Path '.\*' -Include "*w.exe" -Exclude 'tomcat*'

        Directory: D:\Easit\JiraConnector\tomcat\bin

    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a---          2023-09-17    21:42         128480 JiraConnectorw.exe

    PS D:\Easit\JiraConnector\tomcat\bin> Get-ChildItem -Path '.\*' -Include "*w.exe" -Exclude 'tomcat*' | Remove-Item -Force -Confirm:$false
    # If $env:JAVA_HOME had a value before, we need to set it back to that value
    PS D:\Easit\JiraConnector\tomcat\bin> if ($oldJavaHome -eq 'null') {$env:JAVA_HOME = $null} else {$env:JAVA_HOME = $oldJavaHome}

Copy jre to Tomcat directory

If the value of $tomcatSettings.Jvm is to a directory "outside" $connectorRootDirectory you need to copy it to the connector tomcat directory for it to be included in the file we will create and move later. If the value of $tomcatSettings.Jvm is to a directory "inside" $connectorRootDirectory you do NOT need to run the commands below.

1
2
    PS D:\Easit\JiraConnector\tomcat\bin> Copy-Item -Path "$tomcatJvm" -Recurse -Destination "$tomcatRootDirectory\"
    PS D:\Easit\JiraConnector\tomcat\bin>

Create backup

Before we start cleaning out files we DO NOT want to move to the new server, we take a backup of the connector root directory. That way we have a backup to use if anything goes wrong.

1
2
    PS D:\Easit\JiraConnector\tomcat\bin> Set-Location -Path 'D:\Easit'
    PS D:\Easit> Compress-Archive -Path .\JiraConnector\ -DestinationPath '.\JiraConnector_backup.zip' -CompressionLevel Optimal

Remove files and folders

Now we are ready to remove files and folders that we will not need in the new installation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    PS D:\Easit> Set-Location -Path '.\JiraConnector\'
    PS D:\Easit\JiraConnector> (Get-ChildItem -Path '.\*' -Recurse -Include 'logs' -Directory).FullName | Set-Location

    # This will remove all logs in the logs directory
    PS D:\Easit\JiraConnector\tomcat\logs> Get-ChildItem -Path '.\*' -Recurse -File | Remove-Item -Confirm:$false
    PS D:\Easit\JiraConnector\tomcat\logs> Get-ChildItem -Path '.\*' -Recurse -File
    PS D:\Easit\JiraConnector\tomcat\logs> Set-Location -Path "$tomcatRootDirectory\webapps"

    # This will remove all temp files and folders for the connector.
    PS D:\Easit\JiraConnector\tomcat\webapps> Get-ChildItem -Path '.\*' -Directory | ForEach-Object {Get-ChildItem -Path "$($_.FullName)\*" -Recurse -File | Remove-Item -Confirm:$false}
    PS D:\Easit\JiraConnector\tomcat\webapps> Get-ChildItem -Path '.\*' -Recurse -Directory | ForEach-Object {Remove-Item -Path $_.FullName -Confirm:$false -Recurse}

Create file to move

Now we can create a compressed file that we can move to the new server.

1
2
    PS D:\Easit\JiraConnector\tomcat\webapps> Set-Location -Path 'D:\Easit'
    PS D:\Easit> Compress-Archive -Path .\JiraConnector\ -DestinationPath '.\JiraConnector_move.zip' -CompressionLevel Optimal

Now we have a file, *D:\Easit\JiraConnector_move.zip' that we can move to the new server.

Install the connector on the new server

Expand archive

We start by expanding the ZIP file to a location where we want to install it. In our case we want to install it in E:\Easit and the ZIP file is located in C:\Downloads.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    PS E:\Users\admin> Expand-Archive 'C:\Downloads\EPR_move.zip' -DestinationPath 'E:\Easit'
    PS E:\Users\admin> Get-ChildItem -Path 'E:\Easit\*' -Directory

        Directory: E:\Easit

    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    d----          2023-09-18    11:12                JiraConnector

    PS E:\Users\admin> Set-Location -Path 'E:\Easit\JiraConnector'
    PS E:\Easit\JiraConnector> 

Find JRE

Let us find the JRE directory in the new environment, save it to a variable and set it as $env:JAVA_HOME.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    PS E:\Easit\JiraConnector> Get-ChildItem -Path '.\*' -Include 'jre' -Directory -Recurse

        Directory: E:\Easit\JiraConnector\tomcat

    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    d----          2023-09-20    10:51                jre

    PS E:\Easit\JiraConnector> $tomcatJvm = (Get-ChildItem -Path '.\*' -Include 'jre' -Directory -Recurse).FullName
    PS E:\Easit\JiraConnector> if ([String]::IsNullOrEmpty("$env:JAVA_HOME")) {
        "JAVA_HOME is null";$oldJavaHome='null'
    } else {
        "$env:JAVA_HOME";$oldJavaHome = "$env:JAVA_HOME"
    }
    PS E:\Easit\JiraConnector\tomcat\bin> $env:JAVA_HOME = "$tomcatJvm"

Install Windows service

Now we install the connectors Windows service. We set the location to the bin directory in the tomcat directory and look for a file named addtomcatservice.bat.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    PS E:\Easit\JiraConnector> Set-Location -Path '.\tomcat\bin'
    PS E:\Easit\JiraConnector\tomcat\bin> Get-ChildItem -Path '.\*' -Include 'addtomcatservice.bat'

        Directory: E:\Easit\JiraConnector\tomcat\bin

    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a---          2023-09-18    11:13           2356 AddTomcatService.bat

    PS E:\Easit\JiraConnector\tomcat\bin>

With AddTomcatService.bat

If there is a AddTomcatService.bat in the E:\Easit\JiraConnector\tomcat\bin directory, you can use these steps to install the service.

1
2
3
4
5
6
7
    PS E:\Easit\JiraConnector\tomcat\bin> $processParameters = @{
        FilePath = (Get-ChildItem -Path '.\*' -Include 'addtomcatservice.bat').FullName
        PassThru = $true
        NoNewWindow = $true
        Wait = $true
    }
    PS E:\Easit\JiraConnector\tomcat\bin> Start-Process @processParameters

Manually

If there is NOT a AddTomcatService.bat in the E:\Easit\JiraConnector\tomcat\bin directory, you can use these steps to install the service.

1
2
3
4
5
6
7
    PS E:\Easit\JiraConnector\tomcat\bin> .\service.bat install JiraConnector
    PS E:\Easit\JiraConnector\tomcat\bin> .\tomcat9.exe //US//JiraConnector ++JvmOptions "-Dfile.encoding=UTF8;"
    PS E:\Easit\JiraConnector\tomcat\bin> .\tomcat9.exe //US//JiraConnector ++JvmOptions "-Djava.locale.providers=COMPAT,CLDR;"
    PS E:\Easit\JiraConnector\tomcat\bin> .\tomcat9.exe //US//JiraConnector ++JvmOptions "-Dspring.config.location=file:E:\Easit\JiraConnector\config\"
    PS E:\Easit\JiraConnector\tomcat\bin> Copy-Item .\tomcat9w.exe -Destination .\JiraConnectorw.exe
    PS E:\Easit\JiraConnector\tomcat\bin> New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers' -Name 'E:\Easit\JiraConnector\tomcat\bin\JiraConnectorw.exe' -PropertyType 'STRING' -Value '~ RUNASADMIN'
    PS E:\Easit\JiraConnector\tomcat\bin> Set-Service -Name 'JiraConnector' -StartupType 'Automatic'

Restore $env:JAVA_HOME

1
    PS E:\Easit\JiraConnector\tomcat\bin> if ($oldJavaHome -eq 'null') {$env:JAVA_HOME = $null} else {$env:JAVA_HOME = $oldJavaHome}

Starting the connector

Once the installation of the service, steps above, have been completed successfully we can start the connector and "our work here is done".

1
    PS E:\Easit\JiraConnector\tomcat\bin> Start-Service -Name 'JiraConnector'

Mic drop!