aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/manager.h
blob: 6967e078dd9617ba2f179154046fe892ef0db831 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "cmdq.h"
#include "env.h"
#include "metrics.h"
#include "rpcserver.h"
#include "service.h"
#include "state-api.h"
#include <vespa/config-sentinel.h>
#include <vespa/vespalib/net/http/state_server.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/select.h>

#include <list>

using cloud::config::SentinelConfig;
using config::ConfigSubscriber;
using config::ConfigHandle;

namespace config::sentinel {

class OutputConnection;

/**
 *  Management of services.
 *  Handles requests from RPC, service events,
 *  and service configuration updates.
 **/
class Manager {
private:
    typedef std::map<vespalib::string, Service::UP> ServiceMap;

    Env &_env;
    ServiceMap _services;
    ServiceMap _orphans;
    std::list<OutputConnection *> _outputConnections;

    Manager(const Manager&) = delete;
    Manager& operator =(const Manager&) = delete;

    Service *serviceByPid(pid_t pid);
    Service *serviceByName(const vespalib::string & name);
    void handleCommands();
    void handleCmd(const Cmd& cmd);
    void handleOutputs();
    void handleChildDeaths();
    void handleRestarts();

    void terminateServices(bool catchable, bool printDebug = false);
    void doConfigure();
public:
    Manager(Env &env);
    virtual ~Manager();
    bool terminate();
    bool doWork();
    void updateActiveFdset(std::vector<pollfd> &fds);
};

}