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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (hide annotations) (download)
Mon Mar 18 06:29:03 2013 UTC (19 months ago) by mgorny
Branch: MAIN
Changes since 1.21: +3 -3 lines
Update the maintainer to systemd@.

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

  ViewVC Help
Powered by ViewVC 1.1.20