-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
Windows port #5
Comments
|
I did a regression check on whether the code compiles for non-Windows systems, and it looks like there is an issue with this trunk merge to 2.6.5: 6e51ff2 The code still compiles, but the documentation does not: http://buildbot.networkupstools.org/public/nut/builders/Ubuntu-natty-x86/builds/322/steps/compile/logs/stdio It looks like it is related to the change to the formatting of the INSTALL file, but it is possible that another related change did not get pulled in from the trunk. |
I think the INSTALL file was overwritten by mistake during that merge with the standard GNU installation instructions: http://trac.networkupstools.org/projects/nut/browser/branches/windows_port/INSTALL?rev=3714 I'm going to copy over the INSTALL from master, and apply this commit: http://trac.networkupstools.org/projects/nut/changeset/2958/ (but @bohe-eaton feel free to update the instructions if they are out of date) |
Document that, at least, this Makefile.am is broken by design (patch #5 from Greg A. Woods) Fossil-ID: SVN r3572
Hello! A few weeks ago I have successfully built NUT in MinGW environment using Windows-v2.6.5-7 branch (you may find a manual I have posted to nut-upsdev mailing list). I would like to help with Windows port development. I have examined the source code of several components (upsd, upsmon, nut) and I have got some ideas. I will be happy to share them with NUT team. MAINTAINER UPDATE: Links to those mail posts in the archive:
|
hi @intrudo , thanks for jumping in. see also ntUPSd - Network UPS Tools Services for Windows (https://github.com/6XGate/ntUPSd) from @6XGate thx and cheers |
Hi @aquette ! Let’s start =) First of all, I would like to say that I am not going to do something without acceptance of NUT Team (it would be great to coordinate high-level tasks at least). Please, feel free to say "no", if something is out of your vision/roadmap. I sent a message with my ideas to nut-upsdev list and discussed some points with @clepple already. You may find there more details why I think so. So, here are just short descriptions.
Sure, I see many minor tasks, but let us discuss them later. The one thing I worry is branch. I was going to fork Windows-v2.6.5-7 branch and completing Windows port there. @clepple thinks that Windows-v2.6.5-7 should be rebased before. Unfortunately, I am not GIT expert and I am afraid that there will be many conflicts during rebase. Moreover, I think that my commits will be quite massive. What is the best way to synchronize master branch and my repository? I will be glad to get any hint. I have looked into sources of ntUPSd project. They are complete different from NUT one, but maybe I will find something useful there. Thanks! |
Let me know if you have further questions about why I don't think a major Windows development effort should be based on that branch. The architectural changes that @intrudo proposed are probably best done by using Windows-v2.6.5-7 as a guide. For instance, there are a lot of |
Well, if you do not mind, I will fork Windows-v2.6.5-7 branch to implement the SAL. After it is completed, we could get back to the question of proper branching and future merge. |
Agreed. For prototyping, I do not mind development on that branch (or a branch of the branch, given that branches are cheap in Git). I just want to make sure that everyone understands that merging (in the Git sense of the word, where two lines of history connect back to each other) any of the old Windows-* branches back into master will be a train wreck due to the leftover translated SVN cruft, plus the rebasing issues. (We cleaned up most of the SVN cruft in master with reposurgeon, and spent a lot of time verifying correctness against old tarballs, but we did not do the same to the Windows branches.) I think a lot of the Windows-specific files from the branch could be copied over to a new Windows branch that starts from either v2.7.4 or master, though I think that they would change a bit for the proposed reduction of |
Depending on which library is being used for the windows port, would it not already either include a system and syslog function, or not include either, and thus allow us to write a replacement function also removing the need for different code for each platform. |
…/BUILD * commit 'dfdf588dac92d3be175dac30a875e0b19551aefe': (22 commits) snmp-ups.c : a little bit of input checking does not hurt, especially when it fixes a segfault Remove unimplement nut-scanner option Update nut-scanner manual page Fix c++ style comments upsstats.html: Conform to HTML 4.01 Strict upsstats-single.html: Conform to HTML 4.01 Strict Fix c++ style comments Fix exit code for --list common.c/.h : simplify the upsdebugx() enhancement (no need to fight with warnings/pragmas) common.h : rearranged the ENABLE_WARNING/DISABLE_WARNING macro definitions so they are only called for supported compilers and generate empty macros (no-op) for others common.c : move anti-warning macros out of the function body, some compilers do not like that common.c : in upsdebugx() added "[Dx]" prefix : do not add it for level 0 configure.ac : do not fail configuration if a doctype picked with "auto" can not be built on this system - just skip it Added and documented an snmp-ups argument to list currently loaded MIB-to-NUT mappings (typo fix) Added and documented an snmp-ups argument to list currently loaded MIB-to-NUT mappings snmp-ups.c : small typo fix Mention tripplite mapping in snmp-ups manpage; updated some comments about it in ietf-mib.c configure.ac : when verifying ability to build docs, consider out-of-tree builds too configure.ac : verify that we can actually build a simple or chunked HTML document, beside having nominal versions of software configure.ac : verify that we can actually build a manpage document, beside having nominal versions of software ...
Complete the deprecation of MGE-XML convert_deci()
Adding a user provided doc on "How to build NUT Windows Port": |
After a few years' general hiatus on this subect, I tried to revive the changes from Windows-2.6.5-7 branch against current NUT master and came up with https://github.com/networkupstools/nut/tree/Windows-v2.8.0-1 which then got fixed (of accumulated typos and other merge conflicts) into passing builds on Linux (non-regression, testing more with CI farm now) but would need a Windows build env setup to see if the actual The "just for fun" bit turned into half-a-week-long |
Building the NUT 2.8.0 based branch natively on Windows proved problematic, mainly due to the hassle of sourcing a reliable MinGW environment (there are many variants and packagings, including CygWin and MSYS2) as well as lack of MinGW for Linux on a box I tried. But also because it is much more strict in default compiler settings, and notable differences between the original NUT-for-Windows effort and current codebases over time. Now I tried to take a step back to and expected-working solution, to build the 2.6.5-based codebase according to its instructions in I found that Ubuntu 21.10 does ship a usable mingw environment, so built much of NUT and its dependencies for MinGW in an LXC container and rsync'ed files to a Windows 7 machine to test. The resulting updated code and instructions are at https://github.com/networkupstools/nut/tree/Windows-v2.6.5-8 branch (specific state that "works for me" is tagged as https://github.com/networkupstools/nut/releases/tag/Windows-v2.6.5-8 now). Early starts were with 32-bit MinGW (i686) and seemed to compile but I did not test them. Later attempts involved 64-bit target for dependencies (libregex, libusb-1.0 and libusb-0.1-compat for the old codebase, libnetsnmp...) and NUT. I did successfully test an Eaton-ECO USB UPS as far as seeing its identification; but the state was bogus (OB all the time) and not much more data was exposed. Currently I did not care to test much if that is a NUT 2.6.5 issue (old codebase), or Windows porting issue, or even if the UPS (with no load) was just asleep. Replugging the wall cord did not help at least ;) This particular deployment began throwing libusb interrupts errors soon after driver init, and the "pollonly" driver option helped avoid that (in hindsight, I'm not sure if the info updates are really happening though, or it was stuck with what it saw at init time). The nut-scanner succeeded to find the USB UPS, as well as scan the network for a NUT server and report the devices configured on it - so confirming that libltdl magic is also usable. It however relies on suffixed DLL names like The net-snmp sources refused to build a DLL, so it is statically linked into nut-scanner and snmp-ups drivers. No idea how well it works beyond that, as I have no devices to test against at the moment. In particular, nut-scanner seems to have frozen when scanning even one IP address ( I did not yet look at the FWIW, binaries produced for this experiment are archived at https://github.com/networkupstools/nut/releases/download/Windows-v2.6.5-8/nut_install-2.6.5-8-gd1b8d14d1.zip |
Funnily enough I starred and watched this repo yesterday while doing my own NUT on Windows testing, after discovering the latest msi installer wouldn't properly finish installation, I looked it up and came across similar reports, and a workarounds here and here I actually did manage to get it working in standalone mode, and I did also have libusb interrupt errors for which I enabled My reason for considering NUT on Windows is because I'm currently using it on an unRaid system with a similar UPS (Eaton 5E 1500i USB), for which the plugin does allow the system to shutdown based on estimated runtime remaining, and because the default MGE driver has a pretty annoying issue, it randomly disconnects momentarily for a second or two at random periods (usually no more than twice a day, and as little as once every few days), while the disconnection issue alone is not a huge problem, the events that it produces do, as Windows triggers multiple events when it stops recognizing a battery and recognizes one again, which leads to a brief (roughly 2-3 seconds) system hang/unresponsiveness. Since I'm not sure whether I can trust my NUT configuration to shut down my system in the event of a power loss, I was not able to test whether the UPS disconnects with the libusb/NUT driver (I had a stale data issue with unRaid at the default |
Thanks, lots of good ideas here though not sure who and when would follow up on these :) Representing NUT in same way as a laptop battery for different systems (dbus, hal, windows, linux, mac....) does sound reasonable and did for years :) but for some reason nobody published such PRs. Given NUT's layered architecture, and the fact that the UPS may be connected elsewhere, it might be a client similar to upsmon hooking deep into a system. Especially if we get to consider multiple PSUs fed by numerous UPSes in general redundant case; not sure if OS battery facilities even have a concept for that across the board. Finally note that existing NUT for Windows packages are based on 2.6.5 release codebase (and some later merges from trunk development) so evolution and bug fixes there fizzled out roughly in 2013. Lack of features and data points may just be due to that. I'm (slowly... but knowing now that the machinery is viable is a big boon to enthusiasm) struggling to get modern code to just build in similar manner, let alone function and be tested/testable :) |
With recent PRs merged, the Windows branch now includes master (and exceeds with almost no changes to POSIX part of the codebase), and beside our usual NUT CI and CircleCI multi-platform testing, it builds every commit with semi-natively (Windows MSYS2) on AppVeyor and makes a tarball so people can try it out:
Note that all envs (MSYS2, linux+mingw 32-bit and 64-bit) are all differently capable in terms of 3rd party deps provided. But at least it feels great to have explored so many viable options! ;) As noted in the https://github.com/orgs/networkupstools/projects/2/views/1 project, there are still quite a few caveats and commented-away incomplete features which make Windows builds not "prime-time" for each and every use, but at least as built, it should already cover many of the typical bases like USB, ModBus, (maybe less so for Serial ports), NetXML and SNMP... Volunteers to code the missing bits and especially to test against real HW are quite needed at this point. |
Posted the PR above (#1611) which I hope will take care of merging the codebases, so existing NUT for Windows effort becomes part of "master" branch. This does not mean the end of the journey, as there are at least the existing disabled and questionable parts of code (see project referenced above) to take care of, for the added platform to be "on par" with the POSIX builds feature-wise, and packaging which was not revived yet but is something valuable to end-users on that platform. And the multitude of supported build environments currently gives a choice of "either these or those" third-party libraries and so NUT capabilities, something to level out as well. |
configure.ac, drivers/libusb0.c: fix detection of strlwr() and fallback strcasestr() implem
Just wondering with these builds, if set up as a NUT client, what is meant to be run for it to monitor the server in the background? On Linux when the NUT packages are installed it auto starts a upsmon background process that keeps track of the server, and from my brief check of the old (~2013) official Windows installer it sets up a background service that presumably does the same thing. I notice there's a Edit: tested a forced shutdown via the server and indeed the Hopefully in the future there could be a version that could be started as a window-less background process (or if there's a way to do this currently I'd be interested). |
Thanks for the confirmation it works at least so :) Looking at the Those files just go There seems to be a According to the With the above in mind, in the XML file for Windows packaging I found this block:
and the |
:) Tbh I'm not familiar with it all know how I'd be able to modify the source but I did try
Apart from registered Windows services I know there are some executables that run as UI-less processes. One such is display-switch (a clever pseudo KVM) which when opened by itself just remains open in the background until terminated, but when opened via console window will print out config info. Though given there are already some code basis for the Windows service approach I suppose that makes more sense to get functional. |
Just in case: did you do it from a "Run as Administrator" sort of CMD session? |
Oh wow, I feel silly. Running the console as admin made it successfully install. Nice! It auto detected my forced shutdown signal from the server and shutdown as expected. Great to have this native port, since I tried WinNUT-Client first but it failed to detect FSD signals sent from the server and had various disconnects that wouldn't auto re-connect. Thanks for the work you've put into it 👍 |
Just for clarification, is Also tried as one of the tests just Reason being is since I have my server configured to always issue a FSD signal when on battery due to the unorthodox behaviour of my UPS and afaict from the docs an FSD basically directly triggers |
No firm idea, but I think as a service it has no easy access to a desktop session, so probably notepad won't work. Batch files... maybe? By full pathname with extension and possible double-slash (or Unix slash) magic?.. |
Hmm, perhaps I should make it a separate issue but here are various things I've tried with no effect:
Also tried instead using
Goal with a script is I need to run commands to close any open VMs then hibernate my system when the FSD signal is detected, since a vanilla shutdown wouldn't handle all scenarios. |
My guess would be that Windows slashes must be doubled (so as to be escaped), and if quotes are deemed needed - also escaped. So purely parser-wise these would be more correct:
Maybe explicit
I was under the impression that you did nail the syntax for it? Or did it only work for "interactive"
Check
|
So tested these three (edited
Only
Mmm, yeah for Windows I'm familiar, just not what it's being translated to (that is, if my later assumption is correct that everything gets interpreted as Linux commands). Linux man page for Currently testing in a Windows 10 VM via VirtualBox, to test feasibility (and for ease of restarting) before adding to my host Windows system. |
Some more testing. Decided to stop the NUT service and launch
Also since it I noticed references in the source code to Cygwin, which supports executing Windows commands alongside Linux ones with the right syntax. Not sure if that's actually what is used as the interpreter but anyway. Results:
So at least I know now using If there was a way that the service could execute files when at least given a full path it'd be useful. This SO page suggests that for example CMD.exe can be utilized with arguments via a service, so long as it doesn't require any UI/user interaction. Idk if this is relevant to how NUT handles it. |
I read there is a common trick using Windows Task Scheduler to set up execution of complex commands (with privileges needed, ensuring stuff only runs once at a time, etc.) and scripts or other less privileged programs calling that via I suppose here it is overkill since the NUT service should already be quite privileged, but still a useful trick in the automation toolkit. You can probably try setting a higher Keep in mind that there is a NUT config parser involved first and foremost (converting string markup in text files into a |
Checked Event log messages when
Then checked when set to
Might try the method of setting my custom script to execute when the service is detected as stopped (which afaict is possible with it via the Service properties). Edit: oh, I see what you meant re Task Scheduler, didn't click at first. Edit 2: tested creating a Task Scheduler task and using First tested that the task would launch the custom script when manually run via Task Scheduler and gave it However unfortunately the NUT service failed to launch it automatically when the FSD signal was received. If I'm missing something let me know. |
Some success :) Found a way to make It uses VBScript to launch it to begin with, which can be added to the Windows startup/etc.
Downsides to this approach:
Miscellaneous:
Other things explored prior to this that had no effect:
|
…sage [#2463] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…tatus+mode drivers/mge-hid.c: reset ABM path when ABM not enabled
Complete port of NUT to MS Windows.
Alioth feature request:
https://alioth.debian.org/tracker/index.php?func=detail&aid=302177&group_id=30602&atid=411545
The text was updated successfully, but these errors were encountered: