Remove `<*argument>`

pull/611/head
NextTurn 2020-07-28 00:00:00 +08:00 committed by Next Turn
parent cd951e69df
commit db91805e45
3 changed files with 17 additions and 72 deletions

View File

@ -94,33 +94,36 @@ See the [Logging and error reporting](logging-and-error-reporting.md) page for m
### Arguments ### Arguments
`<argument>` element specifies the arguments to be passed to the executable. The `<arguments>` element specifies the arguments to be passed to the executable.
Winsw will quote each argument if necessary, so do not put quotes in `<argument>` to avoid double quotation.
```xml ```xml
<argument>arg1</argument> <arguments>arg1 arg2 arg3</arguments>
<argument>arg2</argument>
<argument>arg3</argument>
``` ```
`<arguments>` element can be used instead to specify the whole command line in a single element. -or-
```xml
<arguments>
arg1
arg2
arg3
</arguments>
### stopargument/stopexecutable ### stopargument/stopexecutable
~~When the service is requested to stop, winsw simply calls [TerminateProcess function](https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess) to kill the service instantly.~~ ~~When the service is requested to stop, winsw simply calls [TerminateProcess function](https://docs.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminateprocess) to kill the service instantly.~~
However, if `<stopargument>`/`<stoparguments>` elements are present, winsw will instead launch another process of `<executable>` (or `<stopexecutable>` if that's specified) with the specified arguments, and expects that to initiate the graceful shutdown of the service process. However, if the `<stoparguments>` element is present, winsw will instead launch another process of `<executable>` (or `<stopexecutable>` if that's specified) with the specified arguments, and expects that to initiate the graceful shutdown of the service process.
Winsw will then wait for the two processes to exit on its own, before reporting back to Windows that the service has terminated. Winsw will then wait for the two processes to exit on its own, before reporting back to Windows that the service has terminated.
When you use the `<stopargument>`/`<stoparguments>`, you must use `<startargument>`/`<startarguments>` instead of `<argument>`. See the complete example below: When you use the `<stoparguments>`, you must use `<startarguments>` instead of `<arguments>`. See the complete example below:
```xml ```xml
<executable>catalina.sh</executable> <executable>catalina.sh</executable>
<startargument>jpda</startargument> <startarguments>jpda run</startarguments>
<startargument>run</startargument>
<stopexecutable>catalina.sh</stopexecutable> <stopexecutable>catalina.sh</stopexecutable>
<stopargument>stop</stopargument> <stoparguments>stop</stoparguments>
``` ```
### Additional commands ### Additional commands

View File

@ -220,61 +220,37 @@ namespace WinSW
public string? StopExecutable => this.SingleElement("stopexecutable", true); public string? StopExecutable => this.SingleElement("stopexecutable", true);
/// <summary> /// <summary>
/// <c>arguments</c> or multiple optional <c>argument</c> elements which overrule the arguments element. /// The <c>arguments</c> element.
/// </summary> /// </summary>
public string Arguments public string Arguments
{ {
get get
{ {
string? arguments = this.AppendTags("argument", null);
if (!(arguments is null))
{
return arguments;
}
XmlNode? argumentsNode = this.dom.SelectSingleNode("//arguments"); XmlNode? argumentsNode = this.dom.SelectSingleNode("//arguments");
return argumentsNode is null ? Defaults.Arguments : Environment.ExpandEnvironmentVariables(argumentsNode.InnerText); return argumentsNode is null ? Defaults.Arguments : Environment.ExpandEnvironmentVariables(argumentsNode.InnerText);
} }
} }
/// <summary> /// <summary>
/// <c>startarguments</c> or multiple optional <c>startargument</c> elements. /// The <c>startarguments</c> element.
/// </summary> /// </summary>
public string? StartArguments public string? StartArguments
{ {
get get
{ {
string? startArguments = this.AppendTags("startargument", null);
if (!(startArguments is null))
{
return startArguments;
}
XmlNode? startArgumentsNode = this.dom.SelectSingleNode("//startarguments"); XmlNode? startArgumentsNode = this.dom.SelectSingleNode("//startarguments");
return startArgumentsNode is null ? null : Environment.ExpandEnvironmentVariables(startArgumentsNode.InnerText); return startArgumentsNode is null ? null : Environment.ExpandEnvironmentVariables(startArgumentsNode.InnerText);
} }
} }
/// <summary> /// <summary>
/// <c>stoparguments</c> or multiple optional <c>stopargument</c> elements. /// The <c>stoparguments</c> element.
/// </summary> /// </summary>
public string? StopArguments public string? StopArguments
{ {
get get
{ {
string? stopArguments = this.AppendTags("stopargument", null);
if (!(stopArguments is null))
{
return stopArguments;
}
XmlNode? stopArgumentsNode = this.dom.SelectSingleNode("//stoparguments"); XmlNode? stopArgumentsNode = this.dom.SelectSingleNode("//stoparguments");
return stopArgumentsNode is null ? null : Environment.ExpandEnvironmentVariables(stopArgumentsNode.InnerText); return stopArgumentsNode is null ? null : Environment.ExpandEnvironmentVariables(stopArgumentsNode.InnerText);
} }
} }

View File

@ -331,40 +331,6 @@ $@"<service>
Assert.Equal("arg", sd.Arguments); Assert.Equal("arg", sd.Arguments);
} }
[Fact]
public void Arguments_NewParam_Single()
{
var sd = ConfigXmlBuilder.Create(this.output)
.WithTag("argument", "--arg1=2")
.ToServiceDescriptor(true);
Assert.Equal(" --arg1=2", sd.Arguments);
}
[Fact]
public void Arguments_NewParam_MultipleArgs()
{
var sd = ConfigXmlBuilder.Create(this.output)
.WithTag("argument", "--arg1=2")
.WithTag("argument", "--arg2=123")
.WithTag("argument", "--arg3=null")
.ToServiceDescriptor(true);
Assert.Equal(" --arg1=2 --arg2=123 --arg3=null", sd.Arguments);
}
/// <summary>
/// Ensures that the new single-argument field has a higher priority.
/// </summary>
[Fact]
public void Arguments_Bothparam_Priorities()
{
var sd = ConfigXmlBuilder.Create(this.output)
.WithTag("arguments", "--arg1=2 --arg2=3")
.WithTag("argument", "--arg2=123")
.WithTag("argument", "--arg3=null")
.ToServiceDescriptor(true);
Assert.Equal(" --arg2=123 --arg3=null", sd.Arguments);
}
[Theory] [Theory]
[InlineData(true)] [InlineData(true)]
[InlineData(false)] [InlineData(false)]