How to update Apache Tomcat
Easit distinguishes an update from an upgrade in that an update occurs within a major version and an upgrade occurs between major versions. Going from version 9.0.xx to version 9.0.xx is an update while going from version 8.x.x to version 9.x.xx is an upgrade.
This guide do not take into account for any changes in the configuration files such as new attributes. Please advise the Apache Migration Guide before updating.
Find service
There are several ways to finding the correct service for your Easit GO instance, for consistency in this guide we will use PowerShell.
Since we are working with services you need to use a elevated session of PowerShell.
| PS C:\Users\admin> Get-Service -Name *easit*
Status Name DisplayName
------ ---- -----------
Started EasitGOProd Apache Tomcat 9.0 EasitGOProd
PS C:\Users\admin>
|
Note the Name of the service that you wish to update or save it to a variable.
| PS C:\Users\admin> $serviceName = 'EasitGOProd'
|
Stop service
| PS C:\Users\admin> Get-Service -Name $serviceName | Stop-Service
|
Backup service settings
Java Options
This will save all settings for the Tomcat service to a file named tomcatSettings.txt in the directory that you are working in.
| PS C:\Users\admin> $registryPath = "HKLM:\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\$serviceName\Parameters\Java"
PS C:\Users\admin> $settingsFile = "tomcatSettings.txt"
PS C:\Users\admin> Get-ItemProperty -Path "$registryPath" | Foreach-Object {
foreach ($set in $_.psobject.properties) {
"$($set.Name):" | Out-File -FilePath $settingsFile -Append
$set.value | Out-File -FilePath $settingsFile -Append
"" | Out-File -FilePath $settingsFile -Append
}
}
PS C:\Users\admin>
|
Find Log On account for service
As we are doing an "in place update" of Apache Tomcat we need to run the new service with the same account as the current one. You can find this information either by running the PowerShell command below or by looking at the service properties in services.msc.
| PS C:\Users\admin> Get-CimInstance -ClassName 'Win32_Service' -Filter "name='EasitGoProd'" | Select StartName
StartName
---------
NT Authority\LocalService
|
Java memory settings
| PS C:\Users\admin> (Get-ItemProperty -Path "$registryPath").JvmMx
4096
PS C:\Users\admin> (Get-ItemProperty -Path "$registryPath").JvmMs
4096
|
Backup service
First find the root directory for the service. We do this by taking a closer look at the options property from the service settings. In the options we want to know the value of Dcatalina.home.
| PS C:\Users\admin> (Get-ItemProperty -Path "$registryPath").Options
-Dcatalina.home=D:\Easit\EasitGOProd\Tomcat
-Dcatalina.base=D:\Easit\EasitGOProd\Tomcat
-Dignore.endorsed.dirs=D:\Easit\EasitGOProd\Tomcat\endorsed
-Djava.io.tmpdir=D:\Easit\EasitGOProd\Tomcat\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=D:\Easit\EasitGOProd\Tomcat\conf\logging.properties
-Dfile.encoding=UTF8
-Djava.locale.providers=COMPAT,CLDR
-XX:+UseG1GC
PS C:\Users\admin>
|
Note the value or save it to a variable.
| PS C:\Users\admin> $tomcatHome = 'D:\Easit\EasitGOProd\Tomcat'
PS C:\Users\admin> $tomcatBin = Join-Path -Path "$tomcatHome" -ChildPath "bin"
|
Create a directory for backups, we suggest that you use the _Backup directory in Easits root directory (usually D:\Easit\_Backup), named something like todays date.
| PS C:\Users\admin> $backupDirectory = New-Item -Path 'D:\Easit\_Backup' -Name (Get-Date -Format 'yyyy-MM-dd') -ItemType Directory
|
Now we start the actual backup process of the Tomcat service.
| PS C:\Users\admin> Copy-Item -Path (Join-Path -Path "$tomcatHome" -ChildPath 'conf') -Recurse -Destination $backupDirectory
PS C:\Users\admin> Get-ChildItem -Path (Join-Path -Path "$tomcatHome" -ChildPath 'webapps') -Recurse -Include '*.war' | Copy-Item -Destination $backupDirectory
PS C:\Users\admin> Get-ChildItem -Path (Join-Path -Path "$tomcatHome" -ChildPath 'bin') -Recurse -Include 'AddTomcatService.bat' | Copy-Item -Destination $backupDirectory
PS C:\Users\admin> Compress-Archive -Path $tomcatHome -DestinationPath $backupDirectory -CompressionLevel Optimal
|
Your backupDirectory should now look like this.
| PS C:\Users\admin> Get-ChildItem -Path $backupDirectory
Directory: D:\Easit\_Backup\2023-01-01
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2023-01-01 12:15 conf
-a---- 2023-01-01 12:15 Tomcat.zip
-a---- 2023-01-01 12:15 Root.war
|
We can now continue with removing the Tomcat service.
Remove service
First we need to change working directory to the bin directory in tomcatHome.
| PS C:\Users\admin> Set-Location -Path (Join-Path -Path "$tomcatHome" -ChildPath 'bin')
|
And then we remove the Tomcat service.
| PS D:\Easit\EasitGOProd\Tomcat\bin> .\service.bat remove $serviceName
|
Rename tomcatHome to enable us to install the new service in the next step.
| PS D:\Easit\EasitGOProd\Tomcat\bin> Set-Location -Path (Split-Path -Path $tomcatHome)
PS D:\Easit\EasitGOProd\> Rename-Item -Path $tomcatHome -NewName 'old_Tomcat'
|
Install service
Depending on if you have a Tomcat package from Easit or directly from Apache foundation the naming and root directories my vary but you should expand the Tomcat package and rename directories so that you will have a directory structure looking like this:
- Easit
- EasitGOProd
- old_Tomcat
- Tomcat
- bin
We then copy the AddTomcatService.bat file to the bin directory in the new Tomcat directory. If you got the Tomcat package from Easit, you do not need to do this as it is already included.
| PS D:\Easit\EasitGOProd\> Get-ChildItem -Path $backupDirectory -Recurse -Include 'AddTomcatService.bat' | Copy-Item -Destination (Join-Path -Path "$tomcatHome" -ChildPath 'bin')
|
We then copy the java directory from the old Tomcat directory to the new Tomcat directory. If you got the Tomcat package from Easit, you do not need to do this as it is already included.
| PS D:\Easit\EasitGOProd\> Copy-Item -Path (Join-Path -Path (Join-Path -Path "$pwd" -ChildPath 'old_Tomcat') -ChildPath 'jre') -Destination "$tomcatHome" -Recurse
|
Now we change working directory to the bin directory in the new Tomcat directory and use AddTomcatService.bat to install a new Tomcat service.
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | PS D:\Easit\EasitGOProd> Set-Location -Path (Join-Path -Path $tomcatHome -ChildPath 'bin')
PS D:\Easit\EasitGOProd\Tomcat\bin> .\AddTomcatService.bat $serviceName
D:\Easit\EasitGOProd
D:\Easit\EasitGOProd\Tomcat
Installing the service 'EasitGOProd' ...
Using CATALINA_HOME: "D:\Easit\EasitGOProd\Tomcat"
Using CATALINA_BASE: "D:\Easit\EasitGOProd\Tomcat"
Using JAVA_HOME: ""
Using JRE_HOME: "D:\Easit\EasitGOProd\Tomcat\jre"
Using JVM: "D:\Easit\EasitGOProd\Tomcat\jre\bin\server\jvm.dll"
The service 'EasitGOProd' has been installed.
Press any key to continue . . .
PS D:\Easit\EasitGOProd\Tomcat\bin>
|
If you do not wish to use AddTomcatService.bat you can use service.bat instead.
This requires the following environment variables: "JRE_HOME", "CATALINA_BASE", "JvmMs" and "JvmMx".
| PS D:\Easit\EasitGOProd\Tomcat\bin> .\service.bat install $serviceName
|
Restore service settings
Before we can start the service, and thereby Easit GO, again we need to restore some settings and the war file.
| PS D:\Easit\EasitGOProd\Tomcat\bin> Get-ChildItem -Path (Join-Path -Path "$backupDirectory" -ChildPath 'conf') -Recurse -Include 'server.xml' | Copy-Item -Destination (Join-Path -Path $tomcatHome -ChildPath 'conf') -Force
PS D:\Easit\EasitGOProd\Tomcat\bin> Get-ChildItem -Path (Join-Path -Path "$backupDirectory" -ChildPath 'conf') -Recurse -Include 'context.xml' | Copy-Item -Destination (Join-Path -Path $tomcatHome -ChildPath 'conf') -Force
PS D:\Easit\EasitGOProd\Tomcat\bin> Get-ChildItem -Path "$backupDirectory" -Recurse -Include '*.war' | Copy-Item -Destination (Join-Path -Path $tomcatHome -ChildPath 'webapps')
PS D:\Easit\EasitGOProd\Tomcat\bin>
|
Last, but not least, update the service Log On, Initial memory pool and Maximum memory pool settings either by navigating to $tomcatHome\bin, right click on [serviceName]w.exe, choose Run as administrator and then click on the tab Log On and Java OR running the command below.
| PS D:\Easit\EasitGOProd\Tomcat\bin> & (Get-ChildItem -Path ".\*" -Recurse -Include "${serviceName}w.exe")
|
Both ways open the GUI for administer the Tomcat service as shows below.
Log On |
Java |
|
|
If you have followed the steps above under Backup service settings you should have all settings either in your PowerShell console or C:\Users\admin\tomcatSettings.txt.
Start service
When you have restored the settings for LogOn and Java we can start the service.
| PS D:\Easit\EasitGOProd\Tomcat\bin> Get-Service -Name $serviceName | Start-Service
|
Cleanup
Now we can remove the Tomcat directory containing the old service.
| PS D:\Easit\EasitGOProd\Tomcat\bin> Set-Location -Path (Split-Path -Path $tomcatHome)
PS D:\Easit\EasitGOProd> Remove-Item -Path (Join-Path -Path "$pwd" -ChildPath 'old_Tomcat') -Recurse -Force
|