diff options
Diffstat (limited to 'meta-phosphor')
-rw-r--r-- | meta-phosphor/classes/obmc-phosphor-systemd.bbclass | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass index c1eb3c9e7..85089f807 100644 --- a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass +++ b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass @@ -104,25 +104,28 @@ python() { 'have a restart policy defined.' % unit.name) - def add_sd_unit(d, unit, pkg): - name = unit.name - unit_dir = d.getVar('systemd_system_unitdir', True) - set_append(d, 'SRC_URI', 'file://%s' % name) - set_append(d, 'FILES_%s' % pkg, '%s/%s' % (unit_dir, name)) - set_append(d, '_INSTALL_SD_UNITS', name) - set_append(d, '_MAKE_SUBS', '%s' % name) + def add_default_subs(d, file): + set_append(d, '_MAKE_SUBS', '%s' % file) for x in [ 'base_bindir', 'bindir', 'sbindir', 'SYSTEMD_DEFAULT_TARGET' ]: - set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % name, + set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % file, '%s:%s' % (x, d.getVar(x, True))) - def add_sd_user(d, unit, pkg): + def add_sd_unit(d, unit, pkg): name = unit.name + unit_dir = d.getVar('systemd_system_unitdir', True) + set_append(d, 'SRC_URI', 'file://%s' % name) + set_append(d, 'FILES_%s' % pkg, '%s/%s' % (unit_dir, name)) + set_append(d, '_INSTALL_SD_UNITS', name) + add_default_subs(d, name) + + + def add_sd_user(d, file, pkg): opts = [ '--system', '--home', @@ -131,7 +134,7 @@ python() { '--shell /sbin/nologin', '--user-group'] - var = 'SYSTEMD_USER_%s' % name + var = 'SYSTEMD_USER_%s' % file user = listvar_to_list(d, var) if len(user) is 0: var = 'SYSTEMD_USER_%s' % pkg @@ -141,7 +144,7 @@ python() { bb.fatal('Too many users assigned to %s: \'%s\'' % (var, ' '.join(user))) user = user[0] - set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % name, + set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % file, 'USER:%s' % user) if user not in d.getVar('USERADD_PARAM_%s' % pkg, True): set_append( @@ -168,28 +171,32 @@ python() { for unit in tmpl + svc: check_sd_unit(d, unit) add_sd_unit(d, unit, pkg) - add_sd_user(d, unit, pkg) + add_sd_user(d, unit.name, pkg) } python systemd_do_postinst() { - for f in listvar_to_list(d, '_MAKE_SUBS'): - subs = dict([ x.split(':') for x in - listvar_to_list(d, 'SYSTEMD_SUBSTITUTIONS_%s' % f)]) - if not subs: - continue - - path = d.getVar('D', True) - path += d.getVar('systemd_system_unitdir', True) - path += '/%s' % f - with open(path, 'r') as fd: - content = fd.read() - with open(path, 'w+') as fd: - try: - fd.write(content.format(**subs)) - except KeyError as e: - bb.fatal('No substitution found for %s in ' - 'file \'%s\'' % (e, f)) + def make_subs(d): + for f in listvar_to_list(d, '_MAKE_SUBS'): + subs = dict([ x.split(':') for x in + listvar_to_list(d, 'SYSTEMD_SUBSTITUTIONS_%s' % f)]) + if not subs: + continue + + path = d.getVar('D', True) + path += d.getVar('systemd_system_unitdir', True) + path += '/%s' % f + with open(path, 'r') as fd: + content = fd.read() + with open(path, 'w+') as fd: + try: + fd.write(content.format(**subs)) + except KeyError as e: + bb.fatal('No substitution found for %s in ' + 'file \'%s\'' % (e, f)) + + + make_subs(d) } |