blob: f882bfcfe176da43625e166cfa8c8ab42d27b961 [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
Brad Bishop8b875602016-07-11 00:42:58 -040010# ${PN}.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() {
Brad Bishop8b875602016-07-11 00:42:58 -040015 pn = d.getVar('PN', True)
Brad Bishop1bb8be52016-06-08 22:03:59 -040016 searchpaths = d.getVar('FILESPATH', True)
17
Brad Bishop8b875602016-07-11 00:42:58 -040018 services = d.getVar('SYSTEMD_SERVICE_' + pn, True)
Brad Bishop1bb8be52016-06-08 22:03:59 -040019
20 if services:
21 services = services.split()
22 else:
Brad Bishop8b875602016-07-11 00:42:58 -040023 services = [pn + '.service']
Brad Bishop1bb8be52016-06-08 22:03:59 -040024
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)
Brad Bishop8b875602016-07-11 00:42:58 -040030 d.appendVar("FILES_%s" %(pn), " %s/%s" \
Brad Bishop29ee5fc2016-07-06 20:11:57 -040031 % (d.getVar('systemd_system_unitdir', True), file))
Brad Bishop1bb8be52016-06-08 22:03:59 -040032 d.appendVar('OBMC_SYSTEMD_SERVICES', ' ' + file)
Brad Bishop8b875602016-07-11 00:42:58 -040033 if file not in (d.getVar('SYSTEMD_SERVICE_' + pn, True) or "").split():
34 d.appendVar('SYSTEMD_SERVICE_' + pn, ' ' + file)
Brad Bishop1bb8be52016-06-08 22:03:59 -040035 else:
36 bb.error("Could not find service file: %s" % file)
37}
Brad Bishop93fb5352015-09-09 03:59:20 +000038
39do_install_append() {
Brad Bishop1bb8be52016-06-08 22:03:59 -040040 # install systemd service/socket/template files
41 if [ "${OBMC_SYSTEMD_SERVICES}" ]; then
42 install -d ${D}${systemd_system_unitdir}
43 fi
44 for s in ${OBMC_SYSTEMD_SERVICES}; do
45 install -m 0644 ${WORKDIR}/$s ${D}${systemd_system_unitdir}
46 sed -i -e 's,@BASE_BINDIR@,${base_bindir},g' \
47 -e 's,@BINDIR@,${bindir},g' \
48 -e 's,@SBINDIR@,${sbindir},g' \
49 ${D}${systemd_system_unitdir}/$s
50 done
Brad Bishop93fb5352015-09-09 03:59:20 +000051}