| 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 | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 10 | # ${PN}.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() { | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 15 | pn = d.getVar('PN', True) | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 16 | searchpaths = d.getVar('FILESPATH', True) | 
|  | 17 |  | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 18 | services = d.getVar('SYSTEMD_SERVICE_' + pn, True) | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 19 |  | 
|  | 20 | if services: | 
|  | 21 | services = services.split() | 
|  | 22 | else: | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 23 | services = [pn + '.service'] | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 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) | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 30 | d.appendVar("FILES_%s" %(pn), " %s/%s" \ | 
| Brad Bishop | 29ee5fc | 2016-07-06 20:11:57 -0400 | [diff] [blame] | 31 | % (d.getVar('systemd_system_unitdir', True), file)) | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 32 | d.appendVar('OBMC_SYSTEMD_SERVICES', ' ' + file) | 
| Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 33 | if file not in (d.getVar('SYSTEMD_SERVICE_' + pn, True) or "").split(): | 
|  | 34 | d.appendVar('SYSTEMD_SERVICE_' + pn, ' ' + file) | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 35 | else: | 
|  | 36 | bb.error("Could not find service file: %s" % file) | 
|  | 37 | } | 
| Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 38 |  | 
|  | 39 | do_install_append() { | 
| Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 40 | # 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 Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 51 | } |