|
1 | 1 | param( |
2 | | - [ValidateSet("BackupPACSDatabase","BackupMWLDatabase","RotateLogs")] |
3 | 2 | [string]$BaseInstallPath = "C:\Program Files\NHS\ManageBreastScreeningGateway", |
| 3 | + [Parameter(Mandatory)] |
4 | 4 | [string]$Action |
5 | 5 | ) |
6 | 6 |
|
@@ -72,7 +72,12 @@ function Start-AllServices { |
72 | 72 | Start-Sleep -Milliseconds 500 |
73 | 73 | } |
74 | 74 |
|
75 | | - Write-Log "$($svc.Name) started." "SUCCESS" |
| 75 | + $finalStatus = Get-Service -Name $svc.Name -ErrorAction SilentlyContinue |
| 76 | + if (-not $finalStatus -or $finalStatus.Status -ne 'Running') { |
| 77 | + throw "Service $($svc.Name) did not start within ${TimeoutSeconds}s (state: $($finalStatus.Status))." |
| 78 | + } |
| 79 | + |
| 80 | + Write-Log "$($svc.Name) started in $([math]::Round($stopwatch.Elapsed.TotalSeconds, 1))s." "SUCCESS" |
76 | 81 | } |
77 | 82 | } |
78 | 83 |
|
@@ -178,27 +183,33 @@ function Archive-PACS { |
178 | 183 |
|
179 | 184 | # -- Main ---------------------------------------------------------------------- |
180 | 185 |
|
| 186 | +$startStopTimeoutSeconds = 30 |
| 187 | + |
181 | 188 | switch ($Action) { |
182 | 189 |
|
183 | 190 | "RotateLogs" { |
184 | | - Stop-AllServices -Services $Services |
| 191 | + Stop-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
185 | 192 | Rotate-ServiceLogs -Services $services -LogsDir $logsDir |
186 | | - Start-AllServices -Services $Services |
| 193 | + Start-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
187 | 194 | } |
188 | 195 |
|
189 | 196 | "BackupPACSDatabase" { |
190 | | - Stop-AllServices -Services $Services |
| 197 | + Stop-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
191 | 198 | Invoke-DatabaseBackup -BaseInstallPath $BaseInstallPath -DbServiceName "PACS" |
192 | 199 | Archive-PACS -BaseInstallPath $BaseInstallPath |
193 | | - Start-AllServices -Services $Services |
| 200 | + Start-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
194 | 201 | } |
195 | 202 |
|
196 | 203 | "BackupMWLDatabase" { |
197 | | - Stop-AllServices -Services $Services |
| 204 | + Stop-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
198 | 205 | Invoke-DatabaseBackup -BaseInstallPath $BaseInstallPath -DbServiceName "MWL" |
199 | | - Start-AllServices -Services $Services |
| 206 | + Start-AllServices -Services $Services -TimeoutSeconds $startStopTimeoutSeconds |
200 | 207 | } |
201 | 208 |
|
| 209 | + default { |
| 210 | + Write-Log "Unknown action: $Action" "ERROR" |
| 211 | + throw "Unknown action: $Action" |
| 212 | + } |
202 | 213 | } |
203 | 214 |
|
204 | 215 | exit 0 |
0 commit comments