diff --git a/src/analytics/OpServerProxy.cc b/src/analytics/OpServerProxy.cc index 8987ec6e2b3..63347c36a7b 100644 --- a/src/analytics/OpServerProxy.cc +++ b/src/analytics/OpServerProxy.cc @@ -546,12 +546,16 @@ class OpServerProxy::OpServerImpl { return true; } - ~OpServerImpl() { + void Shutdown() { TimerManager::DeleteTimer(kafka_timer_); kafka_timer_ = NULL; StopKafka(); } + ~OpServerImpl() { + assert(kafka_timer_ == NULL); + } + RedisInfo redis_uve_; private: /* these are made public, so they are accessed by OpServerProxy */ @@ -591,6 +595,13 @@ OpServerProxy::~OpServerProxy() { delete impl_; } +void +OpServerProxy::Shutdown() { + if (impl_) { + impl_->Shutdown(); + } +} + bool OpServerProxy::UVENotif(const std::string &type, const std::string &source, const std::string &node_type, diff --git a/src/analytics/OpServerProxy.h b/src/analytics/OpServerProxy.h index ace1317d915..bb9fb51fabc 100644 --- a/src/analytics/OpServerProxy.h +++ b/src/analytics/OpServerProxy.h @@ -32,6 +32,7 @@ class OpServerProxy { uint16_t partitions); OpServerProxy() : impl_(NULL) { } virtual ~OpServerProxy(); + virtual void Shutdown(); virtual bool UVEUpdate(const std::string &type, const std::string &attr, const std::string &source, const std::string &node_type, diff --git a/src/analytics/main.cc b/src/analytics/main.cc index 8fb062cff08..014fefad589 100644 --- a/src/analytics/main.cc +++ b/src/analytics/main.cc @@ -188,8 +188,11 @@ static void ShutdownServers(VizCollector *viz_collector, viz_collector->Shutdown(); - TimerManager::DeleteTimer(collector_info_log_timer); - delete collector_info_trigger; + if (collector_info_log_timer) { + TimerManager::DeleteTimer(collector_info_log_timer); + delete collector_info_trigger; + collector_info_log_timer = NULL; + } ConnectionStateManager:: GetInstance()->Shutdown(); @@ -352,13 +355,19 @@ int main(int argc, char *argv[]) unsigned short coll_port = analytics.GetCollector()->GetPort(); VizSandeshContext vsc(&analytics); Sandesh::set_send_rate_limit(options.sandesh_send_rate_limit()); - Sandesh::InitCollector( + bool success(Sandesh::InitCollector( module_id, analytics.name(), g_vns_constants.NodeTypeNames.find(node_type)->second, instance_id, a_evm, "127.0.0.1", coll_port, - options.http_server_port(), &vsc); + options.http_server_port(), &vsc)); + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + ShutdownServers(&analytics, NULL); + delete a_evm; + exit(1); + } Sandesh::SetLoggingParams(options.log_local(), options.log_category(), options.log_level()); diff --git a/src/analytics/viz_collector.cc b/src/analytics/viz_collector.cc index 85c85e01615..4a26062725c 100644 --- a/src/analytics/viz_collector.cc +++ b/src/analytics/viz_collector.cc @@ -121,6 +121,7 @@ void VizCollector::Shutdown() { } TcpServerManager::DeleteServer(collector_); + osp_->Shutdown(); syslog_listener_->Shutdown(); WaitForIdle(); diff --git a/src/control-node/main.cc b/src/control-node/main.cc index f50cc14fac7..a046638610b 100644 --- a/src/control-node/main.cc +++ b/src/control-node/main.cc @@ -149,8 +149,9 @@ static void ShutdownServers( channel_manager->reset(); TcpServerManager::DeleteServer(xmpp_server); - TimerManager::DeleteTimer(node_info_log_timer); - + if (node_info_log_timer) { + TimerManager::DeleteTimer(node_info_log_timer); + } // Shutdown Discovery Service Client ShutdownDiscoveryClient(dsclient); @@ -474,8 +475,9 @@ int main(int argc, char *argv[]) { if (sandesh_generator_init) { NodeType::type node_type = g_vns_constants.Module2NodeType.find(module)->second; + bool success; if (options.collectors_configured()) { - Sandesh::InitGenerator( + success = Sandesh::InitGenerator( module_name, options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, @@ -485,7 +487,7 @@ int main(int argc, char *argv[]) { options.collector_server_list(), &sandesh_context); } else { - Sandesh::InitGenerator( + success = Sandesh::InitGenerator( g_vns_constants.ModuleNames.find(module)->second, options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, @@ -494,6 +496,11 @@ int main(int argc, char *argv[]) { options.http_server_port(), &sandesh_context); } + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + Sandesh::Uninit(); + exit(1); + } } Sandesh::SetLoggingParams(options.log_local(), options.log_category(), @@ -586,7 +593,7 @@ int main(int argc, char *argv[]) { ds_client, _1, _2, _3); vector list; list.clear(); - Sandesh::InitGenerator(subscriber_name, + bool success(Sandesh::InitGenerator(subscriber_name, options.hostname(), node_type_name, g_vns_constants.INSTANCE_ID_DEFAULT, @@ -594,7 +601,12 @@ int main(int argc, char *argv[]) { options.http_server_port(), csf, list, - &sandesh_context); + &sandesh_context)); + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + ShutdownServers(&bgp_peer_manager, ds_client, NULL); + exit(1); + } } } else { LOG(ERROR, "Invalid Discovery Server hostname or ip " << diff --git a/src/dns/contrail-dns.ini b/src/dns/contrail-dns.ini index ca5a3d35287..78b7a30feb6 100644 --- a/src/dns/contrail-dns.ini +++ b/src/dns/contrail-dns.ini @@ -8,6 +8,6 @@ stdout_capture_maxbytes=1MB redirect_stderr=true stdout_logfile=/var/log/contrail/contrail-dns-stdout.log stderr_logfile=/dev/null -startsecs=5 +startsecs=10 exitcodes=0 ; 'expected' exit codes for process (default 0,2) user=contrail diff --git a/src/dns/main.cc b/src/dns/main.cc index 9c3cef2be88..81abf7f9a83 100644 --- a/src/dns/main.cc +++ b/src/dns/main.cc @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) { if (options.discovery_server().empty()) { NodeType::type node_type = g_vns_constants.Module2NodeType.find(module)->second; - Sandesh::InitGenerator( + bool success(Sandesh::InitGenerator( module_name, options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, @@ -136,7 +136,12 @@ int main(int argc, char *argv[]) { Dns::GetEventManager(), options.http_server_port(), 0, options.collector_server_list(), - NULL); + NULL)); + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + Sandesh::Uninit(); + exit(1); + } } Sandesh::SetLoggingParams(options.log_local(), options.log_category(), options.log_level()); @@ -222,7 +227,7 @@ int main(int argc, char *argv[]) { _1, _2, _3); vector list; list.clear(); - Sandesh::InitGenerator(subscriber_name, + bool success(Sandesh::InitGenerator(subscriber_name, options.hostname(), node_type_name, g_vns_constants.INSTANCE_ID_DEFAULT, @@ -230,7 +235,13 @@ int main(int argc, char *argv[]) { options.http_server_port(), csf, list, - NULL); + NULL)); + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + Sandesh::Uninit(); + Dns::ShutdownDiscoveryClient(ds_client); + exit(1); + } } } else { LOG(ERROR, "Invalid Discovery Server hostname or ip " << diff --git a/src/query_engine/qed.cc b/src/query_engine/qed.cc index fe1c8ceb9ab..22e363ae6f3 100644 --- a/src/query_engine/qed.cc +++ b/src/query_engine/qed.cc @@ -122,6 +122,23 @@ static bool OptionsParse(Options &options, EventManager &evm, return false; } +static void ShutdownQe(DiscoveryServiceClient *ds_client, + Timer *qe_info_log_timer) { + if (ds_client) { + ds_client->Shutdown(); + delete ds_client; + } + if (qe_info_log_timer) { + qe_info_log_timer->Cancel(); + TimerManager::DeleteTimer(qe_info_log_timer); + } + WaitForIdle(); + Sandesh::Uninit(); + ConnectionStateManager:: + GetInstance()->Shutdown(); + WaitForIdle(); +} + int main(int argc, char *argv[]) { EventManager evm; @@ -205,7 +222,7 @@ main(int argc, char *argv[]) { instance_id, boost::bind(&GetProcessStateCb, _1, _2, _3, 3)); Sandesh::set_send_rate_limit(options.sandesh_send_rate_limit()); - Sandesh::InitGenerator( + bool success(Sandesh::InitGenerator( module_name, options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, @@ -214,7 +231,13 @@ main(int argc, char *argv[]) { options.http_server_port(), csf, options.collector_server_list(), - NULL); + NULL)); + if (!success) { + LOG(ERROR, "SANDESH: Initialization FAILED ... exiting"); + ShutdownQe(ds_client, NULL); + exit(1); + } + Sandesh::SetLoggingParams(options.log_local(), options.log_category(), options.log_level()); @@ -246,17 +269,17 @@ main(int argc, char *argv[]) { ostream_iterator(css, " ")); LOG(INFO, "Cassandra Servers: " << css.str()); - QueryEngine *qe; + boost::scoped_ptr qe; if (cassandra_ports.size() == 1 && cassandra_ports[0] == 0) { - qe = new QueryEngine(&evm, + qe.reset(new QueryEngine(&evm, options.redis_server(), options.redis_port(), options.redis_password(), max_tasks, options.max_slice(), - options.analytics_data_ttl()); + options.analytics_data_ttl())); } else { - qe = new QueryEngine(&evm, + qe.reset(new QueryEngine(&evm, cassandra_ips, cassandra_ports, options.redis_server(), @@ -265,9 +288,8 @@ main(int argc, char *argv[]) { max_tasks, options.max_slice(), options.analytics_data_ttl(), - options.start_time()); + options.start_time())); } - (void) qe; CpuLoadData::Init(); qe_info_trigger = @@ -279,17 +301,6 @@ main(int argc, char *argv[]) { signal(SIGTERM, terminate_qe); evm.Run(); - if (ds_client) { - ds_client->Shutdown(); - delete ds_client; - } - qe_info_log_timer->Cancel(); - TimerManager::DeleteTimer(qe_info_log_timer); - WaitForIdle(); - delete qe; - Sandesh::Uninit(); - ConnectionStateManager:: - GetInstance()->Shutdown(); - WaitForIdle(); + ShutdownQe(ds_client, qe_info_log_timer); return 0; }