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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (hide annotations) (download)
Wed Sep 11 07:58:00 2013 UTC (10 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.26: +17 -13 lines
Use subshells instead of "local INSDESTTREE" for doins/newins since that confuses people less.

1 mgorny 1.22 # Copyright 1999-2013 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.27 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.26 2013/07/27 10:36:55 mgorny Exp $
4 mgorny 1.1
5     # @ECLASS: systemd.eclass
6     # @MAINTAINER:
7 mgorny 1.22 # systemd@gentoo.org
8 mgorny 1.1 # @BLURB: helper functions to install systemd units
9     # @DESCRIPTION:
10     # This eclass provides a set of functions to install unit files for
11     # sys-apps/systemd within ebuilds.
12     # @EXAMPLE:
13     #
14     # @CODE
15     # inherit autotools-utils systemd
16 vapier 1.8 #
17 mgorny 1.1 # src_configure() {
18     # local myeconfargs=(
19     # --enable-foo
20     # --disable-bar
21     # )
22     #
23     # systemd_to_myeconfargs
24     # autotools-utils_src_configure
25     # }
26     # @CODE
27    
28 mgorny 1.23 inherit toolchain-funcs
29    
30 mgorny 1.1 case ${EAPI:-0} in
31 axs 1.15 0|1|2|3|4|5) ;;
32 mgorny 1.1 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
33     esac
34    
35 mgorny 1.23 DEPEND="virtual/pkgconfig"
36    
37 mgorny 1.9 # @FUNCTION: _systemd_get_unitdir
38     # @INTERNAL
39     # @DESCRIPTION:
40     # Get unprefixed unitdir.
41     _systemd_get_unitdir() {
42 mgorny 1.23 if $(tc-getPKG_CONFIG) --exists systemd; then
43     echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
44     else
45     echo /usr/lib/systemd/system
46     fi
47 mgorny 1.9 }
48    
49 mgorny 1.1 # @FUNCTION: systemd_get_unitdir
50     # @DESCRIPTION:
51     # Output the path for the systemd unit directory (not including ${D}).
52     # This function always succeeds, even if systemd is not installed.
53     systemd_get_unitdir() {
54 darkside 1.6 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
55 mgorny 1.1 debug-print-function ${FUNCNAME} "${@}"
56    
57 mgorny 1.16 echo "${EPREFIX}$(_systemd_get_unitdir)"
58 mgorny 1.1 }
59    
60 mgorny 1.23 # @FUNCTION: _systemd_get_userunitdir
61     # @INTERNAL
62     # @DESCRIPTION:
63     # Get unprefixed userunitdir.
64     _systemd_get_userunitdir() {
65 mgorny 1.24 if $(tc-getPKG_CONFIG) --exists systemd; then
66 mgorny 1.23 echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
67     else
68     echo /usr/lib/systemd/user
69     fi
70     }
71    
72 mgorny 1.21 # @FUNCTION: systemd_get_userunitdir
73     # @DESCRIPTION:
74     # Output the path for the systemd user unit directory (not including
75     # ${D}). This function always succeeds, even if systemd is not
76     # installed.
77     systemd_get_userunitdir() {
78     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
79     debug-print-function ${FUNCNAME} "${@}"
80    
81 mgorny 1.23 echo "${EPREFIX}$(_systemd_get_userunitdir)"
82     }
83    
84     # @FUNCTION: _systemd_get_utildir
85     # @INTERNAL
86     # @DESCRIPTION:
87     # Get unprefixed utildir.
88     _systemd_get_utildir() {
89 mgorny 1.24 if $(tc-getPKG_CONFIG) --exists systemd; then
90 mgorny 1.23 echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
91     else
92     echo /usr/lib/systemd
93     fi
94 mgorny 1.21 }
95    
96 mgorny 1.17 # @FUNCTION: systemd_get_utildir
97     # @DESCRIPTION:
98     # Output the path for the systemd utility directory (not including
99     # ${D}). This function always succeeds, even if systemd is not
100     # installed.
101     systemd_get_utildir() {
102     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
103     debug-print-function ${FUNCNAME} "${@}"
104    
105 mgorny 1.23 echo "${EPREFIX}$(_systemd_get_utildir)"
106 mgorny 1.17 }
107    
108 mgorny 1.1 # @FUNCTION: systemd_dounit
109     # @USAGE: unit1 [...]
110     # @DESCRIPTION:
111     # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
112     # and non-fatal in earlier EAPIs.
113     systemd_dounit() {
114     debug-print-function ${FUNCNAME} "${@}"
115    
116 mgorny 1.27 (
117     insinto "$(_systemd_get_unitdir)"
118     doins "${@}"
119     )
120 mgorny 1.1 }
121    
122 mgorny 1.5 # @FUNCTION: systemd_newunit
123     # @USAGE: oldname newname
124     # @DESCRIPTION:
125     # Install systemd unit with a new name. Uses newins, thus it is fatal
126     # in EAPI 4 and non-fatal in earlier EAPIs.
127     systemd_newunit() {
128     debug-print-function ${FUNCNAME} "${@}"
129    
130 mgorny 1.27 (
131     insinto "$(_systemd_get_unitdir)"
132     newins "${@}"
133     )
134 mgorny 1.5 }
135    
136 mgorny 1.3 # @FUNCTION: systemd_dotmpfilesd
137     # @USAGE: tmpfilesd1 [...]
138     # @DESCRIPTION:
139     # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
140     # in EAPI 4 and non-fatal in earlier EAPIs.
141     systemd_dotmpfilesd() {
142     debug-print-function ${FUNCNAME} "${@}"
143    
144 mgorny 1.13 for f; do
145     [[ ${f} == *.conf ]] \
146     || die 'tmpfiles.d files need to have .conf suffix.'
147     done
148    
149 mgorny 1.27 (
150     insinto /usr/lib/tmpfiles.d/
151     doins "${@}"
152     )
153 mgorny 1.3 }
154    
155 mgorny 1.12 # @FUNCTION: systemd_newtmpfilesd
156     # @USAGE: oldname newname.conf
157     # @DESCRIPTION:
158     # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
159     # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
160     systemd_newtmpfilesd() {
161     debug-print-function ${FUNCNAME} "${@}"
162    
163 mgorny 1.13 [[ ${2} == *.conf ]] \
164     || die 'tmpfiles.d files need to have .conf suffix.'
165    
166 mgorny 1.27 (
167     insinto /usr/lib/tmpfiles.d/
168     newins "${@}"
169     )
170 mgorny 1.12 }
171    
172 mgorny 1.1 # @FUNCTION: systemd_enable_service
173     # @USAGE: target service
174     # @DESCRIPTION:
175     # Enable service in desired target, e.g. install a symlink for it.
176     # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
177     # EAPIs.
178     systemd_enable_service() {
179     debug-print-function ${FUNCNAME} "${@}"
180    
181     [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
182    
183     local target=${1}
184     local service=${2}
185 mgorny 1.9 local ud=$(_systemd_get_unitdir)
186 floppym 1.25 local destname=${service##*/}
187 mgorny 1.1
188     dodir "${ud}"/"${target}".wants && \
189 mgorny 1.10 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
190 mgorny 1.1 }
191    
192     # @FUNCTION: systemd_with_unitdir
193 mgorny 1.4 # @USAGE: [configure option]
194 mgorny 1.1 # @DESCRIPTION:
195     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
196     # scripts. This function always succeeds. Its output may be quoted in order
197     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
198     # this function.
199 mgorny 1.4 #
200     # If upstream does use invalid configure option to handle installing systemd
201     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
202     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
203     # remember to report a bug upstream as well.
204 mgorny 1.1 systemd_with_unitdir() {
205     debug-print-function ${FUNCNAME} "${@}"
206 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
207 mgorny 1.1
208 mgorny 1.16 echo --with-${optname}="$(systemd_get_unitdir)"
209 mgorny 1.1 }
210    
211 mgorny 1.18 # @FUNCTION: systemd_with_utildir
212     # @DESCRIPTION:
213     # Output '--with-systemdsystemutildir' as used by some packages to install
214     # systemd helpers. This function always succeeds. Its output may be quoted
215     # in order to preserve whitespace in paths.
216     systemd_with_utildir() {
217     debug-print-function ${FUNCNAME} "${@}"
218    
219     echo --with-systemdutildir="$(systemd_get_utildir)"
220     }
221    
222 mgorny 1.1 # @FUNCTION: systemd_to_myeconfargs
223     # @DESCRIPTION:
224     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
225     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
226     # quoting automatically.
227     systemd_to_myeconfargs() {
228     debug-print-function ${FUNCNAME} "${@}"
229    
230     myeconfargs=(
231     "${myeconfargs[@]}"
232     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
233     )
234     }
235 mgorny 1.20
236     # @FUNCTION: systemd_update_catalog
237     # @DESCRIPTION:
238     # Update the journald catalog. This needs to be called after installing
239     # or removing catalog files.
240     #
241     # If systemd is not installed, no operation will be done. The catalog
242     # will be (re)built once systemd is installed.
243     #
244     # See: http://www.freedesktop.org/wiki/Software/systemd/catalog
245     systemd_update_catalog() {
246     debug-print-function ${FUNCNAME} "${@}"
247    
248     # Make sure to work on the correct system.
249 mgorny 1.23
250 mgorny 1.20 local journalctl=${EPREFIX}/usr/bin/journalctl
251     if [[ -x ${journalctl} ]]; then
252     ebegin "Updating systemd journal catalogs"
253     journalctl --update-catalog
254     eend $?
255     else
256     debug-print "${FUNCNAME}: journalctl not found."
257     fi
258     }
259 mgorny 1.26
260     # @FUNCTION: systemd_is_booted
261     # @DESCRIPTION:
262     # Check whether the system was booted using systemd.
263     #
264     # This should be used purely for informational purposes, e.g. warning
265     # user that he needs to use systemd. Installed files or application
266     # behavior *must not* rely on this. Please remember to check MERGE_TYPE
267     # to not trigger the check on binary package build hosts!
268     #
269     # Returns 0 if systemd is used to boot the system, 1 otherwise.
270     #
271     # See: man sd_booted
272     systemd_is_booted() {
273     debug-print-function ${FUNCNAME} "${@}"
274    
275     [[ -d /run/systemd/system ]]
276     local ret=${?}
277    
278     debug-print "${FUNCNAME}: [[ -d /run/systemd/system ]] -> ${ret}"
279     return ${ret}
280     }

  ViewVC Help
Powered by ViewVC 1.1.20