Updated ServiceManager.StartServices

This commit is contained in:
Trial97
2020-05-18 10:54:48 +03:00
committed by Dan Christian Bogos
parent 84e05fd8f0
commit 4b7976f920
27 changed files with 37 additions and 67 deletions

View File

@@ -56,7 +56,7 @@ type AnalyzerService struct {
// Start should handle the sercive start
func (anz *AnalyzerService) Start() (err error) {
if anz.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
if anz.anz, err = analyzers.NewAnalyzerService(); err != nil {
utils.Logger.Crit(fmt.Sprintf("<%s> Could not init, error: %s", utils.AnalyzerS, err.Error()))

View File

@@ -76,7 +76,7 @@ type APIerSv1Service struct {
// For this service the start should be called from RAL Service
func (apiService *APIerSv1Service) Start() (err error) {
if apiService.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-apiService.filterSChan

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
v2 "github.com/cgrates/cgrates/apier/v2"
@@ -55,7 +54,7 @@ type APIerSv2Service struct {
// For this service the start should be called from RAL Service
func (api *APIerSv2Service) Start() (err error) {
if api.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
apiV1Chan := api.apiv1.GetAPIerSv1Chan()

View File

@@ -53,7 +53,7 @@ type AsteriskAgent struct {
// Start should handle the sercive start
func (ast *AsteriskAgent) Start() (err error) {
if ast.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
ast.Lock()

View File

@@ -61,7 +61,7 @@ type AttributeService struct {
// Start should handle the sercive start
func (attrS *AttributeService) Start() (err error) {
if attrS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-attrS.cacheS.GetPrecacheChannel(utils.CacheAttributeProfiles)

View File

@@ -70,7 +70,7 @@ type CDRServer struct {
// Start should handle the sercive start
func (cdrService *CDRServer) Start() (err error) {
if cdrService.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.CDRs))

View File

@@ -63,7 +63,7 @@ type ChargerService struct {
// Start should handle the sercive start
func (chrS *ChargerService) Start() (err error) {
if chrS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-chrS.cacheS.GetPrecacheChannel(utils.CacheChargerProfiles)

View File

@@ -50,7 +50,7 @@ type DataDBService struct {
// Start should handle the sercive start
func (db *DataDBService) Start() (err error) {
if db.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
db.Lock()
defer db.Unlock()

View File

@@ -54,7 +54,7 @@ type DiameterAgent struct {
// Start should handle the sercive start
func (da *DiameterAgent) Start() (err error) {
if da.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-da.filterSChan

View File

@@ -64,7 +64,7 @@ type DispatcherService struct {
// Start should handle the sercive start
func (dspS *DispatcherService) Start() (err error) {
if dspS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
utils.Logger.Info("Starting CGRateS Dispatcher service.")
fltrS := <-dspS.filterSChan

View File

@@ -56,7 +56,7 @@ type DNSAgent struct {
// Start should handle the sercive start
func (dns *DNSAgent) Start() (err error) {
if dns.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-dns.filterSChan

View File

@@ -57,7 +57,7 @@ type EventReaderService struct {
// Start should handle the sercive start
func (erS *EventReaderService) Start() (err error) {
if erS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
erS.Lock()

View File

@@ -53,7 +53,7 @@ type FreeswitchAgent struct {
// Start should handle the sercive start
func (fS *FreeswitchAgent) Start() (err error) {
if fS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
fS.Lock()

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
"github.com/cgrates/cgrates/agents"
@@ -54,7 +53,7 @@ type HTTPAgent struct {
// Start should handle the sercive start
func (ha *HTTPAgent) Start() (err error) {
if ha.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-ha.filterSChan

View File

@@ -54,7 +54,7 @@ type KamailioAgent struct {
// Start should handle the sercive start
func (kam *KamailioAgent) Start() (err error) {
if kam.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
kam.Lock()

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
v1 "github.com/cgrates/cgrates/apier/v1"
@@ -65,7 +64,7 @@ type LoaderService struct {
// Start should handle the sercive start
func (ldrs *LoaderService) Start() (err error) {
if ldrs.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-ldrs.filterSChan

View File

@@ -54,7 +54,7 @@ type RadiusAgent struct {
// Start should handle the sercive start
func (rad *RadiusAgent) Start() (err error) {
if rad.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
filterS := <-rad.filterSChan

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
v1 "github.com/cgrates/cgrates/apier/v1"
@@ -62,7 +61,7 @@ type RalService struct {
// For this service the start should be called from RAL Service
func (rals *RalService) Start() (err error) {
if rals.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
engine.SetRpSubjectPrefixMatching(rals.cfg.RalsCfg().RpSubjectPrefixMatching)
rals.Lock()

View File

@@ -64,7 +64,7 @@ type ResourceService struct {
// Start should handle the sercive start
func (reS *ResourceService) Start() (err error) {
if reS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-reS.cacheS.GetPrecacheChannel(utils.CacheResourceProfiles)

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
"github.com/cgrates/cgrates/config"
@@ -55,7 +54,7 @@ type ResponderService struct {
// For this service the start should be called from RAL Service
func (resp *ResponderService) Start() (err error) {
if resp.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
resp.Lock()

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package services
import (
"fmt"
"sync"
v1 "github.com/cgrates/cgrates/apier/v1"
@@ -64,7 +63,7 @@ type SchedulerService struct {
// Start should handle the sercive start
func (schS *SchedulerService) Start() (err error) {
if schS.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-schS.cacheS.GetPrecacheChannel(utils.CacheActionPlans) // wait for ActionPlans to be cached

View File

@@ -67,7 +67,7 @@ type SessionService struct {
// Start should handle the sercive start
func (smg *SessionService) Start() (err error) {
if smg.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
var datadb *engine.DataManager
if smg.dm.IsRunning() {

View File

@@ -63,7 +63,7 @@ type StatService struct {
// Start should handle the sercive start
func (sts *StatService) Start() (err error) {
if sts.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-sts.cacheS.GetPrecacheChannel(utils.CacheStatQueueProfiles)

View File

@@ -51,7 +51,7 @@ type StorDBService struct {
// Start should handle the sercive start
func (db *StorDBService) Start() (err error) {
if db.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
db.Lock()
defer db.Unlock()

View File

@@ -61,7 +61,7 @@ type ThresholdService struct {
// Start should handle the sercive start
func (thrs *ThresholdService) Start() (err error) {
if thrs.IsRunning() {
return fmt.Errorf("service aleady running")
return utils.ErrServiceAlreadyRunning
}
<-thrs.cacheS.GetPrecacheChannel(utils.CacheThresholdProfiles)

View File

@@ -147,34 +147,17 @@ func (srvMngr *ServiceManager) GetConfig() *config.CGRConfig {
// StartServices starts all enabled services
func (srvMngr *ServiceManager) StartServices() (err error) {
go srvMngr.handleReload()
for serviceName, shouldRun := range map[string]bool{
utils.APIerSv1: srvMngr.GetConfig().ApierCfg().Enabled,
utils.APIerSv2: srvMngr.GetConfig().ApierCfg().Enabled,
utils.StorDB: srvMngr.GetConfig().RalsCfg().Enabled || srvMngr.GetConfig().CdrsCfg().Enabled,
utils.AttributeS: srvMngr.GetConfig().AttributeSCfg().Enabled,
utils.ChargerS: srvMngr.GetConfig().ChargerSCfg().Enabled,
utils.ThresholdS: srvMngr.GetConfig().ThresholdSCfg().Enabled,
utils.StatS: srvMngr.GetConfig().StatSCfg().Enabled,
utils.ResourceS: srvMngr.GetConfig().ResourceSCfg().Enabled,
utils.SupplierS: srvMngr.GetConfig().SupplierSCfg().Enabled,
utils.SchedulerS: srvMngr.GetConfig().SchedulerCfg().Enabled,
utils.RALService: srvMngr.GetConfig().RalsCfg().Enabled,
utils.CDRServer: srvMngr.GetConfig().CdrsCfg().Enabled,
utils.SessionS: srvMngr.GetConfig().SessionSCfg().Enabled,
utils.ERs: srvMngr.GetConfig().ERsCfg().Enabled,
utils.DNSAgent: srvMngr.GetConfig().DNSAgentCfg().Enabled,
utils.FreeSWITCHAgent: srvMngr.GetConfig().FsAgentCfg().Enabled,
utils.KamailioAgent: srvMngr.GetConfig().KamAgentCfg().Enabled,
utils.AsteriskAgent: srvMngr.GetConfig().AsteriskAgentCfg().Enabled,
utils.RadiusAgent: srvMngr.GetConfig().RadiusAgentCfg().Enabled,
utils.DiameterAgent: srvMngr.GetConfig().DiameterAgentCfg().Enabled,
utils.HTTPAgent: len(srvMngr.GetConfig().HttpAgentCfg()) != 0,
utils.LoaderS: srvMngr.GetConfig().LoaderCfg().Enabled(),
utils.AnalyzerS: srvMngr.GetConfig().AnalyzerSCfg().Enabled,
utils.DispatcherS: srvMngr.GetConfig().DispatcherSCfg().Enabled,
} {
if shouldRun {
go srvMngr.startService(serviceName)
for _, service := range srvMngr.subsystems {
if service.ShouldRun() && !service.IsRunning() {
go func(srv Service) {
if err := srv.Start(); err != nil {
if err == utils.ErrServiceAlreadyRunning { // in case the service was started in another gorutine
return
}
utils.Logger.Err(fmt.Sprintf("<%s> failed to start %s because: %s", utils.ServiceManager, service.ServiceName(), err))
srvMngr.engineShutdown <- true
}
}(service)
}
}
// startServer()
@@ -341,14 +324,6 @@ func (srvMngr *ServiceManager) reloadService(srviceName string) (err error) {
return
}
func (srvMngr *ServiceManager) startService(srviceName string) {
srv := srvMngr.GetService(srviceName)
if err := srv.Start(); err != nil {
utils.Logger.Err(fmt.Sprintf("<%s> Failed to start %s because: %s", utils.ServiceManager, srviceName, err))
srvMngr.engineShutdown <- true
}
}
// GetService returns the named service
func (srvMngr *ServiceManager) GetService(subsystem string) (srv Service) {
var has bool

View File

@@ -73,6 +73,7 @@ var (
ErrMaxIncrementsExceeded = errors.New("MAX_INCREMENTS_EXCEEDED")
ErrIndexOutOfBounds = errors.New("INDEX_OUT_OF_BOUNDS")
ErrWrongPath = errors.New("WRONG_PATH")
ErrServiceAlreadyRunning = fmt.Errorf("service already running")
ErrMap = map[string]error{
ErrNoMoreData.Error(): ErrNoMoreData,