Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot specify custom configuration filename #1057

Open
chris-zenfolio opened this issue Oct 11, 2023 · 2 comments
Open

Cannot specify custom configuration filename #1057

chris-zenfolio opened this issue Oct 11, 2023 · 2 comments
Labels

Comments

@chris-zenfolio
Copy link

chris-zenfolio commented Oct 11, 2023

Summary
I should be able to follow the directions and specify a custom XML configuration filename, but WinSW errors out every time because it does not see a configuration file the same name as the executable. Example: WinSW.NET461.xml or WinSW-x64.xml

Steps to reproduce

  1. Log in to your Windows 11 desktop
  2. Download your preferred flavor of WinSW (Tested using WinSW-x64 and WinSW.NET461 v2.12.0) to a directory (like C:\WinSW)
  3. Create a Configuration File (Mine is posted below) and save it in the directory.
  4. Open Windows PowerShell (5.1) as an Administrator
  5. Change directory to the preferred directory (using C:\WinSW in this example, did test with other directories)
  6. Run .\WinSW.exe install <CONFIGFILENAME>. (Replace WinSW.exe with whatever filename you use for WinSW. I am using the .NET461 version in this reproduction steps, though it also reproduces with x64 version.)
  7. The output from my testing looks like this:
PS C:\winsw> ls


    Directory: C:\winsw


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          8/1/2023   4:27 AM           1000 blackbox_config.yml
-a----        10/11/2023  11:12 AM       20358656 blackbox_exporter.exe
-a----        10/11/2023  11:10 AM            317 blackbox_service.xml
-a----        10/11/2023   1:27 PM         655872 WinSW.exe
-a----        10/11/2023   1:27 PM         655872 WinSW.NET461.exe


PS C:\winsw> .\WinSW.exe install .\blackbox_service.xml
2023-10-11 13:49:47,883 FATAL - Unhandled exception
System.IO.FileNotFoundException: Unable to locate WinSW.[xml|yml] file within executable directory
   at WinSW.Program.LoadConfigAndInitLoggers(Boolean inConsoleMode)
   at WinSW.Program.Run(String[] argsArray, IServiceConfig config)
   at WinSW.Program.Main(String[] args)
PS C:\winsw> mv .\blackbox_service.xml WinSW.xml
PS C:\winsw> .\WinSW.exe install .\WinSW.xml
2023-10-11 13:50:52,507 INFO  - Installing service 'Blackbox Exporter (blackbox_exporter)'...
2023-10-11 13:50:52,522 INFO  - Service 'Blackbox Exporter (blackbox_exporter)' was installed successfully.

Additional Output from different compile targets:

PS C:\winsw> .\WinSW.NET4.exe install .\WinSW.xml
2023-10-11 15:17:32,546 FATAL - Unhandled exception
System.IO.FileNotFoundException: Unable to locate WinSW.NET4.[xml|yml] file within executable directory
   at WinSW.Program.LoadConfigAndInitLoggers(Boolean inConsoleMode)
   at WinSW.Program.Run(String[] argsArray, IServiceConfig config)
   at WinSW.Program.Main(String[] args)
PS C:\winsw> .\WinSW.NET461.exe install .\WinSW.xml
2023-10-11 15:17:50,749 FATAL - Unhandled exception
System.IO.FileNotFoundException: Unable to locate WinSW.NET461.[xml|yml] file within executable directory
   at WinSW.Program.LoadConfigAndInitLoggers(Boolean inConsoleMode)
   at WinSW.Program.Run(String[] argsArray, IServiceConfig config)
   at WinSW.Program.Main(String[] args)
PS C:\winsw> .\WinSW-x64.exe install .\WinSW.xml
2023-10-11 15:18:02,053 FATAL - Unhandled exception
System.IO.FileNotFoundException: Unable to locate WinSW-x64.[xml|yml] file within executable directory
   at WinSW.Program.LoadConfigAndInitLoggers(Boolean inConsoleMode)
   at WinSW.Program.Run(String[] argsArray, IServiceConfig config)
   at WinSW.Program.Main(String[] args)

Here is my configuration file

<service>
    <id>blackbox_exporter</id>
    <name>Blackbox Exporter</name>
    <description>This service runs the Prometheus Blackbox Exporter</description>
    <executable>blackbox_exporter.exe</executable>
    <arguments>--config.file=blackbox_config.yml</arguments>
    <log mode="roll"></log>
  </service>

Environment

PS C:\winsw> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22621.2428
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.2428
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
@chris-zenfolio chris-zenfolio changed the title Cannot specify custom configuration filename (Windows Powershell Cannot specify custom configuration filename Oct 11, 2023
@ctrueltzsch
Copy link

Rename your prefered winsw.exe to blackbox_service.exe

@chris-zenfolio
Copy link
Author

I figured out the problem. The default documentation page is for v3.0 and the "latest release" is v2.0, so a new user can get confused (like I did) very quickly when the documentation doesn't match the behavior.

When I downloaded the pre-release Alpha for testing, the behavior worked as expected with respect to the config file name. Now that I know this, I'm refactoring my Windows PowerShell script to support v2.x behavior because our organization does not permit running pre-release software.

To the maintainers, please leave v2 as your default documentation until v3 is officially the "latest release".

Thanks,
Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants