Repository navigation
Add maintenance mode cmdlets to the PowerShell module #6166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| namespace ServiceControl.Management.PowerShell | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using System.Management.Automation; | ||
| using ServiceControlInstaller.Engine.Instances; | ||
|
|
||
| [Cmdlet(VerbsLifecycle.Start, "ServiceControlAuditMaintenanceMode")] | ||
| public class StartServiceControlAuditMaintenanceMode : PSCmdlet | ||
| { | ||
| [ValidateNotNullOrEmpty] | ||
| [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "Specify the ServiceControl Audit instance name")] | ||
| public string[] Name { get; set; } | ||
|
|
||
| protected override void BeginProcessing() | ||
| { | ||
| Account.TestIfAdmin(); | ||
| } | ||
|
|
||
| protected override void ProcessRecord() | ||
| { | ||
| foreach (var name in Name) | ||
| { | ||
| var instance = InstanceFinder.ServiceControlAuditInstances().FirstOrDefault(i => i.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | ||
| if (instance == null) | ||
| { | ||
| WriteWarning($"No action taken. An instance called {name} was not found"); | ||
| continue; | ||
| } | ||
|
|
||
| if (!instance.TryStopService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to stop {instance.Name}"), "StopFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
|
|
||
| instance.EnableMaintenanceMode(); | ||
|
|
||
| if (!instance.TryStartService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to start {instance.Name}"), "StartFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| namespace ServiceControl.Management.PowerShell | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using System.Management.Automation; | ||
| using ServiceControlInstaller.Engine.Instances; | ||
|
|
||
| [Cmdlet(VerbsLifecycle.Stop, "ServiceControlAuditMaintenanceMode")] | ||
| public class StopServiceControlAuditMaintenanceMode : PSCmdlet | ||
| { | ||
| [ValidateNotNullOrEmpty] | ||
| [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "Specify the ServiceControl Audit instance name")] | ||
| public string[] Name { get; set; } | ||
|
|
||
| protected override void BeginProcessing() | ||
| { | ||
| Account.TestIfAdmin(); | ||
| } | ||
|
|
||
| protected override void ProcessRecord() | ||
| { | ||
| foreach (var name in Name) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this foreach can go away |
||
| { | ||
| var instance = InstanceFinder.ServiceControlAuditInstances().FirstOrDefault(i => i.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | ||
| if (instance == null) | ||
| { | ||
| WriteWarning($"No action taken. An instance called {name} was not found"); | ||
| continue; | ||
| } | ||
|
|
||
| if (!instance.TryStopService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to stop {instance.Name}"), "StopFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
|
|
||
| instance.DisableMaintenanceMode(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| namespace ServiceControl.Management.PowerShell | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using System.Management.Automation; | ||
| using ServiceControlInstaller.Engine.Instances; | ||
|
|
||
| [Cmdlet(VerbsLifecycle.Start, "ServiceControlMaintenanceMode")] | ||
| public class StartServiceControlMaintenanceMode : PSCmdlet | ||
| { | ||
| [ValidateNotNullOrEmpty] | ||
| [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "Specify the ServiceControl instance name")] | ||
| public string[] Name { get; set; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be an array |
||
|
|
||
| protected override void BeginProcessing() | ||
| { | ||
| Account.TestIfAdmin(); | ||
| } | ||
|
|
||
| protected override void ProcessRecord() | ||
| { | ||
| foreach (var name in Name) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for foreach |
||
| { | ||
| var instance = InstanceFinder.ServiceControlInstances().FirstOrDefault(i => i.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | ||
| if (instance == null) | ||
| { | ||
| WriteWarning($"No action taken. An instance called {name} was not found"); | ||
| continue; | ||
| } | ||
|
|
||
| if (!instance.TryStopService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to stop {instance.Name}"), "StopFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
|
|
||
| instance.EnableMaintenanceMode(); | ||
|
|
||
| if (!instance.TryStartService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to start {instance.Name}"), "StartFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| namespace ServiceControl.Management.PowerShell | ||
| { | ||
| using System; | ||
| using System.Linq; | ||
| using System.Management.Automation; | ||
| using ServiceControlInstaller.Engine.Instances; | ||
|
|
||
| [Cmdlet(VerbsLifecycle.Stop, "ServiceControlMaintenanceMode")] | ||
| public class StopServiceControlMaintenanceMode : PSCmdlet | ||
| { | ||
| [ValidateNotNullOrEmpty] | ||
| [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0, HelpMessage = "Specify the ServiceControl instance name")] | ||
| public string[] Name { get; set; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single string not array |
||
|
|
||
| protected override void BeginProcessing() | ||
| { | ||
| Account.TestIfAdmin(); | ||
| } | ||
|
|
||
| protected override void ProcessRecord() | ||
| { | ||
| foreach (var name in Name) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for foreach |
||
| { | ||
| var instance = InstanceFinder.ServiceControlInstances().FirstOrDefault(i => i.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); | ||
| if (instance == null) | ||
| { | ||
| WriteWarning($"No action taken. An instance called {name} was not found"); | ||
| continue; | ||
| } | ||
|
|
||
| if (!instance.TryStopService()) | ||
| { | ||
| ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to stop {instance.Name}"), "StopFailure", ErrorCategory.InvalidResult, null)); | ||
| } | ||
|
|
||
| instance.DisableMaintenanceMode(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,10 @@ New-Alias -Value Get-ServiceControlManagementCommands -Name sc-help | |||||||||||||||||
| New-Alias -Value Get-ServiceControlRemotes -Name sc-remotes | ||||||||||||||||||
| New-Alias -Value Add-ServiceControlRemote -Name sc-addremote | ||||||||||||||||||
| New-Alias -Value Remove-ServiceControlRemote -Name sc-deleteremote | ||||||||||||||||||
| New-Alias -Value Start-ServiceControlMaintenanceMode -Name sc-maintenance-start | ||||||||||||||||||
| New-Alias -Value Stop-ServiceControlMaintenanceMode -Name sc-maintenance-stop | ||||||||||||||||||
| New-Alias -Value Start-ServiceControlAuditMaintenanceMode -Name audit-maintenance-start | ||||||||||||||||||
| New-Alias -Value Stop-ServiceControlAuditMaintenanceMode -Name audit-maintenance-stop | ||||||||||||||||||
|
Comment on lines
+44
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether |
||||||||||||||||||
|
|
||||||||||||||||||
| Export-ModuleMember * -Alias * | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably just be a single string and not an array