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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (show annotations) (download)
Thu Sep 12 11:46:41 2013 UTC (10 months ago) by mgorny
Branch: MAIN
Changes since 1.29: +30 -1 lines
Introduce systemd_install_serviced() to install foo.service.d/00gentoo.conf files.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.29 2013/09/11 08:53:18 mgorny Exp $
4
5 # @ECLASS: systemd.eclass
6 # @MAINTAINER:
7 # systemd@gentoo.org
8 # @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 systemd
16 #
17 # src_configure() {
18 # local myeconfargs=(
19 # --enable-foo
20 # --disable-bar
21 # "$(systemd_with_unitdir)"
22 # )
23 #
24 # econf "${myeconfargs[@]}"
25 # }
26 # @CODE
27
28 inherit eutils toolchain-funcs
29
30 case ${EAPI:-0} in
31 0|1|2|3|4|5) ;;
32 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
33 esac
34
35 DEPEND="virtual/pkgconfig"
36
37 # @FUNCTION: _systemd_get_unitdir
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Get unprefixed unitdir.
41 _systemd_get_unitdir() {
42 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 }
48
49 # @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 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
55 debug-print-function ${FUNCNAME} "${@}"
56
57 echo "${EPREFIX}$(_systemd_get_unitdir)"
58 }
59
60 # @FUNCTION: _systemd_get_userunitdir
61 # @INTERNAL
62 # @DESCRIPTION:
63 # Get unprefixed userunitdir.
64 _systemd_get_userunitdir() {
65 if $(tc-getPKG_CONFIG) --exists systemd; then
66 echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
67 else
68 echo /usr/lib/systemd/user
69 fi
70 }
71
72 # @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 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 if $(tc-getPKG_CONFIG) --exists systemd; then
90 echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
91 else
92 echo /usr/lib/systemd
93 fi
94 }
95
96 # @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 echo "${EPREFIX}$(_systemd_get_utildir)"
106 }
107
108 # @FUNCTION: systemd_dounit
109 # @USAGE: <unit>...
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 (
117 insinto "$(_systemd_get_unitdir)"
118 doins "${@}"
119 )
120 }
121
122 # @FUNCTION: systemd_newunit
123 # @USAGE: <old-name> <new-name>
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 (
131 insinto "$(_systemd_get_unitdir)"
132 newins "${@}"
133 )
134 }
135
136 # @FUNCTION: systemd_install_serviced
137 # @USAGE: <conf-file> [<service.d>]
138 # @DESCRIPTION:
139 # Install the file <conf-file> as service.d/00gentoo.conf template.
140 # The <service.d> argument specifies the configured service name.
141 # If not specified, the configuration file name will be used with .conf
142 # suffix stripped (e.g. foo.service.conf -> foo.service).
143 systemd_install_serviced() {
144 debug-print-function ${FUNCNAME} "${@}"
145
146 local src=${1}
147 local service=${2}
148
149 [[ ${src} ]] || die "No file specified"
150
151 if [[ ! ${service} ]]; then
152 [[ ${src} == *.conf ]] || die "Source file needs .conf suffix"
153 service=${src##*/}
154 service=${service%.conf}
155 fi
156 # avoid potentially common mistake
157 [[ ${service} == *.d ]] && die "Service must not have .d suffix"
158
159 (
160 insinto /etc/systemd/system/"${service}".d
161 newins "${src}" 00gentoo.conf
162 )
163 }
164
165 # @FUNCTION: systemd_dotmpfilesd
166 # @USAGE: <tmpfilesd>...
167 # @DESCRIPTION:
168 # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
169 # in EAPI 4 and non-fatal in earlier EAPIs.
170 systemd_dotmpfilesd() {
171 debug-print-function ${FUNCNAME} "${@}"
172
173 for f; do
174 [[ ${f} == *.conf ]] \
175 || die 'tmpfiles.d files need to have .conf suffix.'
176 done
177
178 (
179 insinto /usr/lib/tmpfiles.d/
180 doins "${@}"
181 )
182 }
183
184 # @FUNCTION: systemd_newtmpfilesd
185 # @USAGE: <old-name> <new-name>.conf
186 # @DESCRIPTION:
187 # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
188 # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
189 systemd_newtmpfilesd() {
190 debug-print-function ${FUNCNAME} "${@}"
191
192 [[ ${2} == *.conf ]] \
193 || die 'tmpfiles.d files need to have .conf suffix.'
194
195 (
196 insinto /usr/lib/tmpfiles.d/
197 newins "${@}"
198 )
199 }
200
201 # @FUNCTION: systemd_enable_service
202 # @USAGE: <target> <service>
203 # @DESCRIPTION:
204 # Enable service in desired target, e.g. install a symlink for it.
205 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
206 # EAPIs.
207 systemd_enable_service() {
208 debug-print-function ${FUNCNAME} "${@}"
209
210 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
211
212 local target=${1}
213 local service=${2}
214 local ud=$(_systemd_get_unitdir)
215 local destname=${service##*/}
216
217 dodir "${ud}"/"${target}".wants && \
218 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
219 }
220
221 # @FUNCTION: systemd_with_unitdir
222 # @USAGE: [<configure-option-name>]
223 # @DESCRIPTION:
224 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
225 # scripts. This function always succeeds. Its output may be quoted in order
226 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
227 # this function.
228 #
229 # If upstream does use invalid configure option to handle installing systemd
230 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
231 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
232 # remember to report a bug upstream as well.
233 systemd_with_unitdir() {
234 debug-print-function ${FUNCNAME} "${@}"
235 local optname=${1:-systemdsystemunitdir}
236
237 echo --with-${optname}="$(systemd_get_unitdir)"
238 }
239
240 # @FUNCTION: systemd_with_utildir
241 # @DESCRIPTION:
242 # Output '--with-systemdsystemutildir' as used by some packages to install
243 # systemd helpers. This function always succeeds. Its output may be quoted
244 # in order to preserve whitespace in paths.
245 systemd_with_utildir() {
246 debug-print-function ${FUNCNAME} "${@}"
247
248 echo --with-systemdutildir="$(systemd_get_utildir)"
249 }
250
251 # @FUNCTION: systemd_to_myeconfargs
252 # @DESCRIPTION:
253 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
254 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
255 # quoting automatically.
256 systemd_to_myeconfargs() {
257 debug-print-function ${FUNCNAME} "${@}"
258
259 eqawarn 'systemd_to_myeconfargs() is deprecated and will be removed on 2013-10-11.'
260 eqawarn 'Please use $(systemd_with_unitdir) instead.'
261
262 myeconfargs=(
263 "${myeconfargs[@]}"
264 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
265 )
266 }
267
268 # @FUNCTION: systemd_update_catalog
269 # @DESCRIPTION:
270 # Update the journald catalog. This needs to be called after installing
271 # or removing catalog files.
272 #
273 # If systemd is not installed, no operation will be done. The catalog
274 # will be (re)built once systemd is installed.
275 #
276 # See: http://www.freedesktop.org/wiki/Software/systemd/catalog
277 systemd_update_catalog() {
278 debug-print-function ${FUNCNAME} "${@}"
279
280 # Make sure to work on the correct system.
281
282 local journalctl=${EPREFIX}/usr/bin/journalctl
283 if [[ -x ${journalctl} ]]; then
284 ebegin "Updating systemd journal catalogs"
285 journalctl --update-catalog
286 eend $?
287 else
288 debug-print "${FUNCNAME}: journalctl not found."
289 fi
290 }
291
292 # @FUNCTION: systemd_is_booted
293 # @DESCRIPTION:
294 # Check whether the system was booted using systemd.
295 #
296 # This should be used purely for informational purposes, e.g. warning
297 # user that he needs to use systemd. Installed files or application
298 # behavior *must not* rely on this. Please remember to check MERGE_TYPE
299 # to not trigger the check on binary package build hosts!
300 #
301 # Returns 0 if systemd is used to boot the system, 1 otherwise.
302 #
303 # See: man sd_booted
304 systemd_is_booted() {
305 debug-print-function ${FUNCNAME} "${@}"
306
307 [[ -d /run/systemd/system ]]
308 local ret=${?}
309
310 debug-print "${FUNCNAME}: [[ -d /run/systemd/system ]] -> ${ret}"
311 return ${ret}
312 }

  ViewVC Help
Powered by ViewVC 1.1.20