Page 1 of 1

start/stop tomcat in docker container

PostPosted:Sat Aug 15, 2020 11:30 pm
by HugoHiasl
Hello,

I am using the openkm/openkm-ce docker image. I did set it up to work with a MSSQL in a docker container.

Now I wrote a backup script that is doing a daily backup for me. Backing up database works. Zipping and backing up repository works in my DEV.

But I have one problem. Whenever I want to stop the tomcat in the container is says that there is no PID file.

I think I am root if I use docker cli. So it should not be a privilge issue.

Can you please let me know how to shut down tomcat before doing backups and how to restart it afterwards.

Thanks a lot.

BTW. This is my backup PowerShell script:
Code: Select all
$date = Get-Date
$dateString = (Get-Date -f yyyy-MM-dd_HHmmss)
$uncServer = "\\192.168.10.10"
$uncFullPath = "$uncServer\OpenKM DB Backup"
$uncMonthlyDir = "monthly"
$uncWeeklyDir = "weekly"
$uncDailyDir = "daily"

$username = "Diskstation\xxx"
$password = "yyy"




iex "docker exec -it mssql1 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P `"xxx`" -Q `"BACKUP DATABASE [OpenKM] TO DISK = N'/var/opt/mssql/backup/openkm.bak' WITH NOFORMAT, INIT, NAME = 'OpenKM-full', SKIP, NOREWIND, NOUNLOAD, STATS = 10`""

iex "docker cp mssql1:/var/opt/mssql/backup/openkm.bak openkm_$dateString.bak"

iex "docker exec -it openkm-ce zip -r /opt/openkm/backup/repository_$dateString.zip /opt/openkm/repository/"

iex "docker cp openkm-ce:/opt/openkm/backup/repository_$dateString.zip repository_$dateString.zip"

iex "docker exec -it openkm-ce rm /opt/openkm/backup/repository_$dateString.zip"

net use $uncServer $password /USER:$username  
try  
{

	

if ($date.Day -eq 1) {
	if (-not (Test-Path -LiteralPath "$uncFullPath\$uncMonthlyDir")) {
		New-Item -Path "$uncFullPath" -Name "$uncMonthlyDir" -ItemType "directory"
	}

	Copy-Item "openkm_$dateString.bak" "$uncFullPath\$uncMonthlyDir\openkm_$dateString.bak"
	Copy-Item "repository_$dateString.zip" "$uncFullPath\$uncMonthlyDir\repository_$dateString.zip"
	Get-ChildItem "$uncFullPath\$uncMonthlyDir\" |? {$_.lastwritetime -le (Get-Date).AddMonths(-1)} |% {Remove-Item $_ -force }  
}elseif ([int] $date.DayOfWeek -eq 0) {
	if (-not (Test-Path -LiteralPath "$uncFullPath\$uncWeeklyDir")) {
		New-Item -Path "$uncFullPath" -Name "$uncWeeklyDir" -ItemType "directory"
	}

	Copy-Item "openkm_$dateString.bak" "$uncFullPath\$uncWeeklyDir\openkm_$dateString.bak"
	Copy-Item "repository_$dateString.zip" "$uncFullPath\$uncWeeklyDir\repository_$dateString.zip"
	Get-ChildItem "$uncFullPath\$uncWeeklyDir\" |? {$_.lastwritetime -le (Get-Date).AddMonths(-1)} |% {Remove-Item $_ -force }  
} else {
	if (-not (Test-Path -LiteralPath "$uncFullPath\$uncDailyDir")) {
		New-Item -Path "$uncFullPath" -Name "$uncDailyDir" -ItemType "directory"
	}
	Copy-Item "openkm_$dateString.bak" "$uncFullPath\$uncDailyDir\openkm_$dateString.bak"
	Copy-Item "repository_$dateString.zip" "$uncFullPath\$uncDailyDir\repository_$dateString.zip"
	Get-ChildItem "$uncFullPath\$uncDailyDir\" |? {$_.lastwritetime -le (Get-Date).AddDays(-8)} |% {Remove-Item $_ -force }  
}
}
catch [System.Exception] {  
	$pw = Get-Content .\MailPW.txt | ConvertTo-SecureString	
	$cred = New-Object System.Management.Automation.PSCredential "oengst@engst.de", $pw
	Send-MailMessage -Credential $cred -to "oengst@engst.de" -from "oengst@engst.de" -subject "Error OpenKM Backup" -SmtpServer "smtp.strato.de" -UseSSL

}
finally {  
      net use $uncServer /delete  
}

Re: start/stop tomcat in docker container

PostPosted:Mon Aug 17, 2020 10:46 am
by HugoHiasl
If I execute shutdown.sh in /opt/openkm/bin is says:

$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.

But if I connect to the given port 8080 I can use openkm. So it must be running.

Re: start/stop tomcat in docker container

PostPosted:Mon Aug 17, 2020 12:57 pm
by HugoHiasl
The solution is to use a host directory as repository volume (or a docker persistent volume).

This way the tomcat (openkm/openkm-ce) container can be stopped and the repository is still available for backup.

Reason why you need a mounted volume is because if running tomcat in the docker a tomcat shutdown also stops the container.