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

Diff of /eclass/systemd.eclass

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

Revision 1.13 Revision 1.25
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2013 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.13 2012/08/27 21:54:19 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.25 2013/04/13 22:49:21 floppym Exp $
4 4
5# @ECLASS: systemd.eclass 5# @ECLASS: systemd.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# mgorny@gentoo.org 7# systemd@gentoo.org
8# @BLURB: helper functions to install systemd units 8# @BLURB: helper functions to install systemd units
9# @DESCRIPTION: 9# @DESCRIPTION:
10# This eclass provides a set of functions to install unit files for 10# This eclass provides a set of functions to install unit files for
11# sys-apps/systemd within ebuilds. 11# sys-apps/systemd within ebuilds.
12# @EXAMPLE: 12# @EXAMPLE:
23# systemd_to_myeconfargs 23# systemd_to_myeconfargs
24# autotools-utils_src_configure 24# autotools-utils_src_configure
25# } 25# }
26# @CODE 26# @CODE
27 27
28inherit toolchain-funcs
29
28case ${EAPI:-0} in 30case ${EAPI:-0} in
29 0|1|2|3|4) ;; 31 0|1|2|3|4|5) ;;
30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established." 32 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31esac 33esac
32 34
33# Block systemd version without the migration helper. 35DEPEND="virtual/pkgconfig"
34DEPEND="!<sys-apps/systemd-29-r4
35 !=sys-apps/systemd-37-r1"
36 36
37# @FUNCTION: _systemd_get_unitdir 37# @FUNCTION: _systemd_get_unitdir
38# @INTERNAL 38# @INTERNAL
39# @DESCRIPTION: 39# @DESCRIPTION:
40# Get unprefixed unitdir. 40# Get unprefixed unitdir.
41_systemd_get_unitdir() { 41_systemd_get_unitdir() {
42 if $(tc-getPKG_CONFIG) --exists systemd; then
43 echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
44 else
42 echo -n /usr/lib/systemd/system 45 echo /usr/lib/systemd/system
46 fi
43} 47}
44 48
45# @FUNCTION: systemd_get_unitdir 49# @FUNCTION: systemd_get_unitdir
46# @DESCRIPTION: 50# @DESCRIPTION:
47# Output the path for the systemd unit directory (not including ${D}). 51# Output the path for the systemd unit directory (not including ${D}).
48# This function always succeeds, even if systemd is not installed. 52# This function always succeeds, even if systemd is not installed.
49systemd_get_unitdir() { 53systemd_get_unitdir() {
50 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX= 54 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
51 debug-print-function ${FUNCNAME} "${@}" 55 debug-print-function ${FUNCNAME} "${@}"
52 56
53 echo -n "${EPREFIX}$(_systemd_get_unitdir)" 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.
77systemd_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.
101systemd_get_utildir() {
102 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
103 debug-print-function ${FUNCNAME} "${@}"
104
105 echo "${EPREFIX}$(_systemd_get_utildir)"
54} 106}
55 107
56# @FUNCTION: systemd_dounit 108# @FUNCTION: systemd_dounit
57# @USAGE: unit1 [...] 109# @USAGE: unit1 [...]
58# @DESCRIPTION: 110# @DESCRIPTION:
59# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4 111# Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
60# and non-fatal in earlier EAPIs. 112# and non-fatal in earlier EAPIs.
61systemd_dounit() { 113systemd_dounit() {
62 debug-print-function ${FUNCNAME} "${@}" 114 debug-print-function ${FUNCNAME} "${@}"
63 115
64 ( 116 local INSDESTTREE
65 insinto "$(_systemd_get_unitdir)" 117 insinto "$(_systemd_get_unitdir)"
66 doins "${@}" 118 doins "${@}"
67 )
68} 119}
69 120
70# @FUNCTION: systemd_newunit 121# @FUNCTION: systemd_newunit
71# @USAGE: oldname newname 122# @USAGE: oldname newname
72# @DESCRIPTION: 123# @DESCRIPTION:
73# Install systemd unit with a new name. Uses newins, thus it is fatal 124# Install systemd unit with a new name. Uses newins, thus it is fatal
74# in EAPI 4 and non-fatal in earlier EAPIs. 125# in EAPI 4 and non-fatal in earlier EAPIs.
75systemd_newunit() { 126systemd_newunit() {
76 debug-print-function ${FUNCNAME} "${@}" 127 debug-print-function ${FUNCNAME} "${@}"
77 128
78 ( 129 local INSDESTTREE
79 insinto "$(_systemd_get_unitdir)" 130 insinto "$(_systemd_get_unitdir)"
80 newins "${@}" 131 newins "${@}"
81 )
82} 132}
83 133
84# @FUNCTION: systemd_dotmpfilesd 134# @FUNCTION: systemd_dotmpfilesd
85# @USAGE: tmpfilesd1 [...] 135# @USAGE: tmpfilesd1 [...]
86# @DESCRIPTION: 136# @DESCRIPTION:
92 for f; do 142 for f; do
93 [[ ${f} == *.conf ]] \ 143 [[ ${f} == *.conf ]] \
94 || die 'tmpfiles.d files need to have .conf suffix.' 144 || die 'tmpfiles.d files need to have .conf suffix.'
95 done 145 done
96 146
97 ( 147 local INSDESTTREE
98 insinto /usr/lib/tmpfiles.d/ 148 insinto /usr/lib/tmpfiles.d/
99 doins "${@}" 149 doins "${@}"
100 )
101} 150}
102 151
103# @FUNCTION: systemd_newtmpfilesd 152# @FUNCTION: systemd_newtmpfilesd
104# @USAGE: oldname newname.conf 153# @USAGE: oldname newname.conf
105# @DESCRIPTION: 154# @DESCRIPTION:
109 debug-print-function ${FUNCNAME} "${@}" 158 debug-print-function ${FUNCNAME} "${@}"
110 159
111 [[ ${2} == *.conf ]] \ 160 [[ ${2} == *.conf ]] \
112 || die 'tmpfiles.d files need to have .conf suffix.' 161 || die 'tmpfiles.d files need to have .conf suffix.'
113 162
114 ( 163 local INSDESTTREE
115 insinto /usr/lib/tmpfiles.d/ 164 insinto /usr/lib/tmpfiles.d/
116 newins "${@}" 165 newins "${@}"
117 )
118} 166}
119 167
120# @FUNCTION: systemd_enable_service 168# @FUNCTION: systemd_enable_service
121# @USAGE: target service 169# @USAGE: target service
122# @DESCRIPTION: 170# @DESCRIPTION:
129 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" 177 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
130 178
131 local target=${1} 179 local target=${1}
132 local service=${2} 180 local service=${2}
133 local ud=$(_systemd_get_unitdir) 181 local ud=$(_systemd_get_unitdir)
134 local destname=$(basename "${service}") 182 local destname=${service##*/}
135 183
136 dodir "${ud}"/"${target}".wants && \ 184 dodir "${ud}"/"${target}".wants && \
137 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}" 185 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
138} 186}
139 187
151# remember to report a bug upstream as well. 199# remember to report a bug upstream as well.
152systemd_with_unitdir() { 200systemd_with_unitdir() {
153 debug-print-function ${FUNCNAME} "${@}" 201 debug-print-function ${FUNCNAME} "${@}"
154 local optname=${1:-systemdsystemunitdir} 202 local optname=${1:-systemdsystemunitdir}
155 203
156 echo -n --with-${optname}="$(systemd_get_unitdir)" 204 echo --with-${optname}="$(systemd_get_unitdir)"
205}
206
207# @FUNCTION: systemd_with_utildir
208# @DESCRIPTION:
209# Output '--with-systemdsystemutildir' as used by some packages to install
210# systemd helpers. This function always succeeds. Its output may be quoted
211# in order to preserve whitespace in paths.
212systemd_with_utildir() {
213 debug-print-function ${FUNCNAME} "${@}"
214
215 echo --with-systemdutildir="$(systemd_get_utildir)"
157} 216}
158 217
159# @FUNCTION: systemd_to_myeconfargs 218# @FUNCTION: systemd_to_myeconfargs
160# @DESCRIPTION: 219# @DESCRIPTION:
161# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure 220# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
167 myeconfargs=( 226 myeconfargs=(
168 "${myeconfargs[@]}" 227 "${myeconfargs[@]}"
169 --with-systemdsystemunitdir="$(systemd_get_unitdir)" 228 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
170 ) 229 )
171} 230}
231
232# @FUNCTION: systemd_update_catalog
233# @DESCRIPTION:
234# Update the journald catalog. This needs to be called after installing
235# or removing catalog files.
236#
237# If systemd is not installed, no operation will be done. The catalog
238# will be (re)built once systemd is installed.
239#
240# See: http://www.freedesktop.org/wiki/Software/systemd/catalog
241systemd_update_catalog() {
242 debug-print-function ${FUNCNAME} "${@}"
243
244 # Make sure to work on the correct system.
245
246 local journalctl=${EPREFIX}/usr/bin/journalctl
247 if [[ -x ${journalctl} ]]; then
248 ebegin "Updating systemd journal catalogs"
249 journalctl --update-catalog
250 eend $?
251 else
252 debug-print "${FUNCNAME}: journalctl not found."
253 fi
254}

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20