Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }

Copy link
Copy Markdown
Contributor

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


protected override void BeginProcessing()
{
Account.TestIfAdmin();
}

protected override void ProcessRecord()
{
foreach (var name in Name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
New-Alias -Value Start-ServiceControlMaintenanceMode -Name sc-startmaintenance
New-Alias -Value Stop-ServiceControlMaintenanceMode -Name sc-stopmaintenance
New-Alias -Value Start-ServiceControlAuditMaintenanceMode -Name audit-startmaintenance
New-Alias -Value Stop-ServiceControlAuditMaintenanceMode -Name audit-stopmaintenance

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether mode even adds any value to the full command name. We do have docs that say Maintenance Mode, and the UI says maintenance mode, but it's just extra letters to potentially type in this scenario, and we removed it from the aliases. Either way is probably fine; it's just something to consider the trade-offs of.


Export-ModuleMember * -Alias *

Expand Down
Loading
Loading