meta-hpe: rl300-g11 add power supply monitoring recipe
Change-Id: Ib6071c1b6d4df4a1138e0cecf29787c5edcea23c
Signed-off-by: Charles Kearney <charles.kearney@hpe.com>
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service
new file mode 100644
index 0000000..c87921d
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1-monitoring.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=RL300 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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1.json b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1.json
new file mode 100644
index 0000000..655180f
--- /dev/null
+++ b/meta-hpe/meta-rl300-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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service
new file mode 100644
index 0000000..6785901
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1down.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE RL300 PSU1 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 1 down
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service
new file mode 100644
index 0000000..54e4633
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu1up.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE RL300 PSU1 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 1 up
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service
new file mode 100644
index 0000000..1093585
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2-monitoring.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=RL300 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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2.json b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2.json
new file mode 100644
index 0000000..e0a7858
--- /dev/null
+++ b/meta-hpe/meta-rl300-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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service
new file mode 100644
index 0000000..f82256a
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2down.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE RL300 PSU2 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 2 down
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service
new file mode 100644
index 0000000..ce104e0
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psu2up.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=HPE RL300 PSU2 Manager
+
+[Service]
+ExecStart=/usr/bin/psus-manager.sh 2 up
+
+[Install]
+# WantedBy=multi-user.target
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psus-manager.sh b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/psus-manager.sh
new file mode 100644
index 0000000..d654dc3
--- /dev/null
+++ b/meta-hpe/meta-rl300-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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring1.sh b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring1.sh
new file mode 100644
index 0000000..5d0c101
--- /dev/null
+++ b/meta-hpe/meta-rl300-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-rl300-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh
new file mode 100644
index 0000000..6afae93
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/files/startMonitoring2.sh
@@ -0,0 +1,10 @@
+#!/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
diff --git a/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/power-supplies-monitoring.bb b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/power-supplies-monitoring.bb
new file mode 100644
index 0000000..1b035c6
--- /dev/null
+++ b/meta-hpe/meta-rl300-g11/recipes-hpe/power-supplies-monitoring/power-supplies-monitoring.bb
@@ -0,0 +1,30 @@
+inherit obmc-phosphor-systemd
+SUMMARY = "Power Supplies monitoring for HPE RL300 Gen11"
+SYSTEMD_AUTO_ENABLE = "enable"
+SYSTEMD_SERVICE:${PN} = "psu2-monitoring.service psu1-monitoring.service psu2up.service psu2down.service psu1down.service psu1up.service"
+SRC_URI:append = " file://psu2-monitoring.service file://psu1-monitoring.service file://psus-manager.sh file://psu2up.service file://psu2down.service file://psu1down.service file://psu1up.service file://psu2.json file://psu1.json file://startMonitoring1.sh file://startMonitoring2.sh"
+
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${WORKDIR}/LICENSE;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+IMAGE_INSTALL += "power-supplies-monitoring "
+
+FILES:${PN} = "/usr/share/gpios/* /usr/bin/* /etc/system/*"
+
+do_install:append() {
+ install -d ${D}${sysconfdir}/system/
+ install -d ${D}/usr/share/gpios
+ install -d ${D}/usr/bin
+ install -m 0644 ${WORKDIR}/psu1.json ${D}/usr/share/gpios/psu1.json
+ install -m 0644 ${WORKDIR}/psu2.json ${D}/usr/share/gpios/psu2.json
+ install -m 0644 ${WORKDIR}/psu2-monitoring.service ${D}${sysconfdir}/system/psu2-monitoring.service
+ install -m 0644 ${WORKDIR}/psu1-monitoring.service ${D}${sysconfdir}/system/psu1-monitoring.service
+ install -m 0644 ${WORKDIR}/psu2up.service ${D}${sysconfdir}/system/psu2up.service
+ install -m 0644 ${WORKDIR}/psu1up.service ${D}${sysconfdir}/system/psu1up.service
+ install -m 0644 ${WORKDIR}/psu1down.service ${D}${sysconfdir}/system/psu1down.service
+ install -m 0644 ${WORKDIR}/psu1down.service ${D}${sysconfdir}/system/psu1down.service
+ install -m 0755 ${WORKDIR}/psus-manager.sh ${D}/usr/bin/psus-manager.sh
+ install -m 0755 ${WORKDIR}/startMonitoring1.sh ${D}/usr/bin/startMonitoring1.sh
+ install -m 0755 ${WORKDIR}/startMonitoring2.sh ${D}/usr/bin/startMonitoring2.sh
+}