meta-hpe: dl385-g11 power supplies monitoring
Change-Id: I081bba56bc4a9c50044aa5a1625a8d586b4bea8a
Signed-off-by: Andrew Neyland <andrew.neyland@hpe.com>
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service
new file mode 100644
index 0000000..79729bf
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=DL360 power supply 1 monitoring
+After=dbus.service
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=startMonitoring1.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1.json b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1.json
new file mode 100644
index 0000000..0487ed6
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1.json
@@ -0,0 +1,10 @@
+[
+ {
+ "Name": "PowerGoodUp",
+ "LineName": "PSU1_INST",
+ "EventMon": "BOTH",
+ "TargetRising": "psu1up.service",
+ "TargetFalling": "psu1down.service",
+ "Continue": true
+ }
+]
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service
new file mode 100644
index 0000000..ec01cca
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PSU1 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 1 down
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service
new file mode 100644
index 0000000..693fbdd
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PSU1 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 1 up
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service
new file mode 100644
index 0000000..43b96a6
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=DL360 power supply 2 monitoring
+After=dbus.service
+
+[Service]
+Restart=always
+RestartSec=5
+ExecStart=startMonitoring2.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2.json b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2.json
new file mode 100644
index 0000000..8c39009
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2.json
@@ -0,0 +1,10 @@
+[
+ {
+ "Name": "psu2",
+ "LineName": "PSU2_INST",
+ "EventMon": "BOTH",
+ "TargetRising": "psu2up.service",
+ "TargetFalling": "psu2down.service",
+ "Continue": true
+ }
+]
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service
new file mode 100644
index 0000000..cc93a2e
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PSU2 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 2 down
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service
new file mode 100644
index 0000000..77009d3
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE DL360 PSU2 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 2 up
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psus-manager.sh b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psus-manager.sh
new file mode 100644
index 0000000..d654dc3
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/psus-manager.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# we need to restart FRU service and PSU Monitor everything else shall be ok
+systemctl stop xyz.openbmc_project.psusensor.service
+systemctl stop xyz.openbmc_project.GxpFruDevice.service
+
+systemctl start xyz.openbmc_project.GxpFruDevice.service
+systemctl start xyz.openbmc_project.psusensor.service
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring1.sh b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring1.sh
new file mode 100644
index 0000000..5d0c101
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring1.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+myaddress=$(gpiofind PSU1_INST)
+state=$(gpioget "$myaddress")
+if [ "r$state" = "r1" ]
+then
+ psus-manager 1 up
+else
+ psus-manager 1 down
+fi
+/usr/bin/phosphor-multi-gpio-monitor --config /usr/share/gpios/psu1.json
diff --git a/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh
new file mode 100644
index 0000000..279e51f
--- /dev/null
+++ b/meta-hpe/meta-dl385-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+#!/bin/sh
+myaddress=$(gpiofind PSU2_INST)
+state=$(gpioget "$myaddress")
+if [ "r$state" = "r1" ]
+then
+ psus-manager 2 up
+else
+ psus-manager 2 down
+fi
+/usr/bin/phosphor-multi-gpio-monitor --config /usr/share/gpios/psu2.json