forked from Topshelf/Topshelf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added configuration for service recovery options
- Loading branch information
1 parent
4686319
commit 4c93f3c
Showing
5 changed files
with
265 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Topshelf.Extensions.Configuration/Options/ServiceRecoveryOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2007-2014 Chris Patterson, Dru Sellers, Travis Smith, et. al. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
// this file except in compliance with the License. You may obtain a copy of the | ||
// License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software distributed | ||
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations under the License. | ||
#if !NETCORE | ||
namespace Topshelf.Options | ||
{ | ||
using Topshelf.HostConfigurators; | ||
using Topshelf.Runtime.Windows; | ||
|
||
/// <summary> | ||
/// Represents an option to set a service recovery options. | ||
/// </summary> | ||
/// <seealso cref="Option" /> | ||
public class ServiceRecoveryOption | ||
: Option | ||
{ | ||
private readonly ServiceRecoveryOptions serviceRecoveryOptions; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ServiceRecoveryOption"/> class. | ||
/// </summary> | ||
/// <param name="serviceRecoveryOptions">The service recovery options.</param> | ||
public ServiceRecoveryOption(ServiceRecoveryOptions serviceRecoveryOptions) | ||
{ | ||
this.serviceRecoveryOptions = serviceRecoveryOptions; | ||
} | ||
|
||
/// <summary> | ||
/// Applies the option to the specified host configurator. | ||
/// </summary> | ||
/// <param name="configurator">The host configurator.</param> | ||
public void ApplyTo(HostConfigurator configurator) | ||
{ | ||
var recoveryHostConfigurator = new ServiceRecoveryHostConfigurator(); | ||
|
||
foreach (var option in serviceRecoveryOptions.Actions) | ||
{ | ||
switch (option) | ||
{ | ||
case RestartServiceRecoveryAction restartServiceRecoveryAction: | ||
recoveryHostConfigurator.RestartService(restartServiceRecoveryAction.Delay); | ||
break; | ||
case RestartSystemRecoveryAction restartSystemRecoveryAction: | ||
recoveryHostConfigurator.RestartComputer(restartSystemRecoveryAction.Delay, restartSystemRecoveryAction.RestartMessage); | ||
break; | ||
case RunProgramRecoveryAction runProgramRecoveryAction: | ||
recoveryHostConfigurator.RunProgram(runProgramRecoveryAction.Delay, runProgramRecoveryAction.Command); | ||
break; | ||
} | ||
} | ||
|
||
if (this.serviceRecoveryOptions.RecoverOnCrashOnly) | ||
{ | ||
recoveryHostConfigurator.OnCrashOnly(); | ||
} | ||
|
||
recoveryHostConfigurator.SetResetPeriod(this.serviceRecoveryOptions.ResetPeriod); | ||
|
||
configurator.AddConfigurator(recoveryHostConfigurator); | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters