Skip to content
Snippets Groups Projects
Commit 5ed8b177 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Use a list to keep track of suspend reasons

Refers to #36
parent 0f9d7dd5
No related branches found
No related tags found
No related merge requests found
...@@ -556,26 +556,26 @@ namespace ATxService ...@@ -556,26 +556,26 @@ namespace ATxService
/// Check system parameters for valid ranges and update the global service state accordingly. /// Check system parameters for valid ranges and update the global service state accordingly.
/// </summary> /// </summary>
private void UpdateServiceState() { private void UpdateServiceState() {
var limitReason = ""; var suspendReasons = new List<string>();
// check all system parameters for valid ranges and remember the reason in a string // check all system parameters for valid ranges and remember the reason in a string
// if one of them is failing (to report in the log why we're suspended) // if one of them is failing (to report in the log why we're suspended)
if (_cpu.HighLoad) if (_cpu.HighLoad)
limitReason = "CPU usage"; suspendReasons.Add("CPU");
else if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory)
limitReason = "RAM usage"; if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory)
else { suspendReasons.Add("RAM");
var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses(
_config.BlacklistedProcesses); var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses(
if (blacklistedProcess != "") { _config.BlacklistedProcesses);
limitReason = "blacklisted process '" + blacklistedProcess + "'"; if (!string.IsNullOrWhiteSpace(blacklistedProcess)) {
} suspendReasons.Add("process '" + blacklistedProcess + "'");
} }
// all parameters within valid ranges, so set the state to "Running": // all parameters within valid ranges, so set the state to "Running":
if (string.IsNullOrEmpty(limitReason)) { if (suspendReasons.Count == 0) {
_status.ServiceSuspended = false; if (_status.ServiceSuspended) {
if (!string.IsNullOrEmpty(_status.LimitReason)) { _status.ServiceSuspended = false;
_status.LimitReason = ""; // reset to force a message on next service suspend _status.LimitReason = ""; // reset to force a message on next service suspend
Log.Info("Service resuming operation (all parameters in valid ranges)."); Log.Info("Service resuming operation (all parameters in valid ranges).");
} }
...@@ -584,8 +584,8 @@ namespace ATxService ...@@ -584,8 +584,8 @@ namespace ATxService
// set state to "Running" if no-one is logged on: // set state to "Running" if no-one is logged on:
if (SystemChecks.NoUserIsLoggedOn()) { if (SystemChecks.NoUserIsLoggedOn()) {
_status.ServiceSuspended = false; if (_status.ServiceSuspended) {
if (!string.IsNullOrEmpty(_status.LimitReason)) { _status.ServiceSuspended = false;
_status.LimitReason = ""; // reset to force a message on next service suspend _status.LimitReason = ""; // reset to force a message on next service suspend
Log.Info("Service resuming operation (no user logged on)."); Log.Info("Service resuming operation (no user logged on).");
} }
...@@ -594,9 +594,11 @@ namespace ATxService ...@@ -594,9 +594,11 @@ namespace ATxService
// by reaching this point we know the service should be suspended: // by reaching this point we know the service should be suspended:
_status.ServiceSuspended = true; _status.ServiceSuspended = true;
var limitReason = string.Join(", ", suspendReasons);
if (limitReason == _status.LimitReason) if (limitReason == _status.LimitReason)
return; return;
Log.Info("Service suspended due to limitiations [{0}].", limitReason);
Log.Info("Service suspended. Reason(s): [{0}]", limitReason);
_status.LimitReason = limitReason; _status.LimitReason = limitReason;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment