blob: b07174f9fb492f07085cf1c580304f7d3ad0a76b [file] [log] [blame]
Brad Bishop1bb8be52016-06-08 22:03:59 -04001# Common code for systemd based services.
2#
3# Prior to inheriting this class, recipes can define services like this:
4#
5# SYSTEMD_SERVICE_${PN} = "foo.service bar.socket baz@.service"
6#
7# and these files will be added to the main package if they exist.
8#
9# Alternatively this class can just be inherited and
10# ${BPN}.service will be added to the main package.
Brad Bishop93fb5352015-09-09 03:59:20 +000011inherit systemd
12
Brad Bishop1bb8be52016-06-08 22:03:59 -040013
14python() {
15 bpn = d.getVar('BPN', True)
16 searchpaths = d.getVar('FILESPATH', True)
17
18 services = d.getVar('SYSTEMD_SERVICE_' + bpn, True)
19
20 if services:
21 services = services.split()
22 else:
23 services = [bpn + '.service']
24
25 for s in services:
26 file = s
27 path = bb.utils.which(searchpaths, file)
28 if os.path.isfile(path):
29 d.appendVar('SRC_URI', ' file://' + file)
30 d.appendVar(
31 'FILES_' + bpn, ' ' +
32 d.getVar('systemd_system_unitdir', True) + file)
33 d.appendVar('OBMC_SYSTEMD_SERVICES', ' ' + file)
34 if file not in (d.getVar('SYSTEMD_SERVICE_' + bpn, True) or "").split():
35 d.appendVar('SYSTEMD_SERVICE_' + bpn, ' ' + file)
36 else:
37 bb.error("Could not find service file: %s" % file)
38}
Brad Bishop93fb5352015-09-09 03:59:20 +000039
40do_install_append() {
Brad Bishop1bb8be52016-06-08 22:03:59 -040041 # install systemd service/socket/template files
42 if [ "${OBMC_SYSTEMD_SERVICES}" ]; then
43 install -d ${D}${systemd_system_unitdir}
44 fi
45 for s in ${OBMC_SYSTEMD_SERVICES}; do
46 install -m 0644 ${WORKDIR}/$s ${D}${systemd_system_unitdir}
47 sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
48 -e 's,@BINDIR@,${bindir},g' \
49 -e 's,@SBINDIR@,${sbindir},g' \
50 ${D}${systemd_system_unitdir}/$s
51 done
Brad Bishop93fb5352015-09-09 03:59:20 +000052}