diff --git a/modules/mgmt.go b/modules/mgmt.go index f5f082e..4081741 100644 --- a/modules/mgmt.go +++ b/modules/mgmt.go @@ -30,11 +30,16 @@ func (m *Module) SetEnabled(enable bool) (changed bool) { return m.Disable() } -// Enabled returns wether or not the module is currently enabled. +// Enabled returns whether or not the module is currently enabled. func (m *Module) Enabled() bool { return m.enabled.IsSet() } +// EnabledAsDependency returns whether or not the module is currently enabled as a dependency. +func (m *Module) EnabledAsDependency() bool { + return m.enabledAsDependency.IsSet() +} + // EnableModuleManagement enables the module management functionality within modules. The supplied notify function will be called whenever the status of a module changes. The affected module will be in the parameter. You will need to manually enable modules, else nothing will start. func EnableModuleManagement(changeNotifyFn func(*Module)) { if moduleMgmtEnabled.SetToIf(false, true) { diff --git a/modules/subsystems/subsystem.go b/modules/subsystems/subsystem.go index 1a8bec4..37f6837 100644 --- a/modules/subsystems/subsystem.go +++ b/modules/subsystems/subsystem.go @@ -63,7 +63,7 @@ func statusFromModule(module *modules.Module) *ModuleStatus { status := &ModuleStatus{ Name: module.Name, module: module, - Enabled: module.Enabled(), + Enabled: module.Enabled() || module.EnabledAsDependency(), Status: module.Status(), } status.FailureStatus, status.FailureID, status.FailureMsg = module.FailureStatus() @@ -73,7 +73,7 @@ func statusFromModule(module *modules.Module) *ModuleStatus { func compareAndUpdateStatus(module *modules.Module, status *ModuleStatus) (changed bool) { // check if enabled - enabled := module.Enabled() + enabled := module.Enabled() || module.EnabledAsDependency() if status.Enabled != enabled { status.Enabled = enabled changed = true @@ -101,16 +101,10 @@ func compareAndUpdateStatus(module *modules.Module, status *ModuleStatus) (chang func (sub *Subsystem) makeSummary() { // find worst failing module - worstFailing := &ModuleStatus{} + sub.FailureStatus = 0 for _, depStatus := range sub.Modules { - if depStatus.FailureStatus > worstFailing.FailureStatus { - worstFailing = depStatus + if depStatus.FailureStatus > sub.FailureStatus { + sub.FailureStatus = depStatus.FailureStatus } } - - if worstFailing != nil { - sub.FailureStatus = worstFailing.FailureStatus - } else { - sub.FailureStatus = 0 - } }