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