Skip to content
Open
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,42 @@
namespace ServiceControl.Management.PowerShell
{
using System;
using System.Linq;
using System.Management.Automation;
using ServiceControlInstaller.Engine.Instances;

[Cmdlet(VerbsLifecycle.Start, "ServiceControlAuditMaintenance")]
public class StartServiceControlAuditMaintenance : 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()
{
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");
return;
}

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,37 @@
namespace ServiceControl.Management.PowerShell
{
using System;
using System.Linq;
using System.Management.Automation;
using ServiceControlInstaller.Engine.Instances;

[Cmdlet(VerbsLifecycle.Stop, "ServiceControlAuditMaintenance")]
public class StopServiceControlAuditMaintenance : 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()
{
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");
return;
}

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,42 @@
namespace ServiceControl.Management.PowerShell
{
using System;
using System.Linq;
using System.Management.Automation;
using ServiceControlInstaller.Engine.Instances;

[Cmdlet(VerbsLifecycle.Start, "ServiceControlMaintenance")]
public class StartServiceControlMaintenance : 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()
{
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");
return;
}

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,37 @@
namespace ServiceControl.Management.PowerShell
{
using System;
using System.Linq;
using System.Management.Automation;
using ServiceControlInstaller.Engine.Instances;

[Cmdlet(VerbsLifecycle.Stop, "ServiceControlMaintenance")]
public class StopServiceControlMaintenance : 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()
{
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");
return;
}

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-ServiceControlMaintenance -Name sc-startmaintenance
New-Alias -Value Stop-ServiceControlMaintenance -Name sc-stopmaintenance
New-Alias -Value Start-ServiceControlAuditMaintenance -Name audit-startmaintenance
New-Alias -Value Stop-ServiceControlAuditMaintenance -Name audit-stopmaintenance

Export-ModuleMember * -Alias *

Expand Down
Loading
Loading