From afb6229f57be6a180ccccd7c5c44252512db8b80 Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 5 Aug 2025 16:07:22 +0000 Subject: [PATCH] Upload files to "Services Scripts" --- ...ver - Apache Services Restart in Order.ps1 | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Services Scripts/MFA Server - Apache Services Restart in Order.ps1 diff --git a/Services Scripts/MFA Server - Apache Services Restart in Order.ps1 b/Services Scripts/MFA Server - Apache Services Restart in Order.ps1 new file mode 100644 index 0000000..b3eab71 --- /dev/null +++ b/Services Scripts/MFA Server - Apache Services Restart in Order.ps1 @@ -0,0 +1,51 @@ +#MFA DB server +$ServerName = "" + +#Names of services that need to start and listed in correct order +$ServiceName1 = "Tomcat8_Core" +$ServiceName2 = "Tomcat8_BackOffice" +$ServiceName3 = "Tomcat8_Scheduler" +#Variables for getting info about each service +$Service1 = Get-Service -Name $ServiceName1 +$Service2 = Get-Service -Name $ServiceName2 +$Service3 = Get-Service -Name $ServiceName3 + +#Testing the connection to the DB server(must be online before services can start) +If (Test-Connection $ServerName) { + + #If DB server is up then stop all services + Stop-Service $ServiceName1 -Force -verbose + Stop-Service $ServiceName2 -Force -verbose + Stop-Service $ServiceName3 -Force -verbose + + #Refreshes the status of each service + $Service1.Refresh() + $Service2.Refresh() + $Service3.Refresh() + #Making sure all 3 services are stopped before bringing them up in correct order + If ($Service1.status -and $Service2.status -and $Service3.status -eq "Stopped") { + Start-Service $ServiceName1 -verbose + Start-Sleep -seconds 60 + $Service1.Refresh() + + If ($Service1.status -eq "Running") { + Start-Service $ServiceName2 -verbose + Start-Sleep -seconds 60 + $Service2.Refresh() + } + If ($Service2.status -eq "Running") { + Start-Service $ServiceName3 -verbose + Start-Sleep -seconds 30 + $Service3.Refresh() + } + } + If ($Service1.status -and $Service2.status -and $Service3.status -eq "Running") { + Write-Host "Script successfully restarted services in correct order" + } + Else { + Write-Host "Services did not get restarted correctly. Please run script again or manually start services" + } +} +Else { + Write-host "Ping to $ServerName failed, exiting script" +} \ No newline at end of file