/[gentoo-x86]/eclass/systemd.eclass
Gentoo

Diff of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.21
1# Copyright 1999-2011 Gentoo Foundation 1# Copyright 1999-2012 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.2 2011/05/04 16:02:10 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.21 2012/12/31 13:09:09 mgorny Exp $
4 4
5# @ECLASS: systemd.eclass 5# @ECLASS: systemd.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# mgorny@gentoo.org 7# mgorny@gentoo.org
8# @BLURB: helper functions to install systemd units 8# @BLURB: helper functions to install systemd units
11# sys-apps/systemd within ebuilds. 11# sys-apps/systemd within ebuilds.
12# @EXAMPLE: 12# @EXAMPLE:
13# 13#
14# @CODE 14# @CODE
15# inherit autotools-utils systemd 15# inherit autotools-utils systemd
16# 16#
17# src_configure() { 17# src_configure() {
18# local myeconfargs=( 18# local myeconfargs=(
19# --enable-foo 19# --enable-foo
20# --disable-bar 20# --disable-bar
21# ) 21# )
24# autotools-utils_src_configure 24# autotools-utils_src_configure
25# } 25# }
26# @CODE 26# @CODE
27 27
28case ${EAPI:-0} in 28case ${EAPI:-0} in
29 0|1|2|3|4) ;; 29 0|1|2|3|4|5) ;;
30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established." 30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31esac 31esac
32
33# @FUNCTION: _systemd_get_unitdir
34# @INTERNAL
35# @DESCRIPTION:
36# Get unprefixed unitdir.
37_systemd_get_unitdir() {
38 echo /usr/lib/systemd/system
39}
32 40
33# @FUNCTION: systemd_get_unitdir 41# @FUNCTION: systemd_get_unitdir
34# @DESCRIPTION: 42# @DESCRIPTION:
35# Output the path for the systemd unit directory (not including ${D}). 43# Output the path for the systemd unit directory (not including ${D}).
36# This function always succeeds, even if systemd is not installed. 44# This function always succeeds, even if systemd is not installed.
37systemd_get_unitdir() { 45systemd_get_unitdir() {
46 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
38 debug-print-function ${FUNCNAME} "${@}" 47 debug-print-function ${FUNCNAME} "${@}"
39 48
40 echo -n /lib/systemd/system 49 echo "${EPREFIX}$(_systemd_get_unitdir)"
50}
51
52# @FUNCTION: systemd_get_userunitdir
53# @DESCRIPTION:
54# Output the path for the systemd user unit directory (not including
55# ${D}). This function always succeeds, even if systemd is not
56# installed.
57systemd_get_userunitdir() {
58 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
59 debug-print-function ${FUNCNAME} "${@}"
60
61 echo "${EPREFIX}/usr/lib/systemd/user"
62}
63
64# @FUNCTION: systemd_get_utildir
65# @DESCRIPTION:
66# Output the path for the systemd utility directory (not including
67# ${D}). This function always succeeds, even if systemd is not
68# installed.
69systemd_get_utildir() {
70 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
71 debug-print-function ${FUNCNAME} "${@}"
72
73 echo "${EPREFIX}/usr/lib/systemd"
41} 74}
42 75
43# @FUNCTION: systemd_dounit 76# @FUNCTION: systemd_dounit
44# @USAGE: unit1 [...] 77# @USAGE: unit1 [...]
45# @DESCRIPTION: 78# @DESCRIPTION:
46# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4 79# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
47# and non-fatal in earlier EAPIs. 80# and non-fatal in earlier EAPIs.
48systemd_dounit() { 81systemd_dounit() {
49 debug-print-function ${FUNCNAME} "${@}" 82 debug-print-function ${FUNCNAME} "${@}"
50 83
51 ( 84 local INSDESTTREE
52 insinto "$(systemd_get_unitdir)" 85 insinto "$(_systemd_get_unitdir)"
53 doins "${@}" 86 doins "${@}"
54 ) 87}
88
89# @FUNCTION: systemd_newunit
90# @USAGE: oldname newname
91# @DESCRIPTION:
92# Install systemd unit with a new name. Uses newins, thus it is fatal
93# in EAPI 4 and non-fatal in earlier EAPIs.
94systemd_newunit() {
95 debug-print-function ${FUNCNAME} "${@}"
96
97 local INSDESTTREE
98 insinto "$(_systemd_get_unitdir)"
99 newins "${@}"
100}
101
102# @FUNCTION: systemd_dotmpfilesd
103# @USAGE: tmpfilesd1 [...]
104# @DESCRIPTION:
105# Install systemd tmpfiles.d files. Uses doins, thus it is fatal
106# in EAPI 4 and non-fatal in earlier EAPIs.
107systemd_dotmpfilesd() {
108 debug-print-function ${FUNCNAME} "${@}"
109
110 for f; do
111 [[ ${f} == *.conf ]] \
112 || die 'tmpfiles.d files need to have .conf suffix.'
113 done
114
115 local INSDESTTREE
116 insinto /usr/lib/tmpfiles.d/
117 doins "${@}"
118}
119
120# @FUNCTION: systemd_newtmpfilesd
121# @USAGE: oldname newname.conf
122# @DESCRIPTION:
123# Install systemd tmpfiles.d file under a new name. Uses newins, thus it
124# is fatal in EAPI 4 and non-fatal in earlier EAPIs.
125systemd_newtmpfilesd() {
126 debug-print-function ${FUNCNAME} "${@}"
127
128 [[ ${2} == *.conf ]] \
129 || die 'tmpfiles.d files need to have .conf suffix.'
130
131 local INSDESTTREE
132 insinto /usr/lib/tmpfiles.d/
133 newins "${@}"
55} 134}
56 135
57# @FUNCTION: systemd_enable_service 136# @FUNCTION: systemd_enable_service
58# @USAGE: target service 137# @USAGE: target service
59# @DESCRIPTION: 138# @DESCRIPTION:
65 144
66 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" 145 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
67 146
68 local target=${1} 147 local target=${1}
69 local service=${2} 148 local service=${2}
70 local ud=$(systemd_get_unitdir) 149 local ud=$(_systemd_get_unitdir)
150 local destname=$(basename "${service}")
71 151
72 dodir "${ud}"/"${target}".wants && \ 152 dodir "${ud}"/"${target}".wants && \
73 dosym ../"${service}" "${ud}"/"${target}".wants 153 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
74} 154}
75 155
76# @FUNCTION: systemd_with_unitdir 156# @FUNCTION: systemd_with_unitdir
157# @USAGE: [configure option]
77# @DESCRIPTION: 158# @DESCRIPTION:
78# Output '--with-systemdsystemunitdir' as expected by systemd-aware configure 159# Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
79# scripts. This function always succeeds. Its output may be quoted in order 160# scripts. This function always succeeds. Its output may be quoted in order
80# to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over 161# to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
81# this function. 162# this function.
163#
164# If upstream does use invalid configure option to handle installing systemd
165# units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
166# argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
167# remember to report a bug upstream as well.
82systemd_with_unitdir() { 168systemd_with_unitdir() {
83 debug-print-function ${FUNCNAME} "${@}" 169 debug-print-function ${FUNCNAME} "${@}"
170 local optname=${1:-systemdsystemunitdir}
84 171
172 echo --with-${optname}="$(systemd_get_unitdir)"
173}
174
175# @FUNCTION: systemd_with_utildir
176# @DESCRIPTION:
177# Output '--with-systemdsystemutildir' as used by some packages to install
178# systemd helpers. This function always succeeds. Its output may be quoted
179# in order to preserve whitespace in paths.
180systemd_with_utildir() {
181 debug-print-function ${FUNCNAME} "${@}"
182
85 echo -n --with-systemdsystemunitdir="$(systemd_get_unitdir)" 183 echo --with-systemdutildir="$(systemd_get_utildir)"
86} 184}
87 185
88# @FUNCTION: systemd_to_myeconfargs 186# @FUNCTION: systemd_to_myeconfargs
89# @DESCRIPTION: 187# @DESCRIPTION:
90# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure 188# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
96 myeconfargs=( 194 myeconfargs=(
97 "${myeconfargs[@]}" 195 "${myeconfargs[@]}"
98 --with-systemdsystemunitdir="$(systemd_get_unitdir)" 196 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
99 ) 197 )
100} 198}
199
200# @FUNCTION: systemd_update_catalog
201# @DESCRIPTION:
202# Update the journald catalog. This needs to be called after installing
203# or removing catalog files.
204#
205# If systemd is not installed, no operation will be done. The catalog
206# will be (re)built once systemd is installed.
207#
208# See: http://www.freedesktop.org/wiki/Software/systemd/catalog
209systemd_update_catalog() {
210 debug-print-function ${FUNCNAME} "${@}"
211
212 # Make sure to work on the correct system.
213 local journalctl=${EPREFIX}/usr/bin/journalctl
214 if [[ -x ${journalctl} ]]; then
215 ebegin "Updating systemd journal catalogs"
216 journalctl --update-catalog
217 eend $?
218 else
219 debug-print "${FUNCNAME}: journalctl not found."
220 fi
221}

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.20