Skip to content

Commit 548a8d8

Browse files
systemd: add user-service symlink at /usr/lib/systemd/user/ (#2173)
* systemd: add user-service symlink at /usr/lib/systemd/user/ * harden symlink creation and ci test --------- Co-authored-by: fl0rianr <226492742+fl0rianr@users.noreply.github.com>
1 parent a126536 commit 548a8d8

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

.github/workflows/cpp_server_build_test_release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,11 @@ jobs:
14921492
/opt/bin/lemonade --version
14931493
/opt/bin/lemond --version
14941494
1495+
rpm -qpl "$RPM_FILE" | grep -Fx "/usr/lib/systemd/user/lemond.service"
1496+
rpm -qpl --dump "$RPM_FILE" \
1497+
| grep -E '^/usr/lib/systemd/user/lemond\.service ' \
1498+
| grep -F "/opt/lib/systemd/user/lemond.service"
1499+
14951500
test-embeddable-posix:
14961501
name: Test Embeddable (${{ matrix.label }})
14971502
runs-on: ${{ matrix.os }}

CMakeLists.txt

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,34 @@ if(UNIX AND NOT APPLE)
14061406
PATTERN "*.sh" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
14071407
)
14081408

1409+
# Helper: create a systemd unit symlink with fatal-error-on-failure semantics
1410+
function(lemonade_install_systemd_symlink link_path target_path)
1411+
get_filename_component(_link_dir "${link_path}" DIRECTORY)
1412+
1413+
install(CODE "
1414+
set(_link \"\$ENV{DESTDIR}${link_path}\")
1415+
set(_target \"${target_path}\")
1416+
1417+
file(MAKE_DIRECTORY \"\$ENV{DESTDIR}${_link_dir}\")
1418+
1419+
if(IS_SYMLINK \"\${_link}\")
1420+
file(REMOVE \"\${_link}\")
1421+
elseif(EXISTS \"\${_link}\")
1422+
message(FATAL_ERROR \"Refusing to replace existing non-symlink: \${_link}\")
1423+
endif()
1424+
1425+
execute_process(
1426+
COMMAND \"${CMAKE_COMMAND}\" -E create_symlink \"\${_target}\" \"\${_link}\"
1427+
RESULT_VARIABLE _result
1428+
ERROR_VARIABLE _error
1429+
)
1430+
1431+
if(NOT _result EQUAL 0)
1432+
message(FATAL_ERROR \"Failed to create systemd symlink \${_link} -> \${_target}: \${_error}\")
1433+
endif()
1434+
")
1435+
endfunction()
1436+
14091437
# Configure systemd service file (uses CMAKE_INSTALL_FULL_* variables)
14101438
configure_file(
14111439
${CMAKE_SOURCE_DIR}/data/lemond.service.in
@@ -1417,17 +1445,17 @@ if(UNIX AND NOT APPLE)
14171445
install(FILES ${CMAKE_BINARY_DIR}/lemond.service
14181446
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/system
14191447
)
1420-
# Create symlink in standard systemd search path only if not installing to /usr
1448+
# Create symlinks in standard systemd search paths only if not installing to /usr
14211449
# (if prefix is /usr, the service is already in the standard location)
14221450
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
1423-
install(CODE "
1424-
file(MAKE_DIRECTORY \"\$ENV{DESTDIR}/usr/lib/systemd/system\")
1425-
execute_process(
1426-
COMMAND ${CMAKE_COMMAND} -E create_symlink
1427-
${CMAKE_INSTALL_PREFIX}/lib/systemd/system/lemond.service
1428-
\"\$ENV{DESTDIR}/usr/lib/systemd/system/lemond.service\"
1429-
)
1430-
")
1451+
lemonade_install_systemd_symlink(
1452+
"/usr/lib/systemd/system/lemond.service"
1453+
"${CMAKE_INSTALL_PREFIX}/lib/systemd/system/lemond.service"
1454+
)
1455+
lemonade_install_systemd_symlink(
1456+
"/usr/lib/systemd/user/lemond.service"
1457+
"${CMAKE_INSTALL_PREFIX}/lib/systemd/user/lemond.service"
1458+
)
14311459
endif()
14321460

14331461
# Install sysusers.d snippet so the 'lemonade' system user is created

0 commit comments

Comments
 (0)