-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathsupervisor.cc
76 lines (63 loc) · 2.08 KB
/
supervisor.cc
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
/*
* Copyright (C) 2017 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
*/
#include "supervisor.hh"
#include "log.hh"
#include <seastar/core/print.hh>
#include <csignal>
#include <cstdlib>
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif
extern logger startlog;
const sstring supervisor::scylla_upstart_job_str("scylla-server");
const sstring supervisor::upstart_job_env("UPSTART_JOB");
const sstring supervisor::systemd_ready_msg("READY=1");
const sstring supervisor::systemd_status_msg_prefix("STATUS");
sstring supervisor::get_upstart_job_env() {
const char* upstart_job = std::getenv(upstart_job_env.c_str());
return !upstart_job ? "" : upstart_job;
}
bool supervisor::try_notify_upstart(sstring msg, bool ready) {
static const sstring upstart_job_str(get_upstart_job_env());
if (upstart_job_str != scylla_upstart_job_str) {
return false;
}
if (ready) {
std::raise(SIGSTOP);
}
return true;
}
void supervisor::try_notify_systemd(sstring msg, bool ready) {
#ifdef HAVE_LIBSYSTEMD
if (ready) {
sd_notify(0, sprint("%s\n%s=%s\n", systemd_ready_msg, systemd_status_msg_prefix, msg).c_str());
} else {
sd_notify(0, sprint("%s=%s\n", systemd_status_msg_prefix, msg).c_str());
}
#endif
}
void supervisor::notify(sstring msg, bool ready) {
startlog.trace("{}", msg);
if (try_notify_upstart(msg, ready) == true) {
return;
} else {
try_notify_systemd(msg, ready);
}
}