Files
scylladb/supervisor.hh
Avi Kivity f3eade2f62 treewide: relicense to ScyllaDB-Source-Available-1.0
Drop the AGPL license in favor of a source-available license.
See the blog post [1] for details.

[1] https://www.scylladb.com/2024/12/18/why-were-moving-to-a-source-available-license/
2024-12-18 17:45:13 +02:00

44 lines
1.2 KiB
C++

/*
* Copyright (C) 2017-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include <seastar/core/sstring.hh>
#include <seastar/core/format.hh>
#include <seastar/util/log.hh>
#include "seastarx.hh"
#include <systemd/sd-daemon.h>
extern logger startlog;
class supervisor {
public:
static constexpr auto systemd_ready_msg = "READY=1";
/** A systemd status message has a format <status message prefix>=<message> */
static constexpr auto systemd_status_msg_prefix = "STATUS";
public:
/**
* @brief Notify the Supervisor with the given message.
* @param msg message to notify the Supervisor with
* @param ready set to TRUE when scylla service becomes ready
*/
static inline void notify(sstring msg, bool ready = false) {
startlog.info("{}", msg);
try_notify_systemd(msg, ready);
}
private:
static inline void try_notify_systemd(sstring msg, bool ready) {
if (ready) {
sd_notify(0, format("{}\n{}={}\n", systemd_ready_msg, systemd_status_msg_prefix, msg).c_str());
} else {
sd_notify(0, format("{}={}\n", systemd_status_msg_prefix, msg).c_str());
}
}
};