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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <sys/types.h>
#include <sys/select.h>
#include <list>
#include <vespa/vespalib/util/hashmap.h>
#include <vespa/config-sentinel.h>
#include <vespa/config/config.h>
#include "service.h"
#include "metrics.h"
#include "state-api.h"
using cloud::config::SentinelConfig;
using config::ConfigSubscriber;
using config::ConfigHandle;
namespace config {
namespace sentinel {
class CommandConnection;
class OutputConnection;
class ConfigHandler {
private:
typedef std::map<vespalib::string, Service::UP> ServiceMap;
ConfigSubscriber _subscriber;
ConfigHandle<SentinelConfig>::UP _sentinelHandle;
ServiceMap _services;
std::list<CommandConnection *> _connections;
std::list<OutputConnection *> _outputConnections;
int _boundPort;
int _commandSocket;
StartMetrics _startMetrics;
StateApi _stateApi;
ConfigHandler(const ConfigHandler&);
ConfigHandler& operator =(const ConfigHandler&);
Service *serviceByPid(pid_t pid);
Service *serviceByName(const vespalib::string & name);
void handleCommands();
void handleCommand(CommandConnection *c);
void handleOutputs();
void handleChildDeaths();
static int listen(int port);
void configure_port(int port);
void updateMetrics();
void doGet(CommandConnection *c, char *args);
void doLs(CommandConnection *c, char *args);
void doRestart(CommandConnection *c, char *args);
void doRestart(CommandConnection *c, char *args, bool force);
void doStart(CommandConnection *c, char *args);
void doStop(CommandConnection *c, char *args);
void doStop(CommandConnection *c, char *args, bool force);
void doAuto(CommandConnection *c, char *args);
void doManual(CommandConnection *c, char *args);
void doQuit(CommandConnection *c, char *args);
void terminateServices(bool catchable, bool printDebug = false);
void doConfigure();
public:
ConfigHandler();
virtual ~ConfigHandler();
void subscribe(const std::string & configId, uint64_t timeoutMS);
bool terminate();
int doWork();
void updateActiveFdset(fd_set *fds, int *maxNum);
};
} // end namespace config::sentinel
} // end namespace config
|