From 66a504ac558fe2c9249eb2b906aa736c4022dbaf Mon Sep 17 00:00:00 2001 From: Syping Date: Sun, 17 Mar 2024 05:21:33 +0100 Subject: [PATCH] systemd: escape working directory --- CMakeLists.txt | 10 ++++++++++ src/systemd/dtranslatebot.service.in | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c01c808..178606b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,16 @@ endif() if (UNIX AND NOT APPLE) option(WITH_SYSTEMD "Build with systemd Support" OFF) if (WITH_SYSTEMD) + find_program(SYSTEMD_ESCAPE_EXECUTABLE NAMES systemd-escape) + if (DEFINED SYSTEMD_ESCAPE_EXECUTABLE) + execute_process( + COMMAND "${SYSTEMD_ESCAPE_EXECUTABLE}" "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dtranslatebot" + OUTPUT_VARIABLE dtranslatebot_SERVICE_WORKDIR + ) + string(STRIP "${dtranslatebot_SERVICE_WORKDIR}" dtranslatebot_SERVICE_WORKDIR) + else() + set(dtranslatebot_SERVICE_WORKDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dtranslatebot") + endif() configure_file(src/systemd/dtranslatebot.service.in "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" @ONLY) configure_file(src/systemd/dtranslatebot.sysusersd.in "${dtranslatebot_BINARY_DIR}/systemd/sysusers.d/dtranslatebot.conf" @ONLY) install(FILES "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/system") diff --git a/src/systemd/dtranslatebot.service.in b/src/systemd/dtranslatebot.service.in index b537c19..6c2e0c9 100644 --- a/src/systemd/dtranslatebot.service.in +++ b/src/systemd/dtranslatebot.service.in @@ -5,9 +5,9 @@ After=network.target [Service] User=dtranslatebot Group=dtranslatebot -WorkingDirectory="@CMAKE_INSTALL_FULL_LOCALSTATEDIR@/lib/dtranslatebot" +WorkingDirectory=@dtranslatebot_SERVICE_WORKDIR@ ExecStart="@CMAKE_INSTALL_FULL_BINDIR@/dtranslatebot" "@CMAKE_INSTALL_FULL_SYSCONFDIR@/dtranslatebot.json" -Restart=on-failure +Restart=on-abnormal [Install] WantedBy=multi-user.target