| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 1 | # 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 Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 11 | inherit systemd | 
|  | 12 |  | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 13 |  | 
|  | 14 | python() { | 
|  | 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 Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 39 |  | 
|  | 40 | do_install_append() { | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 41 | # 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 Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 52 | } |