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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Mon Dec 31 13:08:12 2012 UTC (20 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.19: +24 -1 lines
Add function to update systemd journal catalog database.

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

  ViewVC Help
Powered by ViewVC 1.1.20