mirror of https://github.com/winsw/winsw
[JENKINS-42744] - Allow ignoring the WINSW_SERVICE_ID env variable (test-only for now)
parent
bca9bafc66
commit
9cfdcf4ae7
|
@ -27,6 +27,12 @@ namespace winsw.Plugins.RunawayProcessKiller
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool StopParentProcessFirst { get; private set; }
|
public bool StopParentProcessFirst { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If true, the runaway process will be checked for the WinSW environment variable before termination.
|
||||||
|
/// This option is not documented AND not supposed to be used by users.
|
||||||
|
/// </summary>
|
||||||
|
public bool CheckWinSWEnvironmentVariable { get; private set; }
|
||||||
|
|
||||||
public override String DisplayName { get { return "Runaway Process Killer"; } }
|
public override String DisplayName { get { return "Runaway Process Killer"; } }
|
||||||
|
|
||||||
private String ServiceId { get; set; }
|
private String ServiceId { get; set; }
|
||||||
|
@ -38,11 +44,12 @@ namespace winsw.Plugins.RunawayProcessKiller
|
||||||
// Default initializer
|
// Default initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
public RunawayProcessKillerExtension(String pidfile, int stopTimeoutMs = 5000, bool stopParentFirst = false)
|
public RunawayProcessKillerExtension(String pidfile, int stopTimeoutMs = 5000, bool stopParentFirst = false, bool checkWinSWEnvironmentVariable = true)
|
||||||
{
|
{
|
||||||
this.Pidfile = pidfile;
|
this.Pidfile = pidfile;
|
||||||
this.StopTimeout = TimeSpan.FromMilliseconds(5000);
|
this.StopTimeout = TimeSpan.FromMilliseconds(5000);
|
||||||
this.StopParentProcessFirst = stopParentFirst;
|
this.StopParentProcessFirst = stopParentFirst;
|
||||||
|
this.CheckWinSWEnvironmentVariable = checkWinSWEnvironmentVariable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Configure(ServiceDescriptor descriptor, XmlNode node)
|
public override void Configure(ServiceDescriptor descriptor, XmlNode node)
|
||||||
|
@ -53,6 +60,9 @@ namespace winsw.Plugins.RunawayProcessKiller
|
||||||
StopTimeout = TimeSpan.FromMilliseconds(Int32.Parse(XmlHelper.SingleElement(node, "stopTimeout", false)));
|
StopTimeout = TimeSpan.FromMilliseconds(Int32.Parse(XmlHelper.SingleElement(node, "stopTimeout", false)));
|
||||||
StopParentProcessFirst = Boolean.Parse(XmlHelper.SingleElement(node, "stopParentFirst", false));
|
StopParentProcessFirst = Boolean.Parse(XmlHelper.SingleElement(node, "stopParentFirst", false));
|
||||||
ServiceId = descriptor.Id;
|
ServiceId = descriptor.Id;
|
||||||
|
//TODO: Consider making it documented
|
||||||
|
var checkWinSWEnvironmentVariable = XmlHelper.SingleElement(node, "checkWinSWEnvironmentVariable", true);
|
||||||
|
CheckWinSWEnvironmentVariable = checkWinSWEnvironmentVariable != null ? Boolean.Parse(checkWinSWEnvironmentVariable) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -113,7 +123,7 @@ namespace winsw.Plugins.RunawayProcessKiller
|
||||||
{
|
{
|
||||||
affiliatedServiceId = previousProcessEnvVars[expectedEnvVarName];
|
affiliatedServiceId = previousProcessEnvVars[expectedEnvVarName];
|
||||||
}
|
}
|
||||||
else
|
else if (CheckWinSWEnvironmentVariable)
|
||||||
{
|
{
|
||||||
Logger.Warn("The process " + pid + " has no " + expectedEnvVarName + " environment variable defined. "
|
Logger.Warn("The process " + pid + " has no " + expectedEnvVarName + " environment variable defined. "
|
||||||
+ "The process has not been started by WinSW, hence it won't be terminated.");
|
+ "The process has not been started by WinSW, hence it won't be terminated.");
|
||||||
|
@ -125,9 +135,14 @@ namespace winsw.Plugins.RunawayProcessKiller
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We just skip this check
|
||||||
|
affiliatedServiceId = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the service ID value
|
// Check the service ID value
|
||||||
if (!ServiceId.Equals(affiliatedServiceId))
|
if (CheckWinSWEnvironmentVariable && !ServiceId.Equals(affiliatedServiceId))
|
||||||
{
|
{
|
||||||
Logger.Warn("The process " + pid + " has been started by Windows service with ID='" + affiliatedServiceId + "'. "
|
Logger.Warn("The process " + pid + " has been started by Windows service with ID='" + affiliatedServiceId + "'. "
|
||||||
+ "It is another service (current service id is '" + ServiceId + "'), hence the process won't be terminated.");
|
+ "It is another service (current service id is '" + ServiceId + "'), hence the process won't be terminated.");
|
||||||
|
|
|
@ -89,8 +89,11 @@ namespace winswTests.Extensions
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Generate extension and ensure that the roundtrip is correct
|
// Generate extension and ensure that the roundtrip is correct
|
||||||
|
//TODO: checkWinSWEnvironmentVariable should be true, but it does not work due to proc.StartInfo.EnvironmentVariables
|
||||||
var pidfile = Path.Combine(tmpDir, "process.pid");
|
var pidfile = Path.Combine(tmpDir, "process.pid");
|
||||||
var sd = ConfigXmlBuilder.create(id: winswId).WithRunawayProcessKiller(new RunawayProcessKillerExtension(pidfile), extensionId).ToServiceDescriptor();
|
var sd = ConfigXmlBuilder.create(id: winswId)
|
||||||
|
.WithRunawayProcessKiller(new RunawayProcessKillerExtension(pidfile, checkWinSWEnvironmentVariable: false), extensionId)
|
||||||
|
.ToServiceDescriptor();
|
||||||
WinSWExtensionManager manager = new WinSWExtensionManager(sd);
|
WinSWExtensionManager manager = new WinSWExtensionManager(sd);
|
||||||
manager.LoadExtensions();
|
manager.LoadExtensions();
|
||||||
var extension = manager.Extensions[extensionId] as RunawayProcessKillerExtension;
|
var extension = manager.Extensions[extensionId] as RunawayProcessKillerExtension;
|
||||||
|
|
|
@ -113,6 +113,7 @@ namespace winswTests.Util
|
||||||
str.AppendFormat(" <pidfile>{0}</pidfile>\n", ext.Pidfile);
|
str.AppendFormat(" <pidfile>{0}</pidfile>\n", ext.Pidfile);
|
||||||
str.AppendFormat(" <stopTimeout>{0}</stopTimeout>\n", ext.StopTimeout.TotalMilliseconds);
|
str.AppendFormat(" <stopTimeout>{0}</stopTimeout>\n", ext.StopTimeout.TotalMilliseconds);
|
||||||
str.AppendFormat(" <stopParentFirst>{0}</stopParentFirst>\n", ext.StopParentProcessFirst);
|
str.AppendFormat(" <stopParentFirst>{0}</stopParentFirst>\n", ext.StopParentProcessFirst);
|
||||||
|
str.AppendFormat(" <checkWinSWEnvironmentVariable>{0}</checkWinSWEnvironmentVariable>\n", ext.CheckWinSWEnvironmentVariable);
|
||||||
str.Append( " </extension>\n");
|
str.Append( " </extension>\n");
|
||||||
ExtensionXmls.Add(str.ToString());
|
ExtensionXmls.Add(str.ToString());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue