Support both XML and YAML configuration + Remove support for *.vshost files and folder hierarchy lookup which used to be an undocumented development features (#641)

* Sync with upstream (#3)

* Add a Dependabot configuration (#558)

* Add a Dependabot configuration

* Update dependabot.yml

* Bump NUnit3TestAdapter from 3.16.0 to 3.16.1 (#561)

Bumps [NUnit3TestAdapter](https://github.com/nunit/nunit3-vs-adapter) from 3.16.0 to 3.16.1.
- [Release notes](https://github.com/nunit/nunit3-vs-adapter/releases)
- [Commits](https://github.com/nunit/nunit3-vs-adapter/compare/V3.16...V3.16.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump Microsoft.NET.Test.Sdk from 16.4.0 to 16.6.1 (#563)

Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.4.0 to 16.6.1.
- [Release notes](https://github.com/microsoft/vstest/releases)
- [Commits](https://github.com/microsoft/vstest/compare/v16.4.0...v16.6.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ilmerge from 3.0.29 to 3.0.40 (#559)

* Bump ilmerge from 3.0.29 to 3.0.40

Bumps [ilmerge](https://github.com/dotnet/ILMerge) from 3.0.29 to 3.0.40.
- [Release notes](https://github.com/dotnet/ILMerge/releases)
- [Commits](https://github.com/dotnet/ILMerge/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* Define $(ILMergeVersion)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Next Turn <45985406+NextTurn@users.noreply.github.com>

* Bump coverlet.collector from 1.2.0 to 1.3.0 (#560)

Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 1.2.0 to 1.3.0.
- [Release notes](https://github.com/coverlet-coverage/coverlet/releases)
- [Commits](https://github.com/coverlet-coverage/coverlet/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ilmerge from 3.0.40 to 3.0.41 (#571)

Bumps [ilmerge](https://github.com/dotnet/ILMerge) from 3.0.40 to 3.0.41.
- [Release notes](https://github.com/dotnet/ILMerge/releases)
- [Commits](https://github.com/dotnet/ILMerge/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: Oleg Nenashev <o.v.nenashev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Next Turn <45985406+NextTurn@users.noreply.github.com>

* Update winsw to work with both XML and YAML config

Add logic to select configuration type
Remove redundant codes for config file finding

* Update ConfigType.cs file encoding

* Reference yamlonfiguration.md file from the Readme.md

* Refactor yaml and xml support

Update  naming conventions in Readme.md
Remove ConfigType.cs

* Refactors

* Update Program.cs

* Remove recursive look for configurations file

Remove trimming .vshost extension in executable file name

* Update Program.cs

Co-authored-by: Oleg Nenashev <o.v.nenashev@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Next Turn <45985406+NextTurn@users.noreply.github.com>
pull/644/head
Buddhika Chathuranga 2020-08-10 16:53:54 +05:30 committed by GitHub
parent 57dbe910cb
commit 853e5aeec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 60 deletions

View File

@ -33,7 +33,7 @@ Binaries are available [here](https://repo.jenkins-ci.org/releases/com/sun/winsw
## Usage
WinSW is being managed by configuration files: [Main XML configuration file](doc/xmlConfigFile.md) and [EXE configuration file](doc/exeConfigFile.md).
WinSW is being managed by configuration files: [Main XML configuration file](doc/xmlConfigFile.md) and [Main YAML configuration file](doc/yamlConfigFile.md).
Your renamed *WinSW.exe* binary also accepts the following commands:
@ -59,7 +59,7 @@ User documentation:
* [Installation guide](doc/installation.md) - Describes the installation process for different systems and .NET versions
* Configuration:
* [Main XML configuration file](doc/xmlConfigFile.md)
* [EXE configuration file](doc/exeConfigFile.md)
* [Main YAML configuration file](doc/yamlConfigFile.md)
* [Logging and error reporting](doc/loggingAndErrorReporting.md)
* [Extensions](doc/extensions/extensions.md)
* Use-cases:

View File

@ -21,6 +21,7 @@ using log4net.Layout;
using WinSW.Configuration;
using WinSW.Logging;
using WinSW.Native;
using WinSW.Util;
using WMI;
using ServiceType = WMI.ServiceType;
@ -64,7 +65,7 @@ namespace WinSW
bool inConsoleMode = argsArray.Length > 0;
// If descriptor is not specified, initialize the new one (and load configs from there)
descriptor ??= new ServiceDescriptor();
descriptor ??= GetServiceDescriptor();
// Configure the wrapper-internal logging.
// STDOUT and STDERR of the child process will be handled independently.
@ -658,6 +659,26 @@ namespace WinSW
}
}
private static IWinSWConfiguration GetServiceDescriptor()
{
var executablePath = new DefaultWinSWSettings().ExecutablePath;
var baseName = Path.GetFileNameWithoutExtension(executablePath);
var d = new DirectoryInfo(Path.GetDirectoryName(executablePath));
if (File.Exists(Path.Combine(d.FullName, baseName + ".xml")))
{
return new ServiceDescriptor(baseName, d);
}
if (File.Exists(Path.Combine(d.FullName, baseName + ".yml")))
{
return new ServiceDescriptorYaml(baseName, d).Configurations;
}
throw new FileNotFoundException($"Unable to locate { baseName }.[xml|yml] file within executable directory");
}
private static void PrintHelp()
{
Console.WriteLine("A wrapper binary that can be used to host executables as Windows services");

View File

@ -73,11 +73,6 @@ namespace WinSW
eventLogProvider.Service = this;
}
public WrapperService()
: this(new ServiceDescriptor())
{
}
/// <summary>
/// Process the file copy instructions, so that we can replace files that are always in use while
/// the service runs.

View File

@ -41,34 +41,8 @@ namespace WinSW
// Currently there is no opportunity to alter the executable path
public virtual string ExecutablePath => Defaults.ExecutablePath;
public ServiceDescriptor()
public ServiceDescriptor(string baseName, DirectoryInfo d)
{
// find co-located configuration xml. We search up to the ancestor directories to simplify debugging,
// as well as trimming off ".vshost" suffix (which is used during debugging)
// Get the first parent to go into the recursive loop
string p = this.ExecutablePath;
string baseName = Path.GetFileNameWithoutExtension(p);
if (baseName.EndsWith(".vshost"))
{
baseName = baseName.Substring(0, baseName.Length - 7);
}
DirectoryInfo d = new DirectoryInfo(Path.GetDirectoryName(p));
while (true)
{
if (File.Exists(Path.Combine(d.FullName, baseName + ".xml")))
{
break;
}
if (d.Parent is null)
{
throw new FileNotFoundException("Unable to locate " + baseName + ".xml file within executable directory or any parents");
}
d = d.Parent;
}
this.BaseName = baseName;
this.BasePath = Path.Combine(d.FullName, this.BaseName);

View File

@ -7,35 +7,12 @@ namespace WinSW
{
public class ServiceDescriptorYaml
{
public readonly YamlConfiguration Configurations = new YamlConfiguration();
public readonly YamlConfiguration Configurations;
public static DefaultWinSWSettings Defaults { get; } = new DefaultWinSWSettings();
public ServiceDescriptorYaml()
public ServiceDescriptorYaml(string baseName, DirectoryInfo d)
{
string p = Defaults.ExecutablePath;
string baseName = Path.GetFileNameWithoutExtension(p);
if (baseName.EndsWith(".vshost"))
{
baseName = baseName.Substring(0, baseName.Length - 7);
}
DirectoryInfo d = new DirectoryInfo(Path.GetDirectoryName(p));
while (true)
{
if (File.Exists(Path.Combine(d.FullName, baseName + ".yml")))
{
break;
}
if (d.Parent is null)
{
throw new FileNotFoundException("Unable to locate " + baseName + ".yml file within executable directory or any parents");
}
d = d.Parent;
}
var basepath = Path.Combine(d.FullName, baseName);
using (var reader = new StreamReader(basepath + ".yml"))