diff --git a/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StartServiceControlAuditMaintenanceMode.cs b/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StartServiceControlAuditMaintenanceMode.cs new file mode 100644 index 0000000000..eeaad435df --- /dev/null +++ b/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StartServiceControlAuditMaintenanceMode.cs @@ -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)); + } + } + } + } +} diff --git a/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StopServiceControlAuditMaintenanceMode.cs b/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StopServiceControlAuditMaintenanceMode.cs new file mode 100644 index 0000000000..1a09df9ff2 --- /dev/null +++ b/src/ServiceControl.Management.PowerShell/Cmdlets/AuditInstances/StopServiceControlAuditMaintenanceMode.cs @@ -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) + { + 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(); + } + } + } +} diff --git a/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StartServiceControlMaintenanceMode.cs b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StartServiceControlMaintenanceMode.cs new file mode 100644 index 0000000000..20f2a7fa00 --- /dev/null +++ b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StartServiceControlMaintenanceMode.cs @@ -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; } + + protected override void BeginProcessing() + { + Account.TestIfAdmin(); + } + + protected override void ProcessRecord() + { + foreach (var name in Name) + { + 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)); + } + } + } + } +} diff --git a/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StopServiceControlMaintenanceMode.cs b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StopServiceControlMaintenanceMode.cs new file mode 100644 index 0000000000..c75007ccc7 --- /dev/null +++ b/src/ServiceControl.Management.PowerShell/Cmdlets/ServiceControlInstances/StopServiceControlMaintenanceMode.cs @@ -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; } + + protected override void BeginProcessing() + { + Account.TestIfAdmin(); + } + + protected override void ProcessRecord() + { + foreach (var name in Name) + { + 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(); + } + } + } +} diff --git a/src/ServiceControl.Management.PowerShell/Particular.ServiceControl.Management.psm1 b/src/ServiceControl.Management.PowerShell/Particular.ServiceControl.Management.psm1 index 5c06c1b9e7..fc2b17fee5 100644 --- a/src/ServiceControl.Management.PowerShell/Particular.ServiceControl.Management.psm1 +++ b/src/ServiceControl.Management.PowerShell/Particular.ServiceControl.Management.psm1 @@ -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 Export-ModuleMember * -Alias * diff --git a/src/ServiceControl.Management.PowerShell/ServiceControl.Management.PowerShell.dll-help.xml b/src/ServiceControl.Management.PowerShell/ServiceControl.Management.PowerShell.dll-help.xml index 42ad697714..febef66b78 100644 --- a/src/ServiceControl.Management.PowerShell/ServiceControl.Management.PowerShell.dll-help.xml +++ b/src/ServiceControl.Management.PowerShell/ServiceControl.Management.PowerShell.dll-help.xml @@ -190,6 +190,374 @@ + + + + Stop-ServiceControlAuditMaintenanceMode + + Stops a ServiceControl Audit instance and clears maintenance mode. + + + + + Stop + ServiceControlAuditMaintenanceMode + + + + Stops the ServiceControl Audit service and removes the maintenance mode setting from its configuration file. The service stays stopped; start it normally to resume ingesting audit messages. Requires an elevated session. Alias: audit-maintenance-stop + + + + Stop-ServiceControlAuditMaintenanceMode + + Name + + Name of the ServiceControl Audit Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + + + + + Name + + Name of the ServiceControl Audit Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + String[] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + Stop-ServiceControlAuditMaintenanceMode -Name Particular.ServiceControl.Audit + + Stops the Particular.ServiceControl.Audit service and clears maintenance mode. + + + + + + + + + + Stop-ServiceControlMaintenanceMode + + Stops a ServiceControl instance and clears maintenance mode. + + + + + Stop + ServiceControlMaintenanceMode + + + + Stops the ServiceControl service and removes the maintenance mode setting from its configuration file. The service stays stopped; start it normally to resume ingesting error messages. Requires an elevated session. Alias: sc-maintenance-stop + + + + Stop-ServiceControlMaintenanceMode + + Name + + Name of the ServiceControl Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + + + + + Name + + Name of the ServiceControl Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + String[] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + Stop-ServiceControlMaintenanceMode -Name Particular.ServiceControl + + Stops the Particular.ServiceControl service and clears maintenance mode. + + + + + + + + + + Start-ServiceControlAuditMaintenanceMode + + Starts a ServiceControl Audit instance in maintenance mode. + + + + + Start + ServiceControlAuditMaintenanceMode + + + + Stops the ServiceControl Audit service, writes the maintenance mode setting to its configuration file, and starts the service again. In maintenance mode the instance does not ingest audit messages and its RavenDB database stays available. Run Stop-ServiceControlAuditMaintenanceMode to clear the setting and stop the service. Requires an elevated session. Alias: audit-maintenance-start + + + + Start-ServiceControlAuditMaintenanceMode + + Name + + Name of the ServiceControl Audit Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + + + + + Name + + Name of the ServiceControl Audit Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + String[] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + Start-ServiceControlAuditMaintenanceMode -Name Particular.ServiceControl.Audit + + Restarts the Particular.ServiceControl.Audit service in maintenance mode. + + + + + + + + + + Start-ServiceControlMaintenanceMode + + Starts a ServiceControl instance in maintenance mode. + + + + + Start + ServiceControlMaintenanceMode + + + + Stops the ServiceControl service, writes the maintenance mode setting to its configuration file, and starts the service again. In maintenance mode the instance does not ingest error messages and its RavenDB database stays available. Run Stop-ServiceControlMaintenanceMode to clear the setting and stop the service. Requires an elevated session. Alias: sc-maintenance-start + + + + Start-ServiceControlMaintenanceMode + + Name + + Name of the ServiceControl Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + + + + + Name + + Name of the ServiceControl Service. This corresponds to the Windows Service Name for the service not the Display Name. + + String[] + + String[] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -------------------------- Example 1 -------------------------- + + PS C:\> + + Start-ServiceControlMaintenanceMode -Name Particular.ServiceControl + + Restarts the Particular.ServiceControl service in maintenance mode. + + + + + +