eclass/systemd: Sync with Gentoo

It's from Gentoo commit c8af7eb1285a2683460618b71e2e9a14ca6badcd.
This commit is contained in:
Flatcar Buildbot 2024-10-21 07:07:25 +00:00
parent 7e40ff3bb8
commit 0574c33f54

View File

@ -4,7 +4,7 @@
# @ECLASS: systemd.eclass # @ECLASS: systemd.eclass
# @MAINTAINER: # @MAINTAINER:
# systemd@gentoo.org # systemd@gentoo.org
# @SUPPORTED_EAPIS: 5 6 7 8 # @SUPPORTED_EAPIS: 7 8
# @BLURB: helper functions to install systemd units # @BLURB: helper functions to install systemd units
# @DESCRIPTION: # @DESCRIPTION:
# This eclass provides a set of functions to install unit files for # This eclass provides a set of functions to install unit files for
@ -24,22 +24,17 @@
# } # }
# @CODE # @CODE
if [[ -z ${_SYSTEMD_ECLASS} ]]; then
_SYSTEMD_ECLASS=1
case ${EAPI} in case ${EAPI} in
6)
ewarn "${CATEGORY}/${PF}: ebuild uses ${ECLASS} with deprecated EAPI ${EAPI}!"
ewarn "${CATEGORY}/${PF}: Support will be removed on 2024-10-08. Please port to newer EAPI."
;;
7|8) ;; 7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac esac
inherit toolchain-funcs inherit toolchain-funcs
if [[ ${EAPI} == [56] ]]; then
DEPEND="virtual/pkgconfig"
else
BDEPEND="virtual/pkgconfig" BDEPEND="virtual/pkgconfig"
fi
# @FUNCTION: _systemd_get_dir # @FUNCTION: _systemd_get_dir
# @USAGE: <variable-name> <fallback-directory> # @USAGE: <variable-name> <fallback-directory>
@ -80,27 +75,18 @@ _systemd_unprefix() {
# ${D}). This function always succeeds, even if systemd is not # ${D}). This function always succeeds, even if systemd is not
# installed. # installed.
systemd_get_systemunitdir() { systemd_get_systemunitdir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemdsystemunitdir /lib/systemd/system _systemd_get_dir systemdsystemunitdir /lib/systemd/system
} }
# @FUNCTION: systemd_get_unitdir
# @DESCRIPTION:
# Deprecated alias for systemd_get_systemunitdir.
systemd_get_unitdir() {
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI 6, use systemd_get_systemunitdir instead"
systemd_get_systemunitdir
}
# @FUNCTION: systemd_get_userunitdir # @FUNCTION: systemd_get_userunitdir
# @DESCRIPTION: # @DESCRIPTION:
# Output the path for the systemd user unit directory (not including # Output the path for the systemd user unit directory (not including
# ${D}). This function always succeeds, even if systemd is not # ${D}). This function always succeeds, even if systemd is not
# installed. # installed.
systemd_get_userunitdir() { systemd_get_userunitdir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemduserunitdir /usr/lib/systemd/user _systemd_get_dir systemduserunitdir /usr/lib/systemd/user
} }
@ -111,7 +97,7 @@ systemd_get_userunitdir() {
# ${D}). This function always succeeds, even if systemd is not # ${D}). This function always succeeds, even if systemd is not
# installed. # installed.
systemd_get_utildir() { systemd_get_utildir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemdutildir /lib/systemd _systemd_get_dir systemdutildir /lib/systemd
} }
@ -121,7 +107,7 @@ systemd_get_utildir() {
# Output the path for the systemd system generator directory (not including # Output the path for the systemd system generator directory (not including
# ${D}). This function always succeeds, even if systemd is not installed. # ${D}). This function always succeeds, even if systemd is not installed.
systemd_get_systemgeneratordir() { systemd_get_systemgeneratordir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemdsystemgeneratordir /lib/systemd/system-generators _systemd_get_dir systemdsystemgeneratordir /lib/systemd/system-generators
} }
@ -131,7 +117,7 @@ systemd_get_systemgeneratordir() {
# Output the path for the systemd system preset directory (not including # Output the path for the systemd system preset directory (not including
# ${D}). This function always succeeds, even if systemd is not installed. # ${D}). This function always succeeds, even if systemd is not installed.
systemd_get_systempresetdir() { systemd_get_systempresetdir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset _systemd_get_dir systemdsystempresetdir /lib/systemd/system-preset
} }
@ -140,7 +126,7 @@ systemd_get_systempresetdir() {
# @DESCRIPTION: # @DESCRIPTION:
# Output the path for the system sleep directory. # Output the path for the system sleep directory.
systemd_get_sleepdir() { systemd_get_sleepdir() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
_systemd_get_dir systemdsleepdir /lib/systemd/system-sleep _systemd_get_dir systemdsleepdir /lib/systemd/system-sleep
} }
@ -149,7 +135,7 @@ systemd_get_sleepdir() {
# @DESCRIPTION: # @DESCRIPTION:
# Install systemd unit(s). Uses doins, thus it is fatal. # Install systemd unit(s). Uses doins, thus it is fatal.
systemd_dounit() { systemd_dounit() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
( (
insopts -m 0644 insopts -m 0644
@ -163,7 +149,7 @@ systemd_dounit() {
# @DESCRIPTION: # @DESCRIPTION:
# Install systemd unit with a new name. Uses newins, thus it is fatal. # Install systemd unit with a new name. Uses newins, thus it is fatal.
systemd_newunit() { systemd_newunit() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
( (
insopts -m 0644 insopts -m 0644
@ -177,7 +163,7 @@ systemd_newunit() {
# @DESCRIPTION: # @DESCRIPTION:
# Install systemd user unit(s). Uses doins, thus it is fatal. # Install systemd user unit(s). Uses doins, thus it is fatal.
systemd_douserunit() { systemd_douserunit() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
( (
insopts -m 0644 insopts -m 0644
@ -192,7 +178,7 @@ systemd_douserunit() {
# Install systemd user unit with a new name. Uses newins, thus it # Install systemd user unit with a new name. Uses newins, thus it
# is fatal. # is fatal.
systemd_newuserunit() { systemd_newuserunit() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
( (
insopts -m 0644 insopts -m 0644
@ -209,7 +195,7 @@ systemd_newuserunit() {
# <conf-file> with the .conf suffix stripped is used # <conf-file> with the .conf suffix stripped is used
# (e.g. foo.service.conf -> foo.service.d/00gentoo.conf). # (e.g. foo.service.conf -> foo.service.d/00gentoo.conf).
systemd_install_serviced() { systemd_install_serviced() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local src=${1} local src=${1}
local service=${2} local service=${2}
@ -247,7 +233,7 @@ systemd_install_serviced() {
# RestartSec=120 # RestartSec=120
# EOF # EOF
systemd_install_dropin() { systemd_install_dropin() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
local basedir local basedir
if [[ $# -ge 1 ]] && [[ $1 == "--user" ]]; then if [[ $# -ge 1 ]] && [[ $1 == "--user" ]]; then
@ -279,7 +265,7 @@ systemd_install_dropin() {
# Enable service in desired target, e.g. install a symlink for it. # Enable service in desired target, e.g. install a symlink for it.
# Uses dosym, thus it is fatal. # Uses dosym, thus it is fatal.
systemd_enable_service() { systemd_enable_service() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
@ -304,7 +290,7 @@ systemd_enable_service() {
# #
# Doc: https://www.freedesktop.org/wiki/Software/systemd/timedated/ # Doc: https://www.freedesktop.org/wiki/Software/systemd/timedated/
systemd_enable_ntpunit() { systemd_enable_ntpunit() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
if [[ ${#} -lt 2 ]]; then if [[ ${#} -lt 2 ]]; then
die "Usage: systemd_enable_ntpunit <NN-name> <service>..." die "Usage: systemd_enable_ntpunit <NN-name> <service>..."
fi fi
@ -339,46 +325,6 @@ systemd_enable_ntpunit() {
return ${ret} return ${ret}
} }
# @FUNCTION: systemd_with_unitdir
# @USAGE: [<configure-option-name>]
# @DESCRIPTION:
# Note: deprecated and banned in EAPI 6. Please use full --with-...=
# parameter for improved ebuild readability.
#
# Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
# scripts. This function always succeeds. Its output may be quoted in order
# to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
# this function.
#
# If upstream does use invalid configure option to handle installing systemd
# units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
# argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
# remember to report a bug upstream as well.
systemd_with_unitdir() {
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-${1:-systemdsystemunitdir}=\"\$(systemd_get_systemunitdir)\" instead"
debug-print-function ${FUNCNAME} "${@}"
local optname=${1:-systemdsystemunitdir}
echo --with-${optname}="$(systemd_get_systemunitdir)"
}
# @FUNCTION: systemd_with_utildir
# @DESCRIPTION:
# Note: deprecated and banned in EAPI 6. Please use full --with-...=
# parameter for improved ebuild readability.
#
# Output '--with-systemdsystemutildir' as used by some packages to install
# systemd helpers. This function always succeeds. Its output may be quoted
# in order to preserve whitespace in paths.
systemd_with_utildir() {
[[ ${EAPI} == 5 ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use --with-systemdutildir=\"\$(systemd_get_utildir)\" instead"
debug-print-function ${FUNCNAME} "${@}"
echo --with-systemdutildir="$(systemd_get_utildir)"
}
# @FUNCTION: systemd_update_catalog # @FUNCTION: systemd_update_catalog
# @DESCRIPTION: # @DESCRIPTION:
# Update the journald catalog. This needs to be called after installing # Update the journald catalog. This needs to be called after installing
@ -389,7 +335,7 @@ systemd_with_utildir() {
# #
# See: https://www.freedesktop.org/wiki/Software/systemd/catalog # See: https://www.freedesktop.org/wiki/Software/systemd/catalog
systemd_update_catalog() { systemd_update_catalog() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ ${EBUILD_PHASE} == post* ]] \ [[ ${EBUILD_PHASE} == post* ]] \
|| die "${FUNCNAME} disallowed during ${EBUILD_PHASE_FUNC:-${EBUILD_PHASE}}" || die "${FUNCNAME} disallowed during ${EBUILD_PHASE_FUNC:-${EBUILD_PHASE}}"
@ -419,7 +365,7 @@ systemd_update_catalog() {
# #
# See: man sd_booted # See: man sd_booted
systemd_is_booted() { systemd_is_booted() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "$@"
[[ -d /run/systemd/system ]] [[ -d /run/systemd/system ]]
local ret=${?} local ret=${?}
@ -448,3 +394,5 @@ systemd_reenable() {
fi fi
done done
} }
fi