jdmallen / dell-ipmi-fan-control-monitor

A .NET 5.0 service that monitors the temperature of a Dell PowerEdge R620 and automatically engages or disengages static fan control based on temperature, in order to control noise in a homelab.
MIT License
39 stars 7 forks source link

Crash on startup: Windows 2016 Server #4

Open user2222222222 opened 3 years ago

user2222222222 commented 3 years ago

I copied files from here: JDMallen.IPMITempMonitor-win64-v1.1.0.zip To here: C:\git\R620TempMonitor\

Then do this to start from command prompt: CD /D "C:\git\R620TempMonitor" SET DOTNET_ENVIRONMENT=Production setx DOTNET_ENVIRONMENT Production JDMallen.IPMITempMonitor.exe

But the program crashes starting with this error: Unhandled exception. System.IO.FileNotFoundException: Could not find file 'C:\testdata.txt'. File name: 'C:\testdata.txt'

If I manually create that file, the non production build functions. If I could compile this on my own, I'd just remove the if (_environment.IsDevelopment()) test on line 277 of Worker.cs.

What am I doing wrong? May I request an updated build where the if (_environment.IsDevelopment()) condition also checks for the existance of the testdata.txt file? That way, production would still run even if environment isn't setup correctly because testdata.txt doesn't exist.

Thank you for posting your work, I'm looking forward to trying it out.

jdmallen commented 3 years ago

Hiya! First guess is that the environment variable isn't being set or read properly for some reason. This section of code is the only place where testdata.txt is sought, which is only reachable if the app believes the current environment is Development, as you noted.

The reason I wrote it this way was to prevent it from actually executing the IPMI commands while in Development mode, and instead just simulate the response with the contents of testdata.txt. I'd prefer to keep it that way, but I'll try to think of a way to more gracefully handle when it can't find the file (or fall back on hard-coded defaults).

Sanity checks:

  1. Did you remember to launch cmd.exe as admin?
  2. Have you tried setting the system environment variables from the GUI?
  3. After you open an elevated PowerShell window and execute gci env: | ? {$_.Name -eq "DOTNET_ENVIRONMENT"}, do you see the correct variable value?
jdmallen commented 3 years ago

I did just push some new changes that might improve things for you. I'll release the binaries later tomorrow.

user2222222222 commented 3 years ago

Thank you so much! I ended up downloading Visual Studio and compiling it myself. I inserted the following command at the top of public Worker() at line #45 to get it working: _environment.EnvironmentName = "Production";

However, there's something else that should be updated. I had a very rare but consistent problem with it locking up. Increasing the refresh time produces a lockup every 4 or 5 hours.

I found it was var maxCpuTemp = matches.Select() that was causing the problem. I have zero experience with c#, so don't know exactly why, but the command locks up when matches has a zero count which will happen if ExecuteIpmiToolCommand() fails.

I put this right after the Regex.Matches() call to fix the problem (line #184): if (matches == null || matches.Count == 0) return (_settings.MaxTempInC + 200);

This will return the system to automatic when reading fails.

I also added this line right after ExecuteIpmiToolCommand(). Not sure if it's necessary, but a null result will cause Regex.Matches() to lockup (empty string tested ok): if (result == null) return (_settings.MaxTempInC + 200);

This script does exactly what I need it to, thank you.

BTW, in case it saves someone some time, this is what I used to install as a service in Windows 2016 server: sc.exe create FanControlMonitor start=auto binpath=C:\R520TempMonitor\JDMallen.IPMITempMonitor.exe sc.exe description FanControlMonitor "Keeps loud dell servers quiet by disabling automatic fan control when temp is low." sc.exe start FanControlMonitor

And to stop and remove it: sc.exe stop FanControlMonitor sc.exe delete FanControlMonitor

user2222222222 commented 3 years ago

One more thing: I don't know enough to know whether this would be something difficult to do, but it would be great to have some sort of health monitor to restart the service if it ever quits working. Maybe if it set a file timestamp in the main loop, another simple service could check it periodically and restart if it's not updating.

user2222222222 commented 3 years ago

Regarding your third question, Here is the output from PowerShell: PS C:\Users\Administrator> gci env: | ? {$_.Name -eq "DOTNET_ENVIRONMENT"} Name Value ------ ------ DOTNET_ENVIRONMENT Production

However, running .\JDMallen.IPMITempMonitor.exe from PowerShell produces the same results: it still looks for C:\testdata.txt and then crashes.