1186077b2b945187a4042041b00b211e399789b2
7 Cluster::Cluster(Server serv
, size_t cnt
)
14 for (size_t i
= 0; i
< count
; ++i
) {
15 cluster
.push_back(proto
);
24 const vector
<Server
> &Cluster::getServers() const {
28 bool Cluster::start() {
31 for (auto &server
: cluster
) {
32 if (!server
.start()) {
36 pids
[server
.getPid()] = &server
;
42 void Cluster::stop(bool graceful
) {
43 for (auto &server
: cluster
) {
48 // no cookies for memcached; TERM is just too slow
49 server
.signal(SIGKILL
);
54 bool Cluster::isStopped() {
59 cluster
.begin(), cluster
.end(), [](Server
&s
) {
60 return s
.getPid() && !s
.tryWait();
64 bool Cluster::isListening() const {
69 cluster
.cbegin(), cluster
.cend(), [](const Server
&s
) {
70 return s
.isListening();
74 bool Cluster::ensureListening() {
78 auto listening
= all_of(
82 cluster
.begin(), cluster
.end(), [](Server
&s
) {
83 return s
.ensureListening();
87 for (auto &server
: cluster
) {
88 pids
[server
.getPid()] = &server
;
94 void Cluster::wait() {
97 while (!isStopped()) {
98 if (waitid(P_ALL
, 0, &inf
, WEXITED
| WNOWAIT
)) {
99 perror("Cluster::wait waitid()");
103 auto server
= pids
.find(inf
.si_pid
);
104 if (server
!= pids
.end()) {
105 server
->second
->wait();
110 bool Cluster::restart() {