Skip to content

Commit

Permalink
Update usage for system/user services with options
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Paiusco committed May 2, 2024
1 parent 27e9ebf commit 203b020
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ set(CMAKE_C_STANDARD 11)
# Include GNU install directory module to detect where to install
# files on Linux/Unix systems (e.g., lib vs lib64)
include(GNUInstallDirs)
find_package(PkgConfig)

# Try to get the systemd directory for user units from the package
# and fall back on upstream default without the '/usr' prefix
pkg_check_modules(SYSTEMD systemd)
if (SYSTEMD_FOUND)
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
else()
set(SD_UNITDIR "lib/systemd/user")
endif()

execute_process(COMMAND git describe --tags --long --always RESULT_VARIABLE RC_GIT_VER OUTPUT_VARIABLE GIT_VERSION)

Expand Down
34 changes: 29 additions & 5 deletions Daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
"${PROJECT_BINARY_DIR}/ydotoold.service"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})
option(SYSTEMD_USER_SERVICE "Install systemd user service file" ON)
option(SYSTEMD_SYSTEM_SERVICE "Install systemd system service file" OFF)
option(OPENRC "Install OpenRC service file" OFF) # To be implemented

if(SYSTEMD_USER_SERVICE AND SYSTEMD_SYSTEM_SERVICE)
message(FATAL_ERROR "Both system and user services are enabled. Choose one.")
endif()

if(SYSTEMD_USER_SERVICE OR SYSTEMD_SYSTEM_SERVICE)
find_package(PkgConfig)
# Try to get the systemd directory for system/user units from the package
# and fall back on upstream default without the '/usr' prefix
pkg_check_modules(SYSTEMD systemd)
if (SYSTEMD_FOUND)
if(SYSTEMD_USER_SERVICE)
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
elseif(SYSTEMD_SYSTEM_SERVICE)
pkg_get_variable(SD_UNITDIR systemd systemdsystemunitdir)
endif()
# else()
# set(SD_UNITDIR "lib/systemd/user")
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
"${PROJECT_BINARY_DIR}/ydotoold.service"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})
endif()
3 changes: 1 addition & 2 deletions Daemon/ydotoold.service.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Starts ydotoold user service
Description=Starts ydotoold Daemon

[Service]
Type=simple
Expand All @@ -13,4 +13,3 @@ TimeoutSec=180

[Install]
WantedBy=basic.target

0 comments on commit 203b020

Please sign in to comment.