diff --git a/src/analytics/OpServerProxy.cc b/src/analytics/OpServerProxy.cc index 1ebfe0ee7b8..cac75419db2 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 b95adad16e3..7414b3fae01 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(); @@ -356,13 +359,19 @@ int main(int argc, char *argv[]) unsigned short coll_port = analytics.GetCollector()->GetPort(); VizSandeshContext vsc(&analytics); - 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 0743229331f..01dda0076f5 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 c740dddcc20..f60a97ee07c 100644 --- a/src/control-node/main.cc +++ b/src/control-node/main.cc @@ -150,8 +150,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); @@ -549,8 +550,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, @@ -560,7 +562,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, @@ -569,6 +571,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(), @@ -687,11 +694,20 @@ int main(int argc, char *argv[]) { csf = boost::bind(&DiscoveryServiceClient::Subscribe, ds_client, _1, _2, _3); vector list; - Sandesh::InitGenerator(subscriber_name, options.hostname(), + bool success(Sandesh::InitGenerator(subscriber_name, + options.hostname(), node_type_name, g_vns_constants.INSTANCE_ID_DEFAULT, - &evm, options.http_server_port(), - csf, list, &sandesh_context); + &evm, + options.http_server_port(), + csf, + list, + &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 address " << 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 cde36e36849..07f08dd9c6a 100644 --- a/src/dns/main.cc +++ b/src/dns/main.cc @@ -133,7 +133,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, @@ -141,7 +141,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()); @@ -228,7 +233,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, @@ -236,7 +241,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 842bf1bbf36..3d5f0abd42c 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; @@ -209,7 +226,7 @@ main(int argc, char *argv[]) { options.hostname(), module_name, instance_id, boost::bind(&GetProcessStateCb, _1, _2, _3, 3)); - Sandesh::InitGenerator( + bool success(Sandesh::InitGenerator( module_name, options.hostname(), g_vns_constants.NodeTypeNames.find(node_type)->second, @@ -218,7 +235,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()); @@ -250,25 +273,24 @@ 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.max_slice())); } else { - qe = new QueryEngine(&evm, + qe.reset(new QueryEngine(&evm, cassandra_ips, cassandra_ports, options.redis_server(), options.redis_port(), options.redis_password(), max_tasks, - options.max_slice()); + options.max_slice())); } - (void) qe; CpuLoadData::Init(); qe_info_trigger = @@ -280,17 +302,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; }