Skip to content

Commit

Permalink
Add sysusers.d configuration file for systemd service
Browse files Browse the repository at this point in the history
  • Loading branch information
roehling committed Aug 13, 2023
1 parent 82e7471 commit 8f84b0d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ set(SYSTEMD_UNITDIR
"${DETECTED_SYSTEMD_UNITDIR}"
CACHE PATH "Install destination for the systemd postsrsd.service unit"
)
find_systemd_sysusers_destination(DETECTED_SYSTEMD_SYSUSERSDIR)
set(SYSTEMD_SYSUSERSDIR
"${DETECTED_SYSTEMD_SYSUSERSDIR}"
CACHE PATH "Install destination for the sysusers.d configuration"
)

if(POSTSRSD_CHROOTDIR)
file(RELATIVE_PATH CHROOTABLE_DATADIR "${POSTSRSD_CHROOTDIR}"
Expand Down Expand Up @@ -350,6 +355,10 @@ configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/data/postsrsd.service.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.service" @ONLY
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/data/sysusers.conf.in"
"${CMAKE_CURRENT_BINARY_DIR}/sysusers.d/${PROJECT_NAME}.conf" @ONLY
)

install(TARGETS postsrsd RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.conf"
Expand All @@ -359,6 +368,9 @@ if(INSTALL_SYSTEMD_SERVICE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.service"
DESTINATION "${SYSTEMD_UNITDIR}"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sysusers.d/${PROJECT_NAME}.conf"
DESTINATION "${SYSTEMD_SYSUSERSDIR}"
)
endif()

if(GENERATE_SRS_SECRET)
Expand Down
23 changes: 23 additions & 0 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,26 @@ function(find_systemd_unit_destination var)
)
endif()
endfunction()

function(find_systemd_sysusers_destination var)
if(CMAKE_INSTALL_PREFIX MATCHES "^/usr/?$")
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_get_variable(sysusersdir systemd sysusersdir)
set(${var}
"${sysusersdir}"
PARENT_SCOPE
)
else()
set(${var}
"/usr/lib/sysusers.d"
PARENT_SCOPE
)
endif()
else()
set(${var}
"/etc/sysusers.d"
PARENT_SCOPE
)
endif()
endfunction()
1 change: 1 addition & 0 deletions data/sysusers.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
u @POSTSRSD_USER@ - "PostSRSd user" - -
6 changes: 5 additions & 1 deletion doc/packaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ users:
installation secure by default, but less so for a distributed binary package.

- ``INSTALL_SYSTEMD_SERVICE``: If set to ``ON`` (the default), a postsrsd.service
unit will be installed to start PostSRSd via systemd at boot time. You can disable
unit will be installed to allow starting PostSRSd via systemd. You can disable
this if your distribution uses a different init system.

- ``SYSTEMD_UNITDIR``: the intended install destination for the
``postsrsd.service`` file. The default should be fine for most systems, but
you can override it if the auto-detected location is wrong.

- ``SYSTEMD_SYSUSERSDIR``: the intended install destination for the
sysusers.d configuration file. The default should be fine for most systems, but
you can override it if the auto-detected location is wrong.

- ``DEVELOPER_BUILD``: this makes the compiler treat all warnings as errors and
enable as much of them as possible. While certainly useful for me as upstream
developer (and for the Github CI), you should keep this option disabled. It
Expand Down

0 comments on commit 8f84b0d

Please sign in to comment.