Files
scylladb/supervisor.hh
Kefu Chai 00810e6a01 treewide: include seastar/core/format.hh instead of seastar/core/print.hh
The later includes the former and in addition to `seastar::format()`,
`print.hh` also provides helpers like `seastar::fprint()` and
`seastar::print()`, which are deprecated and not used by scylladb.

Previously, we include `seastar/core/print.hh` for using
`seastar::format()`. and in seastar 5b04939e, we extracted
`seastar::format()` into `seastar/core/format.hh`. this allows us
to include a much smaller header.

In this change, we just include `seastar/core/format.hh` in place of
`seastar/core/print.hh`.

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>

Closes scylladb/scylladb#21574
2024-11-14 17:45:07 +02:00

44 lines
1.2 KiB
C++

/*
* Copyright (C) 2017-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#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());
}
}
};