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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "metrics.h"
#include <vespa/vespalib/stllike/string.h>
#include <vespa/config-sentinel.h>
#include <list>
using cloud::config::SentinelConfig;
namespace config::sentinel {
class OutputConnection;
class Service
{
private:
Service(const Service &);
Service& operator=(const Service &);
pid_t _pid;
enum ServiceState { READY, STARTING, RUNNING, TERMINATING, KILLING,
FINISHED, TERMINATED, KILLED, FAILED } _rawState;
const enum ServiceState& _state;
int _exitStatus;
SentinelConfig::Service *_config;
bool _isAutomatic;
static const int MAX_RESTART_PENALTY = 1800;
unsigned int _restartPenalty;
time_t _last_start;
void runChild(int pipes[2]) __attribute__((noreturn));
void ensureChildRuns(int fd);
void setState(ServiceState state);
void runPreShutdownCommand();
void runCommand(const std::string & command);
const char *stateName(ServiceState state) const;
const SentinelConfig::Application _application;
std::list<OutputConnection *> &_outputConnections;
StartMetrics &_metrics;
public:
using UP = std::unique_ptr<Service>;
~Service();
Service(const SentinelConfig::Service& config,
const SentinelConfig::Application& application,
std::list<OutputConnection *> &ocs,
StartMetrics &metrics);
void reconfigure(const SentinelConfig::Service& config);
int pid() const { return _pid; }
int terminate(bool catchable, bool dumpState);
int terminate() {
return terminate(true, false);
}
int start();
void youExited(int status); // Call this if waitpid says it exited
const vespalib::string & name() const;
const char *stateName() const { return stateName(_state); }
bool isRunning() const;
int exitStatus() const { return _exitStatus; }
const SentinelConfig::Service& serviceConfig() const { return *_config; }
void setAutomatic(bool autoStatus);
bool isAutomatic() const { return _isAutomatic; }
void resetRestartPenalty() { _restartPenalty = 0; }
void incrementRestartPenalty();
};
}
|