diff options
author | Michał Górny <mgorny@gentoo.org> | 2011-05-04 10:53:35 +0000 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2011-05-04 10:53:35 +0000 |
commit | aedcdcecbc91c6fd42b0e2a6f918981a7ceb8e33 (patch) | |
tree | ef93b792034fbe6e11aa48e55e7378e0b43b39f2 /eclass/systemd.eclass | |
parent | Version bump. (diff) | |
download | historical-aedcdcecbc91c6fd42b0e2a6f918981a7ceb8e33.tar.gz historical-aedcdcecbc91c6fd42b0e2a6f918981a7ceb8e33.tar.bz2 historical-aedcdcecbc91c6fd42b0e2a6f918981a7ceb8e33.zip |
Introducing systemd.eclass - a helper eclass to handle systemd unit installation.
Diffstat (limited to 'eclass/systemd.eclass')
-rw-r--r-- | eclass/systemd.eclass | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass new file mode 100644 index 000000000000..386686395731 --- /dev/null +++ b/eclass/systemd.eclass @@ -0,0 +1,102 @@ +# Copyright 1999-2011 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.1 2011/05/04 10:53:35 mgorny Exp $ + +# @ECLASS: systemd.eclass +# @MAINTAINER: +# mgorny@gentoo.org +# @BLURB: helper functions to install systemd units +# @DESCRIPTION: +# This eclass provides a set of functions to install unit files for +# sys-apps/systemd within ebuilds. +# @EXAMPLE: +# +# @CODE +# inherit autotools-utils systemd +# +# src_configure() { +# local myeconfargs=( +# --enable-foo +# --disable-bar +# ) +# +# systemd_to_myeconfargs +# autotools-utils_src_configure +# } +# @CODE + +inherit multilib + +case ${EAPI:-0} in + 0|1|2|3|4) ;; + *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established." +esac + +# @FUNCTION: systemd_get_unitdir +# @DESCRIPTION: +# Output the path for the systemd unit directory (not including ${D}). +# This function always succeeds, even if systemd is not installed. +systemd_get_unitdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo -n /lib/systemd/system +} + +# @FUNCTION: systemd_dounit +# @USAGE: unit1 [...] +# @DESCRIPTION: +# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4 +# and non-fatal in earlier EAPIs. +systemd_dounit() { + debug-print-function ${FUNCNAME} "${@}" + + ( + insinto "$(systemd_get_unitdir)" + doins "${@}" + ) +} + +# @FUNCTION: systemd_enable_service +# @USAGE: target service +# @DESCRIPTION: +# Enable service in desired target, e.g. install a symlink for it. +# Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier +# EAPIs. +systemd_enable_service() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" + + local target=${1} + local service=${2} + local ud=$(systemd_get_unitdir) + + dodir "${ud}"/"${target}".wants && \ + dosym ../"${service}" "${ud}"/"${target}".wants +} + +# @FUNCTION: systemd_with_unitdir +# @DESCRIPTION: +# 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. +systemd_with_unitdir() { + debug-print-function ${FUNCNAME} "${@}" + + echo -n --with-systemdsystemunitdir="$(systemd_get_unitdir)" +} + +# @FUNCTION: systemd_to_myeconfargs +# @DESCRIPTION: +# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure +# scripts to the myeconfargs variable used by autotools-utils eclass. Handles +# quoting automatically. +systemd_to_myeconfargs() { + debug-print-function ${FUNCNAME} "${@}" + + myeconfargs=( + "${myeconfargs[@]}" + --with-systemdsystemunitdir="$(systemd_get_unitdir)" + ) +} |