forked from sonic-net/sonic-swss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteammgrd.cpp
105 lines (84 loc) · 2.51 KB
/
teammgrd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <fstream>
#include "teammgr.h"
#include "netdispatcher.h"
#include "netlink.h"
#include "select.h"
#include "warm_restart.h"
#include <signal.h>
using namespace std;
using namespace swss;
#define SELECT_TIMEOUT 1000
bool received_sigterm = false;
static struct sigaction old_sigaction;
void sig_handler(int signo)
{
SWSS_LOG_ENTER();
if (old_sigaction.sa_handler != SIG_IGN && old_sigaction.sa_handler != SIG_DFL) {
old_sigaction.sa_handler(signo);
}
received_sigterm = true;
return;
}
int main(int argc, char **argv)
{
Logger::linkToDbNative("teammgrd");
SWSS_LOG_ENTER();
SWSS_LOG_NOTICE("--- Starting teammrgd ---");
/* Register the signal handler for SIGTERM */
struct sigaction sigact = {};
sigact.sa_handler = sig_handler;
if (sigaction(SIGTERM, &sigact, &old_sigaction))
{
SWSS_LOG_ERROR("failed to setup SIGTERM action handler");
exit(EXIT_FAILURE);
}
try
{
DBConnector conf_db("CONFIG_DB", 0);
DBConnector app_db("APPL_DB", 0);
DBConnector state_db("STATE_DB", 0);
WarmStart::initialize("teammgrd", "teamd");
WarmStart::checkWarmStart("teammgrd", "teamd");
TableConnector conf_lag_table(&conf_db, CFG_LAG_TABLE_NAME);
TableConnector conf_lag_member_table(&conf_db, CFG_LAG_MEMBER_TABLE_NAME);
TableConnector state_port_table(&state_db, STATE_PORT_TABLE_NAME);
vector<TableConnector> tables = {
conf_lag_table,
conf_lag_member_table,
state_port_table
};
TeamMgr teammgr(&conf_db, &app_db, &state_db, tables);
vector<Orch *> cfgOrchList = {&teammgr};
Select s;
for (Orch *o: cfgOrchList)
{
s.addSelectables(o->getSelectables());
}
while (!received_sigterm)
{
Selectable *sel;
int ret;
ret = s.select(&sel, SELECT_TIMEOUT);
if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
continue;
}
if (ret == Select::TIMEOUT)
{
teammgr.doTask();
continue;
}
auto *c = (Executor *)sel;
c->execute();
}
teammgr.cleanTeamProcesses();
SWSS_LOG_NOTICE("Exiting");
}
catch (const exception &e)
{
SWSS_LOG_ERROR("Runtime error: %s", e.what());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}