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/packagegroups/packagegroup-obmc-apps.bb b/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bb
index a0415e0..815f40f 100644
--- a/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bb
+++ b/common/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bb
@@ -41,6 +41,7 @@
 SUMMARY_${PN}-host-state-mgmt = "Host state management"
 RDEPENDS_${PN}-host-state-mgmt = " \
         ${VIRTUAL-RUNTIME_obmc-host-state-manager} \
+        ${VIRTUAL-RUNTIME_obmc-discover-system-state} \
         "
 
 SUMMARY_${PN}-inventory = "Inventory applications"
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"
diff --git a/common/recipes-phosphor/system/obmc-mgr-state.bb b/common/recipes-phosphor/system/obmc-mgr-state.bb
deleted file mode 100644
index 464cf11..0000000
--- a/common/recipes-phosphor/system/obmc-mgr-state.bb
+++ /dev/null
@@ -1,28 +0,0 @@
-SUMMARY = "OpenBMC state manager"
-DESCRIPTION = "OpenBMC state manager."
-PR = "r1"
-
-inherit skeleton-python
-inherit obmc-phosphor-systemd
-
-VIRTUAL-RUNTIME_skeleton_workbook ?= ""
-
-RDEPENDS_${PN} += "\
-        python-dbus \
-        python-json \
-        python-subprocess \
-        python-pygobject \
-        "
-
-SKELETON_DIR = "pystatemgr"
-SYSTEMD_SERVICE_${PN} += "obmc-mgr-state.service obmc-mgr-state.target"
-
-TMPL = "mapper-wait@.service"
-TGT = "obmc-mgr-state.target"
-HOST_FMT = "../${TMPL}:${TGT}.wants/mapper-wait@-org-openbmc-settings-host{0}.service"
-CHASSIS_FMT = "../${TMPL}:${TGT}.wants/mapper-wait@-org-openbmc-control-chassis{0}.service"
-POWER_FMT = "../${TMPL}:${TGT}.wants/mapper-wait@-org-openbmc-control-power{0}.service"
-
-SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_FMT', 'OBMC_HOST_INSTANCES')}"
-SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_FMT', 'OBMC_CHASSIS_INSTANCES')}"
-SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'POWER_FMT', 'OBMC_POWER_INSTANCES')}"
diff --git a/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.service b/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.service
deleted file mode 100644
index 681abb4..0000000
--- a/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.service
+++ /dev/null
@@ -1,15 +0,0 @@
-[Unit]
-Description=Restore Last State
-Wants=obmc-mgr-state.target
-After=obmc-mgr-state.target
-Wants=mapper-wait@-org-openbmc-settings-host0.service
-After=mapper-wait@-org-openbmc-settings-host0.service
-
-[Service]
-Restart=no
-Type=oneshot
-ExecStart={sbindir}/discover_system_state.py
-Environment="PYTHONUNBUFFERED=1"
-
-[Install]
-WantedBy={SYSTEMD_DEFAULT_TARGET}
diff --git a/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.target b/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.target
deleted file mode 100644
index fef2a1f..0000000
--- a/common/recipes-phosphor/system/obmc-mgr-state/obmc-mgr-state.target
+++ /dev/null
@@ -1,2 +0,0 @@
-[Unit]
-Description=Restore Last State
diff --git a/conf/distro/include/phosphor-defaults.inc b/conf/distro/include/phosphor-defaults.inc
index 296d304..75d51db 100644
--- a/conf/distro/include/phosphor-defaults.inc
+++ b/conf/distro/include/phosphor-defaults.inc
@@ -32,6 +32,13 @@
 # interface.
 VIRTUAL-RUNTIME_obmc-host-state-manager ?= "phosphor-state-manager-host"
 
+# obmc-discover-system-state
+#
+# Provides an implementation of phosphor-discover-system-state, which, if the
+# host is powered off, will check the current power policy and, if necessary,
+# power the host back on.
+VIRTUAL-RUNTIME_obmc-discover-system-state ?= "phosphor-state-manager-discover"
+
 # obmc-fan-presence
 #
 # Provides implementations of fan presence detection