mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
feat: use Type=notify-reload in daemon service (#7570)
* feat: use `Type=notify-reload` in daemon service * build: keep systemd names consistent --------- Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
@@ -15,7 +15,7 @@ tr_allow_compile_if(
|
||||
|
||||
target_compile_definitions(${TR_NAME}-daemon
|
||||
PRIVATE
|
||||
$<$<BOOL:${WITH_SYSTEMD}>:USE_SYSTEMD>)
|
||||
$<$<BOOL:${WITH_SYSTEMD}>:WITH_SYSTEMD>)
|
||||
|
||||
tr_target_compile_definitions_for_headers(${TR_NAME}-daemon
|
||||
PRIVATE
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <array>
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio> /* printf */
|
||||
#include <iostream>
|
||||
#include <iterator> /* std::back_inserter */
|
||||
@@ -48,7 +49,10 @@ struct tr_ctor;
|
||||
struct tr_session;
|
||||
struct tr_torrent;
|
||||
|
||||
#ifdef USE_SYSTEMD
|
||||
#ifdef WITH_SYSTEMD
|
||||
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
|
||||
#include <systemd/sd-daemon.h>
|
||||
|
||||
@@ -705,6 +709,25 @@ void tr_daemon::reconfigure()
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WITH_SYSTEMD
|
||||
auto ts = timespec{};
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
|
||||
{
|
||||
auto error = tr_error{};
|
||||
error.set_from_errno(errno);
|
||||
tr_logAddError(fmt::format(
|
||||
fmt::runtime(_("Failed to reload: Failed to get current monotonic time: {errmsg} ({errno})")),
|
||||
fmt::arg("errmsg", error.message()),
|
||||
fmt::arg("errno", error.code())));
|
||||
return;
|
||||
}
|
||||
|
||||
sd_notifyf(
|
||||
0,
|
||||
"STATUS=Reloading...\nRELOADING=1\nMONOTONIC_USEC=%" PRIu64 "\n",
|
||||
static_cast<uint64_t>(ts.tv_sec) * 1000000U + static_cast<uint64_t>(ts.tv_nsec) / 1000U);
|
||||
#endif
|
||||
|
||||
char const* configDir;
|
||||
|
||||
/* reopen the logfile to allow for log rotation */
|
||||
@@ -718,6 +741,8 @@ void tr_daemon::reconfigure()
|
||||
|
||||
tr_sessionSet(my_session_, load_settings(configDir));
|
||||
tr_sessionReloadBlocklists(my_session_);
|
||||
|
||||
sd_notify(0, "STATUS=Reload complete.\nREADY=1\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,8 @@ Documentation=man:@TR_NAME@-daemon(1)
|
||||
|
||||
[Service]
|
||||
User=transmission
|
||||
Type=notify
|
||||
Type=notify-reload
|
||||
ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/@TR_NAME@-daemon -f --log-level=error
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
|
||||
# Hardening
|
||||
CapabilityBoundingSet=
|
||||
|
||||
Reference in New Issue
Block a user