Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[teamsyncd][teammgrd] Graceful exit after receiving SIGTERM #1407

Merged
merged 3 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions cfgmgr/teammgrd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,8 @@ int main(int argc, char **argv)
s.addSelectables(o->getSelectables());
}

while (true)
{
if(received_sigterm)
{
teammgr.cleanTeamProcesses(SIGTERM);
received_sigterm = false;
}

while (!received_sigterm)
{
Selectable *sel;
int ret;

Expand All @@ -91,6 +85,8 @@ int main(int argc, char **argv)
auto *c = (Executor *)sel;
c->execute();
}
teammgr.cleanTeamProcesses(SIGTERM);
SWSS_LOG_NOTICE("Exiting");
}
catch (const exception &e)
{
Expand Down
44 changes: 18 additions & 26 deletions teamsyncd/teamsyncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,28 @@ int main(int argc, char **argv)
/* Register the signal handler for SIGTERM */
signal(SIGTERM, sig_handler);

while (1)
try
{
try
{
NetLink netlink;

netlink.registerGroup(RTNLGRP_LINK);
cout << "Listens to teamd events..." << endl;
netlink.dumpRequest(RTM_GETLINK);

s.addSelectable(&netlink);
while (true)
{
if(received_sigterm)
{
sync.cleanTeamSync();
received_sigterm = false;
}
NetLink netlink;
netlink.registerGroup(RTNLGRP_LINK);
cout << "Listens to teamd events..." << endl;
netlink.dumpRequest(RTM_GETLINK);

Selectable *temps;
s.select(&temps, 1000); // block for a second
sync.periodic();
}
}
catch (const std::exception& e)
s.addSelectable(&netlink);
while (!received_sigterm)
{
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
return 0;
Selectable *temps;
s.select(&temps, 1000); // block for a second
sync.periodic();
}
sync.cleanTeamSync();
SWSS_LOG_NOTICE("Received SIGTERM Exiting");
}
catch (const std::exception& e)
{
cout << "Exception \"" << e.what() << "\" had been thrown in deamon" << endl;
return 0;
}

return 1;
return 0;
}