Only run power restore on AC losses
Added a meson build option that allows the customer to enable automatic
power restore policy only for AC losses where the chassis power was
on prior to a BMC reset(and off when it comes back online).
The default is set to 'false' which provides the standard behavior of
APR which is to always run APR on an BMC reboot.
If the option 'only-run-apr-on-power-loss' is 'true' then APR is only
run in the case of the chassis losing power. AC power losses trigger the
creation of a file called 'chassis@0-lost-power' that identifies an
AC power loss has occurred. This generated file can be found in the
directory '/run/openbmc/'.
Tested:
- Verified that when built with option 'only-run-apr-on-power-loss'
set to false(default) that APR was ran.
- Verified that when built with option 'only-run-apr-on-power-loss'
set to true that apr was not ran when a power loss did not occur.
- Verified that when built with option 'only-run-apr-on-power-loss'
set to true that apr was only ran when a power loss occured.
Jun 08 01:55:13 p10bmc phosphor-chassis-state-manager[3009]:
The system suffered a power blackout.
root@p10bmc:/lib/systemd/system# ls /run/openbmc/
chassis@0-lost-power
Signed-off-by: Corey Hardesty <corey.hardesty@icloud.com>
Change-Id: Iac37761416d699e3a469936e00868a8d9b6dfdb1
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 9c16ea0..9bfdb95 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -7,6 +7,7 @@
#include "xyz/openbmc_project/State/Shutdown/Power/error.hpp"
#include <fmt/format.h>
+#include <fmt/printf.h>
#include <cereal/archives/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
@@ -154,9 +155,18 @@
"Chassis power was on before the BMC reboot and it is off now");
// Reset host sensors since system is off now
+ // TODO: when CHASSIS_BLACKOUT_TGT will include this service
+ // Needs to be removed when the blackout target is merged
startUnit(fmt::format(RESET_HOST_SENSORS_SVC_FMT, id));
setStateChangeTime();
+ // Generate file indicating AC loss occurred
+ std::string chassisLostPowerFileFmt =
+ fmt::sprintf(CHASSIS_LOST_POWER_FILE, id);
+ fs::create_directories(BASE_FILE_DIR);
+ fs::path chassisPowerLossFile{chassisLostPowerFileFmt};
+ std::ofstream outfile(chassisPowerLossFile);
+ outfile.close();
// 0 indicates pinhole reset. 1 is NOT pinhole reset
if (phosphor::state::manager::utils::getGpioValue(