summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-11 13:05:26 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2016-07-28 14:35:37 -0400
commit687146f04022213f631c73b54ab41455eeb46194 (patch)
tree61e4c61daee4b4238c3d4fb1ae10c2443abac82b /meta-phosphor/classes/obmc-phosphor-systemd.bbclass
parentf98709fa6fbe67f0edc0b2594a83db37dfff3e7c (diff)
downloadtalos-openbmc-687146f04022213f631c73b54ab41455eeb46194.tar.gz
talos-openbmc-687146f04022213f631c73b54ab41455eeb46194.zip
classes-systemd: Add restart policy warning
Print a warning if a systemd service unit is detected without a restart policy defined. To inhibit: INHIBIT_SYSTEMD_RESTART_POLICY_WARNING += "${UNIT}" Change-Id: I27436276425d028d892c7c98736781e8577ad8eb 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.bbclass39
1 files changed, 37 insertions, 2 deletions
diff --git a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
index 3df5ee44a..dba39d356 100644
--- a/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
+++ b/meta-phosphor/classes/obmc-phosphor-systemd.bbclass
@@ -8,6 +8,11 @@
#
# Alternatively this class can just be inherited and
# ${PN}.service will be added to the main package.
+#
+# Other variables:
+# INHIBIT_SYSTEMD_RESTART_POLICY_${unit}
+# Inhibit the warning that is displayed if a service unit without a
+# restart policy is detected.
inherit obmc-phosphor-utils
inherit systemd
@@ -15,16 +20,45 @@ inherit systemd
_INSTALL_SD_UNITS=""
+def systemd_is_service(unit):
+ return unit.endswith('.service')
+
+
+def systemd_is_template(unit):
+ return '@.' in unit
+
+
+def systemd_parse_unit(d, path):
+ import ConfigParser
+ parser = ConfigParser.SafeConfigParser()
+ parser.optionxform = str
+ parser.read('%s' % path)
+ return parser
+
+
python() {
- def add_sd_unit(d, unit, pkg):
+ def check_sd_unit(d, unit):
searchpaths = d.getVar('FILESPATH', True)
path = bb.utils.which(searchpaths, '%s' % unit)
if not os.path.isfile(path):
bb.fatal('Did not find unit file "%s"' % unit)
+
+ parser = systemd_parse_unit(d, path)
+ inhibit = listvar_to_list(d, 'INHIBIT_SYSTEMD_RESTART_POLICY_WARNING')
+ if systemd_is_service(unit) and \
+ not systemd_is_template(unit) and \
+ unit not in inhibit and \
+ not parser.has_option('Service', 'Restart'):
+ bb.warn('Systemd unit \'%s\' does not '
+ 'have a restart policy defined.' % unit)
+
+
+ def add_sd_unit(d, unit, pkg):
set_append(d, 'SRC_URI', 'file://%s' % unit)
set_append(d, 'FILES_%s' % pkg, '%s/%s' \
% (d.getVar('systemd_system_unitdir', True), unit))
- set_append(d, '_INSTALL_SD_UNITS', '%s' % unit)
+ set_append(d, '_INSTALL_SD_UNITS', unit)
+
pn = d.getVar('PN', True)
if d.getVar('SYSTEMD_SERVICE_%s' % pn, True) is None:
@@ -32,6 +66,7 @@ python() {
for pkg in listvar_to_list(d, 'SYSTEMD_PACKAGES'):
for unit in listvar_to_list(d, 'SYSTEMD_SERVICE_%s' % pkg):
+ check_sd_unit(d, unit)
add_sd_unit(d, unit, pkg)
}
OpenPOWER on IntegriCloud