summaryrefslogtreecommitdiff
path: root/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-08-17 22:42:31 +0300
committerPatrick Williams <patrick@stwcx.xyz>2016-09-06 04:55:37 +0300
commit522234c8e22c43ac7ece5b0b33b379c94dc49277 (patch)
treedf64376195e8b4aeb06e7b0c8740e4a54b458b04 /meta-phosphor/classes/obmc-phosphor-systemd.bbclass
parent18645293cab6c1c14310e982592294b833e3df92 (diff)
downloadopenbmc-522234c8e22c43ac7ece5b0b33b379c94dc49277.tar.xz
classes-systemd: general refactoring
Factor out some code so it can be used elsewhere. Change-Id: Ifbb2d7553c2c21868b5bc5b515b6f03f2c0882c0 Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'meta-phosphor/classes/obmc-phosphor-systemd.bbclass')
-rw-r--r--meta-phosphor/classes/obmc-phosphor-systemd.bbclass65
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)
}