move chassis power services to phosphor-state-manager
Move the generic services which are used to power on and off the chassis
into phosphor-state-manager. This will make the use of
phosphor-state-manager for chassis power control more straightforward.
These services are directly copied from openbmc/openbmc/
meta-phosphor/recipes-phosphor/chassis/obmc-op-control-power/ and
renamed to match with the existing naming conventions.
The only change to these files was if a Wants/Before/After service name
was changing as a part of this.
A follow on commit will improve some of the Description fields.
The following email has more details on this change:
https://lists.ozlabs.org/pipermail/openbmc/2022-November/032457.html
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I35d555139897cf58a26e36d1558ab7f5225d34bd
diff --git a/service_files/meson.build b/service_files/meson.build
index 18e33ea..26c95c8 100644
--- a/service_files/meson.build
+++ b/service_files/meson.build
@@ -1,7 +1,12 @@
unit_files = [
'phosphor-systemd-target-monitor.service',
'phosphor-discover-system-state@.service',
+ 'obmc-power-start@.service',
+ 'obmc-power-stop@.service',
+ 'obmc-powered-off@.service',
'phosphor-reboot-host@.service',
+ 'phosphor-reset-chassis-on@.service',
+ 'phosphor-reset-chassis-running@.service',
'phosphor-reset-host-reboot-attempts@.service',
'phosphor-reset-host-recovery@.service',
'phosphor-reset-host-running@.service',
diff --git a/service_files/obmc-power-start@.service b/service_files/obmc-power-start@.service
new file mode 100644
index 0000000..10d4a3b
--- /dev/null
+++ b/service_files/obmc-power-start@.service
@@ -0,0 +1,20 @@
+[Unit]
+Description=Start Power%i
+Wants=obmc-power-start@%i.target
+Before=obmc-power-start@%i.target
+Wants=obmc-power-start-pre@%i.target
+After=obmc-power-start-pre@%i.target
+After=obmc-fan-control.target
+Wants=mapper-wait@-org-openbmc-control-power%i.service
+After=mapper-wait@-org-openbmc-control-power%i.service
+Conflicts=obmc-chassis-poweroff@%i.target
+ConditionPathExists=!/run/openbmc/chassis@%i-on
+
+[Service]
+RemainAfterExit=yes
+Type=oneshot
+ExecStart=/bin/sh -c "busctl call `mapper get-service /org/openbmc/control/power%i` /org/openbmc/control/power%i org.openbmc.control.Power setPowerState i 1"
+SyslogIdentifier=phosphor-power-start
+
+[Install]
+WantedBy=obmc-host-start@%i.target
diff --git a/service_files/obmc-power-stop@.service b/service_files/obmc-power-stop@.service
new file mode 100644
index 0000000..e5e821a
--- /dev/null
+++ b/service_files/obmc-power-stop@.service
@@ -0,0 +1,17 @@
+[Unit]
+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
+Conflicts=obmc-chassis-poweron@%i.target
+
+[Service]
+RemainAfterExit=yes
+ExecStart=/bin/sh -c "busctl call `mapper get-service /org/openbmc/control/power%i` /org/openbmc/control/power%i org.openbmc.control.Power setPowerState i 0"
+SyslogIdentifier=obmc-power-stop
+
+[Install]
+WantedBy=obmc-host-stop@%i.target
diff --git a/service_files/obmc-powered-off@.service b/service_files/obmc-powered-off@.service
new file mode 100644
index 0000000..434e0da
--- /dev/null
+++ b/service_files/obmc-powered-off@.service
@@ -0,0 +1,20 @@
+[Unit]
+Description=Power is off to chassis%i
+After=phosphor-wait-power-off@%i.service
+Requires=phosphor-wait-power-off@%i.service
+
+[Service]
+RemainAfterExit=no
+# systemd starts all wanted targets in parallel and a Conflict
+# statement will resolve itself when the target starts, not when
+# completes. Some services have a requirement to stop
+# once power is off. The solution is to create a new target,
+# obmc-chassis-powered-off@.target, that is started after it is
+# verified that power has been removed from the chassis. Then
+# services may conflict with this target to ensure they
+# are stopped at the appropriate time.
+ExecStart=/bin/systemctl start obmc-chassis-powered-off@%i.target
+
+
+[Install]
+WantedBy=obmc-chassis-poweroff@%i.target
diff --git a/service_files/phosphor-reset-chassis-on@.service b/service_files/phosphor-reset-chassis-on@.service
new file mode 100644
index 0000000..d7555b7
--- /dev/null
+++ b/service_files/phosphor-reset-chassis-on@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Start chassis%i on after BMC reset
+Requires=phosphor-reset-chassis-running@%i.service
+After=phosphor-reset-chassis-running@%i.service
+After=obmc-power-reset-on@%i.target
+Requires=obmc-power-reset-on@%i.target
+ConditionPathExists=/run/openbmc/chassis@%i-on
+
+[Service]
+RemainAfterExit=no
+ExecStart=/bin/systemctl start obmc-chassis-poweron@%i.target
+
+
+[Install]
+WantedBy=obmc-chassis-powerreset@%i.target
diff --git a/service_files/phosphor-reset-chassis-running@.service b/service_files/phosphor-reset-chassis-running@.service
new file mode 100644
index 0000000..381f89d
--- /dev/null
+++ b/service_files/phosphor-reset-chassis-running@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Check Chassis%i pgood and create a file to indicate it
+Wants=mapper-wait@-org-openbmc-control-power%i.service
+After=mapper-wait@-org-openbmc-control-power%i.service
+Wants=obmc-power-reset-on@%i.target
+Before=obmc-power-reset-on@%i.target
+Conflicts=obmc-chassis-poweroff@%i.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/bin/sh -c "if [ $(busctl get-property `mapper get-service /org/openbmc/control/power%i` /org/openbmc/control/power%i org.openbmc.control.Power pgood | sed 's/i\s*[1]/on/' | grep on | wc -l) != 0 ]; then mkdir -p /run/openbmc/ && touch /run/openbmc/chassis@%i-on; fi"
+
+[Install]
+WantedBy=obmc-chassis-powerreset@%i.target