diff --git a/services/caches.go b/services/caches.go index 2886602a4..aef1cead9 100644 --- a/services/caches.go +++ b/services/caches.go @@ -101,7 +101,7 @@ func (cS *CacheService) Shutdown() (_ error) { // IsRunning returns if the service is running func (cS *CacheService) IsRunning() bool { - return true + return CheckServiceState(cS.ServiceName(), utils.StateServiceUP, cS.srvIndexer) } // ServiceName returns the service name diff --git a/services/config.go b/services/config.go index 4b5eaec64..b417df739 100644 --- a/services/config.go +++ b/services/config.go @@ -80,7 +80,7 @@ func (s *ConfigService) Shutdown() error { // IsRunning returns whether the service is running or not. func (s *ConfigService) IsRunning() bool { - return true + return CheckServiceState(s.ServiceName(), utils.StateServiceUP, s.srvIndexer) } // ServiceName returns the service name diff --git a/services/globalvars.go b/services/globalvars.go index 988d9a575..dda1c06d6 100644 --- a/services/globalvars.go +++ b/services/globalvars.go @@ -74,7 +74,7 @@ func (gv *GlobalVarS) Shutdown() error { // IsRunning returns if the service is running func (gv *GlobalVarS) IsRunning() bool { - return true + return CheckServiceState(gv.ServiceName(), utils.StateServiceUP, gv.srvIndexer) } // ServiceName returns the service name diff --git a/services/guardian.go b/services/guardian.go index d6ab40865..12cdd8d63 100644 --- a/services/guardian.go +++ b/services/guardian.go @@ -80,7 +80,7 @@ func (s *GuardianService) Shutdown() error { // IsRunning returns whether the service is running or not. func (s *GuardianService) IsRunning() bool { - return true + return CheckServiceState(s.ServiceName(), utils.StateServiceUP, s.srvIndexer) } // ServiceName returns the service name diff --git a/services/statedeps.go b/services/statedeps.go index 27795bfa8..0a33aa1aa 100644 --- a/services/statedeps.go +++ b/services/statedeps.go @@ -20,6 +20,8 @@ package services import ( "sync" + + "github.com/cgrates/cgrates/servmanager" ) // NewStateDependencies constructs a StateDependencies struct @@ -44,3 +46,12 @@ func (sDs *StateDependencies) StateChan(stateID string) (retChan chan struct{}) sDs.stateDepsMux.RUnlock() return } + +func CheckServiceState(id, state string, indexer *servmanager.ServiceIndexer) bool { + select { + case <-indexer.GetService(id).StateChan(state): + return true + default: + return false + } +}