Skip to content

Commit d1fe910

Browse files
authored
Merge pull request #237 from Paiusco/create-split-systemd-system-user-service
Create CMake option for systemd system/user service
2 parents 27e9ebf + f13aeec commit d1fe910

File tree

7 files changed

+44
-17
lines changed

7 files changed

+44
-17
lines changed

.github/workflows/push_pr_build_cmake.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
run: |
4949
mv ${{github.workspace}}/build/ydotool ${{github.workspace}}/build/ydotool-${{matrix.os}}
5050
mv ${{github.workspace}}/build/ydotoold ${{github.workspace}}/build/ydotoold-${{matrix.os}}
51+
mv ${{github.workspace}}/build/ydotoold.service ${{github.workspace}}/build/ydotoold-${{matrix.os}}.service
5152
5253
- name: Archive production artifacts
5354
uses: actions/upload-artifact@v4
@@ -56,4 +57,5 @@ jobs:
5657
path: |
5758
${{github.workspace}}/build/ydotool-${{matrix.os}}
5859
${{github.workspace}}/build/ydotoold-${{matrix.os}}
60+
${{github.workspace}}/build/ydotoold-${{matrix.os}}.service
5961

CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ set(CMAKE_C_STANDARD 11)
66
# Include GNU install directory module to detect where to install
77
# files on Linux/Unix systems (e.g., lib vs lib64)
88
include(GNUInstallDirs)
9-
find_package(PkgConfig)
10-
11-
# Try to get the systemd directory for user units from the package
12-
# and fall back on upstream default without the '/usr' prefix
13-
pkg_check_modules(SYSTEMD systemd)
14-
if (SYSTEMD_FOUND)
15-
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
16-
else()
17-
set(SD_UNITDIR "lib/systemd/user")
18-
endif()
199

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

Daemon/CMakeLists.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
configure_file(
2-
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
3-
"${PROJECT_BINARY_DIR}/ydotoold.service"
4-
@ONLY)
5-
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})
1+
option(SYSTEMD_USER_SERVICE "Install systemd user service file" ON)
2+
option(SYSTEMD_SYSTEM_SERVICE "Install systemd system service file" OFF)
3+
option(OPENRC "Install OpenRC service file" OFF) # To be implemented
4+
5+
if(SYSTEMD_USER_SERVICE AND SYSTEMD_SYSTEM_SERVICE)
6+
message(FATAL_ERROR "Both system and user services are enabled. Choose one.")
7+
endif()
8+
9+
if(SYSTEMD_USER_SERVICE OR SYSTEMD_SYSTEM_SERVICE)
10+
add_subdirectory(systemd)
11+
endif()
12+
13+
if(OPENRC)
14+
add_subdirectory(openrc)
15+
endif()

Daemon/openrc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TBD
File renamed without changes.

Daemon/systemd/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
find_package(PkgConfig)
2+
3+
# Try to get the systemd directory for system/user units from the package
4+
# and fall back on upstream default without the '/usr' prefix if not forced by
5+
# command line.
6+
pkg_check_modules(SYSTEMD systemd)
7+
if (SYSTEMD_FOUND)
8+
if(SYSTEMD_USER_SERVICE)
9+
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
10+
elseif(SYSTEMD_SYSTEM_SERVICE)
11+
pkg_get_variable(SD_UNITDIR systemd systemdsystemunitdir)
12+
endif()
13+
endif()
14+
15+
if(NOT DEFINED SD_UNITDIR)
16+
set(SD_UNITDIR "lib/systemd/user")
17+
endif()
18+
19+
message("Systemd service file is going to be installed at ${SD_UNITDIR}")
20+
21+
configure_file(
22+
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
23+
"${PROJECT_BINARY_DIR}/ydotoold.service"
24+
@ONLY)
25+
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})

Daemon/ydotoold.service.in renamed to Daemon/systemd/ydotoold.service.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[Unit]
2-
Description=Starts ydotoold user service
2+
Description=Starts ydotoold Daemon
33

44
[Service]
55
Type=simple
@@ -13,4 +13,3 @@ TimeoutSec=180
1313

1414
[Install]
1515
WantedBy=basic.target
16-

0 commit comments

Comments
 (0)