Skip to content
Snippets Groups Projects
Verified Commit ed5782dc authored by Benny Baumann's avatar Benny Baumann
Browse files

Minimalistic systemd service

parent 0b3f869b
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ Source: rmrf
Section: mail
Priority: optional
Maintainer: Benny Baumann <benbe@chaotikum.org>
Build-Depends: debhelper (>= 10), libncurses-dev (>=6) | libncurses5-dev (>=6), libssl-dev (>= 1.1.0), libboost-dev, libboost-test-dev, libpython3-dev, liblua5.3-dev, gettext
Build-Depends: debhelper (>= 10), libncurses-dev (>=6) | libncurses5-dev (>=6), libssl-dev (>= 1.1.0), libboost-dev, libboost-test-dev, libpython3-dev, liblua5.3-dev, libsystemd-dev (>= 42), gettext
Standards-Version: 4.1.2
Homepage: https://git.chaotikum.org/ReadMailReallyFast
Vcs-Git: https://git.chaotikum.org/ReadMailReallyFast/code.git
......
#include <chrono>
#include <cstdint>
#include <thread>
#include "service/daemonctl.hpp"
int main() {
dctl_status_msg("Initializing");
dctl_status_msg("Reading configuration");
dctl_status_msg("Initializing network");
dctl_status_msg("Loading caches");
dctl_status_msg("Refreshing caches");
dctl_status_msg("Reading state");
dctl_status_msg("Initializing");
dctl_status_msg("Binding sockets");
dctl_status_msg("Activating");
dctl_status_ready();
dctl_status_msg("Active");
for(size_t x = 10; x; x--) {
std::this_thread::sleep_for(std::chrono::seconds(1));
dctl_watchdog_refresh();
}
dctl_status_msg("Preparing for shutdown");
dctl_status_shutdown();
dctl_status_msg("Finalizing pending transactions");
dctl_status_msg("Storing active state");
dctl_status_msg("Storing active caches");
dctl_status_msg("Closing active sockets");
dctl_status_msg("Inactive");
}
`pkg-config --cflags --libs libsystemd`
#pragma once
#define ATTR_NONNULL_ALL __attribute__((nonnull))
#define ATTR_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
#define ATTR_PRINTF(fmtpos, argpos) __attribute__(( format(printf, (fmtpos), (argpos) ) ))
#define ATTR_STRFTIME(fmtpos) __attribute__(( format(strftime, (fmtpos), 0 ) ))
#define ATTR_PACKED __attribute__((packed))
#define ATTR_WEAK __attribute__((weak))
#define ATTR_LIKELY(x) __builtin_expect((x), 1)
#define ATTR_UNLIKELY(x) __builtin_expect((x), 0)
#pragma once
#include "macros.hpp"
ATTR_NONNULL_ALL
void dctl_status_msg(const char* msg);
void dctl_status_ready();
void dctl_status_reload();
void dctl_status_shutdown();
void dctl_watchdog_refresh();
#include "service/daemonctl.hpp"
#ifdef __FreeBSD__
ATTR_WEAK
void dctl_status_msg(const char* msg) {
(void)msg;
}
ATTR_WEAK
void dctl_status_ready() {
}
ATTR_WEAK
void dctl_status_reload() {
}
ATTR_WEAK
void dctl_status_shutdown() {
}
ATTR_WEAK
void dctl_watchdog_refresh() {
}
#endif
#include "service/daemonctl.hpp"
#ifdef __linux__
#include <systemd/sd-daemon.h>
#include <iostream>
ATTR_NONNULL_ALL
void dctl_status_msg(const char* msg) {
sd_notifyf(0, "STATUS=%s", msg);
std::cout << SD_INFO << "STATUS=" << msg << std::endl;
}
void dctl_status_ready() {
sd_notify(0, "READY=1");
}
void dctl_status_reload() {
sd_notify(0, "RELOADING=1");
}
void dctl_status_shutdown() {
sd_notify(0, "STOPPING=1");
}
void dctl_watchdog_refresh() {
sd_notify(0, "WATCHDOG=1");
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment