blob: 3df5ee44a71e85e297605f153034c4c06977e9b6 [file] [log] [blame]
Brad Bishope36358c2016-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 Bishop62d676a2016-07-11 00:42:58 -040010# ${PN}.service will be added to the main package.
Brad Bishop9dc56712016-07-07 15:56:02 -040011
12inherit obmc-phosphor-utils
Brad Bishop93fb5352015-09-09 03:59:20 +000013inherit systemd
14
Brad Bishop9dc56712016-07-07 15:56:02 -040015_INSTALL_SD_UNITS=""
16
Brad Bishope36358c2016-06-08 22:03:59 -040017
18python() {
Brad Bishop9dc56712016-07-07 15:56:02 -040019 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 Bishop62d676a2016-07-11 00:42:58 -040029 pn = d.getVar('PN', True)
Brad Bishop9dc56712016-07-07 15:56:02 -040030 if d.getVar('SYSTEMD_SERVICE_%s' % pn, True) is None:
31 d.setVar('SYSTEMD_SERVICE_%s' % pn, '%s.service' % pn)
Brad Bishope36358c2016-06-08 22:03:59 -040032
Brad Bishop9dc56712016-07-07 15:56:02 -040033 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 Bishope36358c2016-06-08 22:03:59 -040036}
Brad Bishop93fb5352015-09-09 03:59:20 +000037
Brad Bishop9dc56712016-07-07 15:56:02 -040038
Brad Bishop93fb5352015-09-09 03:59:20 +000039do_install_append() {
Brad Bishope36358c2016-06-08 22:03:59 -040040 # install systemd service/socket/template files
Brad Bishop9dc56712016-07-07 15:56:02 -040041 [ -z "${_INSTALL_SD_UNITS}" ] || \
Brad Bishope36358c2016-06-08 22:03:59 -040042 install -d ${D}${systemd_system_unitdir}
Brad Bishop9dc56712016-07-07 15:56:02 -040043 for s in ${_INSTALL_SD_UNITS}; do
44 install -m 0644 ${WORKDIR}/$s \
45 ${D}${systemd_system_unitdir}/$s
Brad Bishope36358c2016-06-08 22:03:59 -040046 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}