From f815b2eac42e2f63842904b892c3cc1b5e4888f2 Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Thu, 14 Jul 2016 19:50:19 -0400 Subject: classes-systemd: Add user Add a SYSTEMD_USER_${PN}_foo.service variable for setting the service user in systemd service files. Change-Id: I9354b19f6cf5563fe33ee71dc5b8b07c4f380847 Signed-off-by: Brad Bishop --- .../classes/obmc-phosphor-systemd.bbclass | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'meta-phosphor/classes/obmc-phosphor-systemd.bbclass') diff --git a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass index 0aa549342..04b813506 100644 --- a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass +++ b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass @@ -21,14 +21,24 @@ # VAR:VALUE # where {VAR} is the format string bitbake should look for in the # unit file and VALUE is the value to substitute. +# +# SYSTEMD_USER_${PN}_${PN}.service = "foo" +# The user for the unit. inherit obmc-phosphor-utils inherit systemd +inherit useradd _INSTALL_SD_UNITS="" SYSTEMD_DEFAULT_TARGET ?= "obmc-standby.target" +# Big ugly hack to prevent useradd.bbclass post-parse sanity checker failure. +# If there are users to be added, we'll add them in our post-parse. +# If not...there don't seem to be any ill effects... +USERADD_PACKAGES ?= " " +USERADD_PARAM_${PN} ?= ";" + def systemd_is_service(unit): return unit.endswith('.service') @@ -77,6 +87,33 @@ python() { set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % unit, '%s:%s' % (x, d.getVar(x, True))) + user = d.getVar( + 'SYSTEMD_USER_%s_%s' % (pkg, unit), True) + if user: + set_append(d, 'SYSTEMD_SUBSTITUTIONS_%s' % unit, + 'USER:%s' % d.getVar('SYSTEMD_USER_%s_%s' % (pkg, unit), True)) + + + def add_sd_user(d, unit, pkg): + opts = [ + '--system', + '--home', + '/', + '--no-create-home', + '--shell /sbin/nologin', + '--user-group'] + + user = d.getVar( + 'SYSTEMD_USER_%s_%s' % (pkg, unit), True) + if user: + set_append( + d, + 'USERADD_PARAM_%s' % pkg, + '%s' % (' '.join(opts + [user])), + ';') + if pkg not in d.getVar('USERADD_PACKAGES', True): + set_append(d, 'USERADD_PACKAGES', pkg) + pn = d.getVar('PN', True) if d.getVar('SYSTEMD_SERVICE_%s' % pn, True) is None: @@ -86,6 +123,7 @@ python() { for unit in listvar_to_list(d, 'SYSTEMD_SERVICE_%s' % pkg): check_sd_unit(d, unit) add_sd_unit(d, unit, pkg) + add_sd_user(d, unit, pkg) } -- cgit v1.2.1