Recipe for phosphor-discover-system-state

This recipe will add the new program phosphor-discover-system-state
to new builds. Additionally, the old Python state manager is
removed from the build since discover_system_state.py was the last
thing in it.

Resolves openbmc/openbmc#773

Change-Id: I99ba0f1f0264cedebc5a9a7e5fa5dbaba0b79502
Signed-off-by: Michael Tritz <mtritz@us.ibm.com>
diff --git a/common/recipes-phosphor/state/files/phosphor-discover-system-state@.service b/common/recipes-phosphor/state/files/phosphor-discover-system-state@.service
new file mode 100644
index 0000000..325e8dc
--- /dev/null
+++ b/common/recipes-phosphor/state/files/phosphor-discover-system-state@.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=Reboot If Enabled
+Wants=mapper-wait@-org-openbmc-settings-host%i.service
+After=mapper-wait@-org-openbmc-settings-host%i.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host%i.service
+After=mapper-wait@-xyz-openbmc_project-state-host%i.service
+Wants=mapper-wait@-xyz-openbmc_project-state-chassis%i.service
+After=mapper-wait@-xyz-openbmc_project-state-chassis%i.service
+
+[Service]
+Restart=no
+Type=oneshot
+ExecStart={sbindir}/phosphor-discover-system-state --host %i
+
+[Install]
+WantedBy={SYSTEMD_DEFAULT_TARGET}
diff --git a/common/recipes-phosphor/state/phosphor-state-manager.bb b/common/recipes-phosphor/state/phosphor-state-manager.bb
index 5258486..ce0fa1e 100644
--- a/common/recipes-phosphor/state/phosphor-state-manager.bb
+++ b/common/recipes-phosphor/state/phosphor-state-manager.bb
@@ -20,9 +20,7 @@
 
 DBUS_PACKAGES = "${STATE_MGR_PACKAGES}"
 
-# Set SYSTEMD_PACKAGES to empty because we do not want ${PN} and DBUS_PACKAGES
-# handles the rest.
-SYSTEMD_PACKAGES = ""
+SYSTEMD_PACKAGES = "${PN}-discover"
 
 inherit autotools pkgconfig
 inherit obmc-phosphor-dbus-service
@@ -48,6 +46,12 @@
 DBUS_SERVICE_${PN}-bmc += "xyz.openbmc_project.State.BMC.service"
 
 FILES_${PN}-discover = "${sbindir}/phosphor-discover-system-state"
+SYSTEMD_SERVICE_${PN}-discover += "phosphor-discover-system-state@.service"
+
+TMPL = "phosphor-discover-system-state@.service"
+INSTFMT = "phosphor-discover-system-state@{0}.service"
+FMT = "../${TMPL}:${SYSTEMD_DEFAULT_TARGET}.wants/${INSTFMT}"
+SYSTEMD_LINK_${PN}-discover += "${@compose_list(d, 'FMT', 'OBMC_HOST_INSTANCES')}"
 
 SRC_URI += "git://github.com/openbmc/phosphor-state-manager"
 SRCREV = "cc3fb5d9a720a9a5b2102683da716004cd938e39"