summaryrefslogtreecommitdiffstats
path: root/meta-oe/classes
diff options
context:
space:
mode:
authorAndreas Müller <schnitzeltony@googlemail.com>2012-07-11 13:22:08 +0200
committerKoen Kooi <koen@dominion.thruhere.net>2012-07-16 09:39:05 +0200
commit5ed19733f5193b752da650841a1383adb532fffd (patch)
treee6206a675001010939353efebcd2c2662bf37809 /meta-oe/classes
parentd0b43b1144d9bf7cabda64e291b366bfc177f39c (diff)
downloadmeta-openembedded-5ed19733f5193b752da650841a1383adb532fffd.tar.gz
systemd.bbclass: move to meta-systemd
Diffstat (limited to 'meta-oe/classes')
-rw-r--r--meta-oe/classes/systemd.bbclass207
1 files changed, 0 insertions, 207 deletions
diff --git a/meta-oe/classes/systemd.bbclass b/meta-oe/classes/systemd.bbclass
deleted file mode 100644
index 2e585c3ec..000000000
--- a/meta-oe/classes/systemd.bbclass
+++ /dev/null
@@ -1,207 +0,0 @@
1DEPENDS_append = " systemd-systemctl-native"
2
3systemd_postinst() {
4OPTS=""
5
6if [ -n "$D" ]; then
7 OPTS="--root=$D"
8fi
9
10systemctl $OPTS enable ${SYSTEMD_SERVICE}
11
12if [ -z "$D" ]; then
13 systemctl start ${SYSTEMD_SERVICE}
14fi
15}
16
17systemd_prerm() {
18if [ -z "$D" ]; then
19 systemctl stop ${SYSTEMD_SERVICE}
20fi
21}
22
23systemd_postrm() {
24systemctl disable ${SYSTEMD_SERVICE}
25}
26
27def get_package_var(d, var, pkg):
28 val = (d.getVar('%s_%s' % (var, pkg), d, 1) or "").strip()
29 if val == "":
30 val = (d.getVar(var, d, 1) or "").strip()
31 return val
32
33def systemd_after_parse(d):
34 def systemd_check_vars():
35 if d.getVar('BB_WORKERCONTEXT', True) is not None:
36 return
37
38 bb_filename = d.getVar('FILE')
39 packages = d.getVar('PACKAGES', 1)
40
41 # check SYSTEMD_PACKAGES
42 systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or ""
43 if systemd_pkgs == "":
44 raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename
45 for pkg_systemd in systemd_pkgs.split():
46 if pkg_systemd.find("-systemd") == -1:
47 if pkg_systemd != d.getVar('PN', 1):
48 raise bb.build.FuncFailed, \
49 "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN} (deprecated)" % \
50 (bb_filename, pkg_systemd)
51 else:
52 # Only complain if recipe lacks native systemd support
53 native_systemd_support = d.getVar('NATIVE_SYSTEMD_SUPPORT', 1) or ""
54 if native_systemd_support == "":
55 bb.warn("%s: it is recommended to set SYSTEMD_PACKAGES as <existing-package>-systemd" % bb_filename)
56 else:
57 pkg_systemd_base = pkg_systemd.replace('-systemd', '')
58 if pkg_systemd_base not in packages:
59 raise bb.build.FuncFailed, \
60 "\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN} (deprecated)" % \
61 ( bb_filename, pkg_systemd)
62
63 # prepend systemd-packages not already included
64 def systemd_create_package(pkg_systemd):
65 packages = d.getVar('PACKAGES', 1)
66 if not pkg_systemd in packages:
67 packages = "%s %s" % (pkg_systemd, packages)
68 d.setVar('PACKAGES', packages)
69
70
71 bpn = d.getVar('BPN', 1)
72 if bpn + "-native" != d.getVar('PN', 1) and \
73 bpn + "-cross" != d.getVar('PN', 1) and \
74 bpn + "-nativesdk" != d.getVar('PN', 1):
75 systemd_check_vars()
76 for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
77 systemd_create_package(pkg_systemd)
78
79
80python __anonymous() {
81 systemd_after_parse(d)
82}
83
84# automatically install all *.service and *.socket supplied in recipe's SRC_URI
85do_install_append() {
86 for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do
87 # ensure installing systemd-files only (e.g not avahi *.service)
88 if grep -q '\[Unit\]' $service ; then
89 install -d ${D}${systemd_unitdir}/system
90 install -m 644 $service ${D}${systemd_unitdir}/system
91 fi
92 done
93}
94
95python populate_packages_prepend () {
96 def systemd_generate_package_scripts(pkg):
97 bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
98 localdata = bb.data.createCopy(d)
99 overrides = bb.data.getVar("OVERRIDES", localdata, 1)
100 bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata)
101 bb.data.update_data(localdata)
102
103 """
104 systemd postinst is appended here because pkg_postinst may require to
105 execute on the target. Not doing so may cause systemd postinst invoked
106 twice to cause unwanted warnings.
107 """
108 postinst = bb.data.getVar('pkg_postinst', localdata, 1)
109 if not postinst:
110 postinst = '#!/bin/sh\n'
111 postinst += bb.data.getVar('systemd_postinst', localdata, 1)
112 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
113
114 prerm = bb.data.getVar('pkg_prerm', localdata, 1)
115 if not prerm:
116 prerm = '#!/bin/sh\n'
117 prerm += bb.data.getVar('systemd_prerm', localdata, 1)
118 bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d)
119
120 postrm = bb.data.getVar('pkg_postrm', localdata, 1)
121 if not postrm:
122 postrm = '#!/bin/sh\n'
123 postrm += bb.data.getVar('systemd_postrm', localdata, 1)
124 bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
125
126 # add files to FILES_*-systemd if existent and not already done
127 def systemd_append_file(pkg_systemd, file_append):
128 appended = False
129 if os.path.exists('${D}' + file_append):
130 var_name = "FILES_" + pkg_systemd
131 files = d.getVar(var_name, 0) or ""
132 if file_append not in files.split():
133 d.setVar(var_name, "%s %s" % (files, file_append))
134 appended = True
135 return appended
136
137 # add systemd files to FILES_*-systemd, parse for Also= and follow recursive
138 def systemd_add_files_and_parse(pkg_systemd, path, service, keys):
139 # avoid infinite recursion
140 if systemd_append_file(pkg_systemd, path + service):
141 fullpath = '${D}' + path + service
142 if service.find('.socket') != -1:
143 # for *.socket add *.service and *@.service
144 service_base = service.replace('.socket', '')
145 systemd_add_files_and_parse(pkg_systemd, path, service_base + '.service', keys)
146 systemd_add_files_and_parse(pkg_systemd, path, service_base + '@.service', keys)
147 for key in keys.split():
148 # recurse all dependencies found in keys ('Also';'Conflicts';..) and add to files
149 cmd = "grep %s %s | sed 's,%s=,,g' | tr ',' '\\n'" % (key, fullpath, key)
150 pipe = os.popen(cmd, 'r')
151 line = pipe.readline()
152 while line:
153 line = line.replace('\n', '')
154 systemd_add_files_and_parse(pkg_systemd, path, line, keys)
155 line = pipe.readline()
156 pipe.close()
157
158 # check service-files and call systemd_add_files_and_parse for each entry
159 def systemd_check_services():
160 searchpaths = '/etc/systemd/system/ /lib/systemd/system/ /usr/lib/systemd/system/'
161 systemd_packages = d.getVar('SYSTEMD_PACKAGES', 1)
162 has_exactly_one_service = len(systemd_packages.split()) == 1
163 if has_exactly_one_service:
164 has_exactly_one_service = len(get_package_var(d, 'SYSTEMD_SERVICE', systemd_packages).split()) == 1
165
166 keys = 'Also' # Conflicts??
167 if has_exactly_one_service:
168 # single service gets also the /dev/null dummies
169 keys = 'Also Conflicts'
170 # scan for all in SYSTEMD_SERVICE[]
171 for pkg_systemd in systemd_packages.split():
172 for service in get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd).split():
173 path_found = ''
174 for path in searchpaths.split():
175 if os.path.exists('${D}' + path + service):
176 path_found = path
177 if path_found != '':
178 systemd_add_files_and_parse(pkg_systemd, path_found, service, keys)
179 else:
180 raise bb.build.FuncFailed, "\n\nFor package %s SYSTEMD_SERVICE-entry %s does not exist" % \
181 (pkg_systemd, service)
182
183 # *-systemd packages get RDEPENDS to systemd and their base package
184 def systemd_add_rdepends(pkg_systemd):
185 # RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd
186 rdepends = d.getVar('RDEPENDS_' + pkg_systemd, 1) or ""
187 rdepends_arr = rdepends.split()
188 if not 'systemd' in rdepends_arr:
189 rdepends = '%s %s' % (rdepends, 'systemd')
190 pkg_systemd_base = pkg_systemd.replace('-systemd', '')
191 # no automatism for:
192 # recipes setting rdepends themselves AND
193 # not rdepending myself AND
194 # avoid double entries
195 if len(rdepends_arr) == 0 and pkg_systemd != '${PN}' and not pkg_systemd_base in rdepends:
196 rdepends = '%s %s' % (rdepends, pkg_systemd_base)
197 d.setVar('RDEPENDS_' + pkg_systemd, rdepends)
198
199
200 # run all modifications once when creating package
201 if os.path.exists('${D}'):
202 for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
203 if get_package_var(d, 'SYSTEMD_SERVICE', pkg_systemd) != "":
204 systemd_generate_package_scripts(pkg_systemd)
205 systemd_add_rdepends(pkg_systemd)
206 systemd_check_services()
207}