diff --git a/cmd/cgr-rater/cgr-rater.go b/cmd/cgr-rater/cgr-rater.go index 61aa54709..1859b4a7a 100644 --- a/cmd/cgr-rater/cgr-rater.go +++ b/cmd/cgr-rater/cgr-rater.go @@ -48,9 +48,8 @@ var ( balancer_web_status_server = "127.0.0.1:8000" // Web server address balancer_json = false // use JSON for RPC encoding - scheduler_enabled = false - scheduler_standalone = false // run standalone (no other service) - scheduler_json = false + scheduler_enabled = false + scheduler_json = false sm_enabled = false sm_standalone = false // run standalone @@ -96,7 +95,6 @@ func readConfig(configFn string) { balancer_json, _ = c.GetBool("balancer", "json") scheduler_enabled, _ = c.GetBool("scheduler", "enabled") - scheduler_standalone, _ = c.GetBool("scheduler", "standalone") scheduler_json, _ = c.GetBool("scheduler", "json") sm_enabled, _ = c.GetBool("session_manager", "enabled") @@ -117,27 +115,6 @@ func readConfig(configFn string) { mediator_password, _ = c.GetString("mediator", "password") } -func resolveStandaloneConfilcts() { - if balancer_standalone { - rater_standalone = false - } - if scheduler_standalone { - rater_standalone = false - balancer_standalone = false - } - if sm_standalone { - rater_standalone = false - balancer_standalone = false - scheduler_standalone = false - } - if mediator_standalone { - rater_standalone = false - balancer_standalone = false - scheduler_standalone = false - sm_standalone = false - } -} - func listenToRPCRequests(responder interface{}, rpcAddress string, json bool) { l, err := net.Listen("tcp", rpcAddress) defer l.Close() @@ -179,7 +156,9 @@ func main() { flag.Parse() runtime.GOMAXPROCS(runtime.NumCPU()) readConfig(*config) - resolveStandaloneConfilcts() + if balancer_standalone { + rater_standalone = false + } getter, err := timespans.NewRedisStorage(redis_server, redis_db) if err != nil { timespans.Logger.Crit("Could not connect to redis, exiting!") @@ -189,8 +168,8 @@ func main() { timespans.SetStorageGetter(getter) if !rater_standalone && !balancer_enabled { - go registerToBalancer(rater_balancer_server, rater_listen) - go stopRaterSingnalHandler(rater_balancer_server, rater_listen, getter) + go registerToBalancer() + go stopRaterSingnalHandler() } if !balancer_enabled { go listenToRPCRequests(&Responder{new(DirectResponder)}, rater_listen, rater_json) @@ -202,5 +181,13 @@ func main() { go listenToHttpRequests() } + if scheduler_enabled { + go func() { + loadActionTimings() + go reloadSchedulerSingnalHandler() + s.loop() + }() + } + <-exitChan } diff --git a/cmd/cgr-rater/rater_test.go b/cmd/cgr-rater/rater_test.go index 3cf74814d..90bfb6aff 100644 --- a/cmd/cgr-rater/rater_test.go +++ b/cmd/cgr-rater/rater_test.go @@ -41,18 +41,15 @@ func TestConfig(t *testing.T) { balancer_json != true || scheduler_enabled != true || - scheduler_standalone != true || scheduler_json != true || sm_enabled != true || - sm_standalone != true || sm_api_server != "test" || sm_freeswitch_server != "test" || sm_freeswitch_pass != "test" || sm_json != true || mediator_enabled != true || - mediator_standalone != true || mediator_cdr_file != "test" || mediator_result_file != "test" || mediator_host != "test" || @@ -71,16 +68,13 @@ func TestConfig(t *testing.T) { t.Log(balancer_listen_api) t.Log(balancer_json) t.Log(scheduler_enabled) - t.Log(scheduler_standalone) t.Log(scheduler_json) t.Log(sm_enabled) - t.Log(sm_standalone) t.Log(sm_api_server) t.Log(sm_freeswitch_server) t.Log(sm_freeswitch_pass) t.Log(sm_json) t.Log(mediator_enabled) - t.Log(mediator_standalone) t.Log(mediator_cdr_file) t.Log(mediator_result_file) t.Log(mediator_host) diff --git a/cmd/cgr-rater/registration.go b/cmd/cgr-rater/registration.go index be34a8105..e21c2ab2c 100644 --- a/cmd/cgr-rater/registration.go +++ b/cmd/cgr-rater/registration.go @@ -80,30 +80,30 @@ func stopBalancerSingnalHandler() { /* Listens for the SIGTERM, SIGINT, SIGQUIT system signals and gracefuly unregister from balancer and closes the storage before exiting. */ -func stopRaterSingnalHandler(server, listen string, sg timespans.StorageGetter) { +func stopRaterSingnalHandler() { log.Print("Handling stop signals...") c := make(chan os.Signal) signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) sig := <-c log.Printf("Caught signal %v, unregistering from balancer\n", sig) - unregisterFromBalancer(server, listen) - sg.Close() + unregisterFromBalancer() exitChan <- true } /* Connects to the balancer and calls unregister RPC method. */ -func unregisterFromBalancer(server, listen string) { - client, err := rpc.DialHTTP("tcp", server) +func unregisterFromBalancer() { + client, err := rpc.Dial("tcp", rater_balancer_server) if err != nil { log.Print("Cannot contact the balancer!") exitChan <- true + return } var reply int - log.Print("Unregistering from balancer ", server) - client.Call("RaterServer.UnRegisterRater", listen, &reply) + log.Print("Unregistering from balancer ", rater_balancer_server) + client.Call("RaterServer.UnRegisterRater", rater_listen, &reply) if err := client.Close(); err != nil { log.Print("Could not close balancer unregistration!") exitChan <- true @@ -113,18 +113,35 @@ func unregisterFromBalancer(server, listen string) { /* Connects to the balancer and rehisters the rater to the server. */ -func registerToBalancer(server, listen string) { - client, err := rpc.DialHTTP("tcp", server) +func registerToBalancer() { + client, err := rpc.Dial("tcp", rater_balancer_server) if err != nil { log.Print("Cannot contact the balancer!") exitChan <- true + return } var reply int - log.Print("Registering to balancer ", server) - client.Call("RaterServer.RegisterRater", listen, &reply) + log.Print("Registering to balancer ", rater_balancer_server) + client.Call("RaterServer.RegisterRater", rater_listen, &reply) if err := client.Close(); err != nil { log.Print("Could not close balancer registration!") exitChan <- true } log.Print("Registration finished!") } + +// Listens for the HUP system signal and gracefuly reloads the timers from database. +func reloadSchedulerSingnalHandler() { + timespans.Logger.Info("Handling HUP signal...") + for { + c := make(chan os.Signal) + signal.Notify(c, syscall.SIGHUP) + sig := <-c + + timespans.Logger.Info(fmt.Sprintf("Caught signal %v, reloading action timings.\n", sig)) + loadActionTimings() + // check the tip of the queue for new actions + restartLoop <- 1 + timer.Stop() + } +} diff --git a/conf/mediator_standalone.config b/conf/full.config similarity index 94% rename from conf/mediator_standalone.config rename to conf/full.config index bb1f63c30..bb03c83ff 100644 --- a/conf/mediator_standalone.config +++ b/conf/full.config @@ -31,11 +31,7 @@ listen_rater = 127.0.0.1:2000 # Rater server address listen_api = 127.0.0.1:2001 # Json RPC server address web_status_server = 127.0.0.1:8000 # Web server address (for status) json = false # use JSON for RPC encoding - -[scheduler] -enabled = false -standalone = false # run standalone (no other service) -json = false # use JSON for RPC encoding +ON for RPC encoding [session_manager] enabled = false diff --git a/conf/mediator.config b/conf/mediator.config index bb1f63c30..7a3e0612d 100644 --- a/conf/mediator.config +++ b/conf/mediator.config @@ -24,30 +24,8 @@ balancer_server = 127.0.0.1:2000 # balancer address host:port listen_api = 127.0.0.1:1234 # listening address host:port json = false # use JSON for RPC encoding -[balancer] -enabled = false -standalone = false # run standalone -listen_rater = 127.0.0.1:2000 # Rater server address -listen_api = 127.0.0.1:2001 # Json RPC server address -web_status_server = 127.0.0.1:8000 # Web server address (for status) -json = false # use JSON for RPC encoding - -[scheduler] -enabled = false -standalone = false # run standalone (no other service) -json = false # use JSON for RPC encoding - -[session_manager] -enabled = false -standalone = false # run standalone -api_server = 127.0.0.1:2000 # balancer address host:port -freeswitch_server = localhost:8021 # freeswitch address host:port -freeswitch_pass = ClueCon # freeswitch address host:port -json = false # use JSON for RPC encoding - [mediator] enabled = false -standalone = false # run standalone cdr_file = Master.csv # Freeswitch Master CSV CDR file. result_file = out.csv # Generated file containing CDR and price info. host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets. diff --git a/conf/scheduler.config b/conf/scheduler.config index bb1f63c30..0cc58eee0 100644 --- a/conf/scheduler.config +++ b/conf/scheduler.config @@ -20,38 +20,9 @@ redis_db = 10 # redis database number [rater] standalone = true # start standalone server (no balancer) -balancer_server = 127.0.0.1:2000 # balancer address host:port listen_api = 127.0.0.1:1234 # listening address host:port json = false # use JSON for RPC encoding -[balancer] -enabled = false -standalone = false # run standalone -listen_rater = 127.0.0.1:2000 # Rater server address -listen_api = 127.0.0.1:2001 # Json RPC server address -web_status_server = 127.0.0.1:8000 # Web server address (for status) -json = false # use JSON for RPC encoding - [scheduler] -enabled = false -standalone = false # run standalone (no other service) +enabled = true json = false # use JSON for RPC encoding - -[session_manager] -enabled = false -standalone = false # run standalone -api_server = 127.0.0.1:2000 # balancer address host:port -freeswitch_server = localhost:8021 # freeswitch address host:port -freeswitch_pass = ClueCon # freeswitch address host:port -json = false # use JSON for RPC encoding - -[mediator] -enabled = false -standalone = false # run standalone -cdr_file = Master.csv # Freeswitch Master CSV CDR file. -result_file = out.csv # Generated file containing CDR and price info. -host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets. -port = 5432 # The port to bind to. -db = cgrates # The name of the database to connect to. -user = # The user to sign in as. -password = # The user's password. \ No newline at end of file diff --git a/conf/scheduler_standalone.config b/conf/scheduler_standalone.config deleted file mode 100644 index bb1f63c30..000000000 --- a/conf/scheduler_standalone.config +++ /dev/null @@ -1,57 +0,0 @@ -# Rating system designed to be used in VoIP Carriers World -# Copyright (C) 2012 Radu Ioan Fericean -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see - -[global] -redis_server = 127.0.0.1:6379 #redis address host:port -redis_db = 10 # redis database number - -[rater] -standalone = true # start standalone server (no balancer) -balancer_server = 127.0.0.1:2000 # balancer address host:port -listen_api = 127.0.0.1:1234 # listening address host:port -json = false # use JSON for RPC encoding - -[balancer] -enabled = false -standalone = false # run standalone -listen_rater = 127.0.0.1:2000 # Rater server address -listen_api = 127.0.0.1:2001 # Json RPC server address -web_status_server = 127.0.0.1:8000 # Web server address (for status) -json = false # use JSON for RPC encoding - -[scheduler] -enabled = false -standalone = false # run standalone (no other service) -json = false # use JSON for RPC encoding - -[session_manager] -enabled = false -standalone = false # run standalone -api_server = 127.0.0.1:2000 # balancer address host:port -freeswitch_server = localhost:8021 # freeswitch address host:port -freeswitch_pass = ClueCon # freeswitch address host:port -json = false # use JSON for RPC encoding - -[mediator] -enabled = false -standalone = false # run standalone -cdr_file = Master.csv # Freeswitch Master CSV CDR file. -result_file = out.csv # Generated file containing CDR and price info. -host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets. -port = 5432 # The port to bind to. -db = cgrates # The name of the database to connect to. -user = # The user to sign in as. -password = # The user's password. \ No newline at end of file diff --git a/conf/session_manager.config b/conf/session_manager.config index bb1f63c30..8b20ad33a 100644 --- a/conf/session_manager.config +++ b/conf/session_manager.config @@ -24,34 +24,10 @@ balancer_server = 127.0.0.1:2000 # balancer address host:port listen_api = 127.0.0.1:1234 # listening address host:port json = false # use JSON for RPC encoding -[balancer] -enabled = false -standalone = false # run standalone -listen_rater = 127.0.0.1:2000 # Rater server address -listen_api = 127.0.0.1:2001 # Json RPC server address -web_status_server = 127.0.0.1:8000 # Web server address (for status) -json = false # use JSON for RPC encoding - -[scheduler] -enabled = false -standalone = false # run standalone (no other service) -json = false # use JSON for RPC encoding - [session_manager] enabled = false -standalone = false # run standalone api_server = 127.0.0.1:2000 # balancer address host:port freeswitch_server = localhost:8021 # freeswitch address host:port freeswitch_pass = ClueCon # freeswitch address host:port json = false # use JSON for RPC encoding -[mediator] -enabled = false -standalone = false # run standalone -cdr_file = Master.csv # Freeswitch Master CSV CDR file. -result_file = out.csv # Generated file containing CDR and price info. -host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets. -port = 5432 # The port to bind to. -db = cgrates # The name of the database to connect to. -user = # The user to sign in as. -password = # The user's password. \ No newline at end of file diff --git a/conf/session_manager_standalone.config b/conf/session_manager_standalone.config deleted file mode 100644 index bb1f63c30..000000000 --- a/conf/session_manager_standalone.config +++ /dev/null @@ -1,57 +0,0 @@ -# Rating system designed to be used in VoIP Carriers World -# Copyright (C) 2012 Radu Ioan Fericean -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see - -[global] -redis_server = 127.0.0.1:6379 #redis address host:port -redis_db = 10 # redis database number - -[rater] -standalone = true # start standalone server (no balancer) -balancer_server = 127.0.0.1:2000 # balancer address host:port -listen_api = 127.0.0.1:1234 # listening address host:port -json = false # use JSON for RPC encoding - -[balancer] -enabled = false -standalone = false # run standalone -listen_rater = 127.0.0.1:2000 # Rater server address -listen_api = 127.0.0.1:2001 # Json RPC server address -web_status_server = 127.0.0.1:8000 # Web server address (for status) -json = false # use JSON for RPC encoding - -[scheduler] -enabled = false -standalone = false # run standalone (no other service) -json = false # use JSON for RPC encoding - -[session_manager] -enabled = false -standalone = false # run standalone -api_server = 127.0.0.1:2000 # balancer address host:port -freeswitch_server = localhost:8021 # freeswitch address host:port -freeswitch_pass = ClueCon # freeswitch address host:port -json = false # use JSON for RPC encoding - -[mediator] -enabled = false -standalone = false # run standalone -cdr_file = Master.csv # Freeswitch Master CSV CDR file. -result_file = out.csv # Generated file containing CDR and price info. -host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets. -port = 5432 # The port to bind to. -db = cgrates # The name of the database to connect to. -user = # The user to sign in as. -password = # The user's password. \ No newline at end of file diff --git a/data/test.config b/data/test.config index f4e1cc29a..5f16b1f8b 100644 --- a/data/test.config +++ b/data/test.config @@ -34,12 +34,10 @@ json = true # use JSON for RPC encoding [scheduler] enabled = true -standalone = true # run standalone (no other service) json = true # use JSON for RPC encoding [session_manager] enabled = true -standalone = true # run standalone api_server = test # balancer address host:port freeswitch_server = test # freeswitch address host:port freeswitch_pass = test # freeswitch address host:port @@ -47,7 +45,6 @@ json = true # use JSON for RPC encoding [mediator] enabled = true -standalone = true # run standalone cdr_file = test # Freeswitch Master CSV CDR file. result_file = test # Generated file containing CDR and price info. host = test # The host to connect to. Values that start with / are for UNIX domain sockets.