Ensure host-shutdown target calls the host-stop target

As a part of the soft power off (host-shutdown) ensure
that the host-stop target always gets called.  Updated the
involved services to ensure they are run in the correct order.

Change-Id: I7e9113631786f0d0cb0f89b94c4b97fdc0328e7b
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-host-stop-pre@.target b/common/recipes-core/systemd/obmc-targets/obmc-host-stop-pre@.target
index 208892f..75afd43 100644
--- a/common/recipes-core/systemd/obmc-targets/obmc-host-stop-pre@.target
+++ b/common/recipes-core/systemd/obmc-targets/obmc-host-stop-pre@.target
@@ -2,6 +2,7 @@
 Description=Stop Host%i (Pre)
 Wants={SYSTEMD_DEFAULT_TARGET}
 After={SYSTEMD_DEFAULT_TARGET}
+Before=obmc-host-stopping@%i.target
 Conflicts=obmc-host-start@%i.target
 RefuseManualStart=yes
 RefuseManualStop=yes
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-host-stopped@.target b/common/recipes-core/systemd/obmc-targets/obmc-host-stopped@.target
index 1043578..d3efca5 100644
--- a/common/recipes-core/systemd/obmc-targets/obmc-host-stopped@.target
+++ b/common/recipes-core/systemd/obmc-targets/obmc-host-stopped@.target
@@ -1,7 +1,9 @@
 [Unit]
 Description=Host%i (Stopped)
 Wants={SYSTEMD_DEFAULT_TARGET}
-After=obmc-host-stop@%i.target
+Wants=obmc-host-stopping@%i.target
+After=obmc-host-stopping@%i.target
+Before=obmc-power-stop-pre@%i.target
 Conflicts=obmc-host-start@%i.target
 RefuseManualStart=yes
 RefuseManualStop=yes
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-host-stopping@.target b/common/recipes-core/systemd/obmc-targets/obmc-host-stopping@.target
index bc81a57..6209c52 100644
--- a/common/recipes-core/systemd/obmc-targets/obmc-host-stopping@.target
+++ b/common/recipes-core/systemd/obmc-targets/obmc-host-stopping@.target
@@ -1,7 +1,9 @@
 [Unit]
 Description=Host%i (Stopping)
 Wants={SYSTEMD_DEFAULT_TARGET}
+Wants=obmc-host-stop-pre@%i.target
 After=obmc-host-stop-pre@%i.target
+Before=obmc-host-stopped@%i.target
 Conflicts=obmc-host-start@%i.target
 Conflicts=obmc-host-starting@%i.target
 RefuseManualStart=yes
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-power-stop-pre@.target b/common/recipes-core/systemd/obmc-targets/obmc-power-stop-pre@.target
index 2f130c9..50d5050 100644
--- a/common/recipes-core/systemd/obmc-targets/obmc-power-stop-pre@.target
+++ b/common/recipes-core/systemd/obmc-targets/obmc-power-stop-pre@.target
@@ -2,6 +2,8 @@
 Description=Power%i Off (Pre)
 Wants={SYSTEMD_DEFAULT_TARGET}
 After={SYSTEMD_DEFAULT_TARGET}
+Wants=obmc-host-stopped@%i.target
+After=obmc-host-stopped@%i.target
 Conflicts=obmc-chassis-poweron@%i.target
 RefuseManualStart=yes
 RefuseManualStop=yes
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-power-stop@.target b/common/recipes-core/systemd/obmc-targets/obmc-power-stop@.target
index b32d76f..f0429d7 100644
--- a/common/recipes-core/systemd/obmc-targets/obmc-power-stop@.target
+++ b/common/recipes-core/systemd/obmc-targets/obmc-power-stop@.target
@@ -1,5 +1,6 @@
 [Unit]
 Description=Power%i Off
+Wants=obmc-power-stop-pre@%i.target
 After=obmc-power-stop-pre@%i.target
 Wants={SYSTEMD_DEFAULT_TARGET}
 Conflicts=obmc-chassis-poweron@%i.target
diff --git a/common/recipes-phosphor/chassis/obmc-op-control-power/op-power-stop@.service b/common/recipes-phosphor/chassis/obmc-op-control-power/op-power-stop@.service
index dd3570e..0833afb 100644
--- a/common/recipes-phosphor/chassis/obmc-op-control-power/op-power-stop@.service
+++ b/common/recipes-phosphor/chassis/obmc-op-control-power/op-power-stop@.service
@@ -2,6 +2,7 @@
 Description=Stop Power%i
 Wants=obmc-power-stop@%i.target
 Before=obmc-power-stop@%i.target
+Wants=obmc-power-stop-pre@%i.target
 After=obmc-power-stop-pre@%i.target
 Wants=mapper-wait@-org-openbmc-control-power%i.service
 After=mapper-wait@-org-openbmc-control-power%i.service
diff --git a/common/recipes-phosphor/chassis/obmc-op-control-power/op-wait-power-off@.service b/common/recipes-phosphor/chassis/obmc-op-control-power/op-wait-power-off@.service
index ad2b8b2..de2ff70 100644
--- a/common/recipes-phosphor/chassis/obmc-op-control-power/op-wait-power-off@.service
+++ b/common/recipes-phosphor/chassis/obmc-op-control-power/op-wait-power-off@.service
@@ -3,6 +3,8 @@
 Before=obmc-power-off@%i.target
 Wants=obmc-power-stop@%i.target
 Before=obmc-power-stop@%i.target
+Wants=obmc-power-stop-pre@%i.target
+After=obmc-power-stop-pre@%i.target
 Wants=mapper-wait@-org-openbmc-control-power%i.service
 After=mapper-wait@-org-openbmc-control-power%i.service
 Conflicts=obmc-chassis-poweron@%i.target
diff --git a/common/recipes-phosphor/chassis/obmc-watchdog/obmc-stop-watchdog@.service b/common/recipes-phosphor/chassis/obmc-watchdog/obmc-stop-watchdog@.service
index d149403..63f340b 100644
--- a/common/recipes-phosphor/chassis/obmc-watchdog/obmc-stop-watchdog@.service
+++ b/common/recipes-phosphor/chassis/obmc-watchdog/obmc-stop-watchdog@.service
@@ -2,6 +2,8 @@
 Description=Stop Watchdog%i
 Wants=mapper-wait@-org-openbmc-watchdog-host%i.service
 After=mapper-wait@-org-openbmc-watchdog-host%i.service
+Wants=obmc-host-stop-pre@%i.target
+Before=obmc-host-stop-pre@%i.target
 Conflicts=obmc-host-start@%i.target
 
 [Service]
diff --git a/common/recipes-phosphor/ipmi/phosphor-ipmi-host/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service b/common/recipes-phosphor/ipmi/phosphor-ipmi-host/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service
index aaba630..d1a814f 100644
--- a/common/recipes-phosphor/ipmi/phosphor-ipmi-host/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service
+++ b/common/recipes-phosphor/ipmi/phosphor-ipmi-host/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service
@@ -2,6 +2,8 @@
 Description=Soft power off of the host
 Wants=mapper-wait@-org-openbmc-HostIpmi-1.service
 After=mapper-wait@-org-openbmc-HostIpmi-1.service
+Wants=obmc-host-stopping@0.target
+Before=obmc-host-stopping@0.target
 
 [Service]
 Restart=no
diff --git a/common/recipes-phosphor/state/phosphor-state-manager.bb b/common/recipes-phosphor/state/phosphor-state-manager.bb
index 2f06dde..0f5e015 100644
--- a/common/recipes-phosphor/state/phosphor-state-manager.bb
+++ b/common/recipes-phosphor/state/phosphor-state-manager.bb
@@ -79,6 +79,13 @@
 FMT = "../${TMPL}:${SYSTEMD_DEFAULT_TARGET}.wants/${INSTFMT}"
 SYSTEMD_LINK_${PN}-discover += "${@compose_list(d, 'FMT', 'OBMC_HOST_INSTANCES')}"
 
+# Force the shutdown target to run the host-stop target
+HOST_STOP_TMPL = "obmc-host-stop@.target"
+HOST_STOP_TGTFMT = "obmc-host-shutdown@{1}.target"
+HOST_STOP_INSTFMT = "obmc-host-stop@{0}.target"
+HOST_STOP_FMT = "../${HOST_STOP_TMPL}:${HOST_STOP_TGTFMT}.requires/${HOST_STOP_INSTFMT}"
+SYSTEMD_LINK_${PN}-host += "${@compose_list_zip(d, 'HOST_STOP_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
+
 SRC_URI += "git://github.com/openbmc/phosphor-state-manager"
 SRCREV = "48696ce1a4a5b894382f0c9336a93d43f23b5fb1"