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 | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 11 | |
| 12 | inherit obmc-phosphor-utils |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 13 | inherit systemd |
| 14 | |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 15 | _INSTALL_SD_UNITS="" |
| 16 | |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 17 | |
| 18 | python() { |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 19 | def add_sd_unit(d, unit, pkg): |
| 20 | searchpaths = d.getVar('FILESPATH', True) |
| 21 | path = bb.utils.which(searchpaths, '%s' % unit) |
| 22 | if not os.path.isfile(path): |
| 23 | bb.fatal('Did not find unit file "%s"' % unit) |
| 24 | set_append(d, 'SRC_URI', 'file://%s' % unit) |
| 25 | set_append(d, 'FILES_%s' % pkg, '%s/%s' \ |
| 26 | % (d.getVar('systemd_system_unitdir', True), unit)) |
| 27 | set_append(d, '_INSTALL_SD_UNITS', '%s' % unit) |
| 28 | |
Brad Bishop | 8b87560 | 2016-07-11 00:42:58 -0400 | [diff] [blame] | 29 | pn = d.getVar('PN', True) |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 30 | if d.getVar('SYSTEMD_SERVICE_%s' % pn, True) is None: |
| 31 | d.setVar('SYSTEMD_SERVICE_%s' % pn, '%s.service' % pn) |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 32 | |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 33 | for pkg in listvar_to_list(d, 'SYSTEMD_PACKAGES'): |
| 34 | for unit in listvar_to_list(d, 'SYSTEMD_SERVICE_%s' % pkg): |
| 35 | add_sd_unit(d, unit, pkg) |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 36 | } |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 37 | |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 38 | |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 39 | do_install_append() { |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 40 | # install systemd service/socket/template files |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 41 | [ -z "${_INSTALL_SD_UNITS}" ] || \ |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 42 | install -d ${D}${systemd_system_unitdir} |
Brad Bishop | bfef6ff | 2016-07-07 15:56:02 -0400 | [diff] [blame^] | 43 | for s in ${_INSTALL_SD_UNITS}; do |
| 44 | install -m 0644 ${WORKDIR}/$s \ |
| 45 | ${D}${systemd_system_unitdir}/$s |
Brad Bishop | 1bb8be5 | 2016-06-08 22:03:59 -0400 | [diff] [blame] | 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 | } |