summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-14 19:50:19 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-28 14:35:37 -0400
commitf815b2eac42e2f63842904b892c3cc1b5e4888f2 (patch)
tree944565db7fc0049da2d2623f75fa7aa3eacfc8c2 /meta-phosphor/classes/obmc-phosphor-systemd.bbclass
parent51528fe90d217f8a4fd85abab15fec2fe703dec0 (diff)
downloadtalos-openbmc-f815b2eac42e2f63842904b892c3cc1b5e4888f2.tar.gz
talos-openbmc-f815b2eac42e2f63842904b892c3cc1b5e4888f2.zip
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 <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'meta-phosphor/classes/obmc-phosphor-systemd.bbclass')
-rw-r--r--meta-phosphor/classes/obmc-phosphor-systemd.bbclass38
1 files changed, 38 insertions, 0 deletions
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)
}
OpenPOWER on IntegriCloud