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

Diff of /eclass/systemd.eclass

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

Revision 1.16 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.16 2012/10/30 20:24:09 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|5) ;; 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
35DEPEND="virtual/pkgconfig"
36
33# @FUNCTION: _systemd_get_unitdir 37# @FUNCTION: _systemd_get_unitdir
34# @INTERNAL 38# @INTERNAL
35# @DESCRIPTION: 39# @DESCRIPTION:
36# Get unprefixed unitdir. 40# Get unprefixed unitdir.
37_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
38 echo /usr/lib/systemd/system 45 echo /usr/lib/systemd/system
46 fi
39} 47}
40 48
41# @FUNCTION: systemd_get_unitdir 49# @FUNCTION: systemd_get_unitdir
42# @DESCRIPTION: 50# @DESCRIPTION:
43# Output the path for the systemd unit directory (not including ${D}). 51# Output the path for the systemd unit directory (not including ${D}).
47 debug-print-function ${FUNCNAME} "${@}" 55 debug-print-function ${FUNCNAME} "${@}"
48 56
49 echo "${EPREFIX}$(_systemd_get_unitdir)" 57 echo "${EPREFIX}$(_systemd_get_unitdir)"
50} 58}
51 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)"
106}
107
52# @FUNCTION: systemd_dounit 108# @FUNCTION: systemd_dounit
53# @USAGE: unit1 [...] 109# @USAGE: unit1 [...]
54# @DESCRIPTION: 110# @DESCRIPTION:
55# 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
56# and non-fatal in earlier EAPIs. 112# and non-fatal in earlier EAPIs.
57systemd_dounit() { 113systemd_dounit() {
58 debug-print-function ${FUNCNAME} "${@}" 114 debug-print-function ${FUNCNAME} "${@}"
59 115
60 ( 116 local INSDESTTREE
61 insinto "$(_systemd_get_unitdir)" 117 insinto "$(_systemd_get_unitdir)"
62 doins "${@}" 118 doins "${@}"
63 )
64} 119}
65 120
66# @FUNCTION: systemd_newunit 121# @FUNCTION: systemd_newunit
67# @USAGE: oldname newname 122# @USAGE: oldname newname
68# @DESCRIPTION: 123# @DESCRIPTION:
69# 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
70# in EAPI 4 and non-fatal in earlier EAPIs. 125# in EAPI 4 and non-fatal in earlier EAPIs.
71systemd_newunit() { 126systemd_newunit() {
72 debug-print-function ${FUNCNAME} "${@}" 127 debug-print-function ${FUNCNAME} "${@}"
73 128
74 ( 129 local INSDESTTREE
75 insinto "$(_systemd_get_unitdir)" 130 insinto "$(_systemd_get_unitdir)"
76 newins "${@}" 131 newins "${@}"
77 )
78} 132}
79 133
80# @FUNCTION: systemd_dotmpfilesd 134# @FUNCTION: systemd_dotmpfilesd
81# @USAGE: tmpfilesd1 [...] 135# @USAGE: tmpfilesd1 [...]
82# @DESCRIPTION: 136# @DESCRIPTION:
88 for f; do 142 for f; do
89 [[ ${f} == *.conf ]] \ 143 [[ ${f} == *.conf ]] \
90 || die 'tmpfiles.d files need to have .conf suffix.' 144 || die 'tmpfiles.d files need to have .conf suffix.'
91 done 145 done
92 146
93 ( 147 local INSDESTTREE
94 insinto /usr/lib/tmpfiles.d/ 148 insinto /usr/lib/tmpfiles.d/
95 doins "${@}" 149 doins "${@}"
96 )
97} 150}
98 151
99# @FUNCTION: systemd_newtmpfilesd 152# @FUNCTION: systemd_newtmpfilesd
100# @USAGE: oldname newname.conf 153# @USAGE: oldname newname.conf
101# @DESCRIPTION: 154# @DESCRIPTION:
105 debug-print-function ${FUNCNAME} "${@}" 158 debug-print-function ${FUNCNAME} "${@}"
106 159
107 [[ ${2} == *.conf ]] \ 160 [[ ${2} == *.conf ]] \
108 || die 'tmpfiles.d files need to have .conf suffix.' 161 || die 'tmpfiles.d files need to have .conf suffix.'
109 162
110 ( 163 local INSDESTTREE
111 insinto /usr/lib/tmpfiles.d/ 164 insinto /usr/lib/tmpfiles.d/
112 newins "${@}" 165 newins "${@}"
113 )
114} 166}
115 167
116# @FUNCTION: systemd_enable_service 168# @FUNCTION: systemd_enable_service
117# @USAGE: target service 169# @USAGE: target service
118# @DESCRIPTION: 170# @DESCRIPTION:
125 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service" 177 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
126 178
127 local target=${1} 179 local target=${1}
128 local service=${2} 180 local service=${2}
129 local ud=$(_systemd_get_unitdir) 181 local ud=$(_systemd_get_unitdir)
130 local destname=$(basename "${service}") 182 local destname=${service##*/}
131 183
132 dodir "${ud}"/"${target}".wants && \ 184 dodir "${ud}"/"${target}".wants && \
133 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}" 185 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
134} 186}
135 187
150 local optname=${1:-systemdsystemunitdir} 202 local optname=${1:-systemdsystemunitdir}
151 203
152 echo --with-${optname}="$(systemd_get_unitdir)" 204 echo --with-${optname}="$(systemd_get_unitdir)"
153} 205}
154 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)"
216}
217
155# @FUNCTION: systemd_to_myeconfargs 218# @FUNCTION: systemd_to_myeconfargs
156# @DESCRIPTION: 219# @DESCRIPTION:
157# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure 220# Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
158# scripts to the myeconfargs variable used by autotools-utils eclass. Handles 221# scripts to the myeconfargs variable used by autotools-utils eclass. Handles
159# quoting automatically. 222# quoting automatically.
163 myeconfargs=( 226 myeconfargs=(
164 "${myeconfargs[@]}" 227 "${myeconfargs[@]}"
165 --with-systemdsystemunitdir="$(systemd_get_unitdir)" 228 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
166 ) 229 )
167} 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.16  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.20