blob: eee1fab60f17d8b5b5f1ef383c91f1eff917f000 [file] [log] [blame]
Jason M. Billsd711cc82020-12-04 16:46:39 -08001/*
2// Copyright (c) 2021 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#include <sdbusplus/asio/object_server.hpp>
18
19#include <iostream>
20
21namespace host_error_monitor
22{
23bool hostIsOff();
24
25void startPowerCycle(std::shared_ptr<sdbusplus::asio::connection> conn)
26{
27 conn->async_method_call(
28 [](boost::system::error_code ec) {
29 if (ec)
30 {
31 std::cerr << "failed to set Chassis State\n";
32 }
33 },
34 "xyz.openbmc_project.State.Chassis",
35 "/xyz/openbmc_project/state/chassis0",
36 "org.freedesktop.DBus.Properties", "Set",
37 "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition",
38 std::variant<std::string>{
39 "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"});
40}
41
42void startWarmReset(std::shared_ptr<sdbusplus::asio::connection> conn)
43{
44 conn->async_method_call(
45 [](boost::system::error_code ec) {
46 if (ec)
47 {
48 std::cerr << "failed to set Host State\n";
49 }
50 },
51 "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
52 "org.freedesktop.DBus.Properties", "Set",
53 "xyz.openbmc_project.State.Host", "RequestedHostTransition",
54 std::variant<std::string>{
55 "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"});
56}
57
58void startCrashdumpAndRecovery(
59 std::shared_ptr<sdbusplus::asio::connection> conn, bool recoverSystem,
60 const std::string& triggerType)
61{
62 static bool recover;
63 recover = recoverSystem;
64 std::cerr << "Starting crashdump\n";
65 static std::shared_ptr<sdbusplus::bus::match::match> crashdumpCompleteMatch;
66
67 if (!crashdumpCompleteMatch)
68 {
69 crashdumpCompleteMatch = std::make_shared<sdbusplus::bus::match::match>(
70 *conn,
71 "type='signal',interface='com.intel.crashdump.Stored',member='"
72 "CrashdumpComplete'",
73 [conn](sdbusplus::message::message& msg) {
74 std::cerr << "Crashdump completed\n";
75 if (recover)
76 {
77 std::cerr << "Recovering the system\n";
78 startWarmReset(conn);
79 }
80 crashdumpCompleteMatch.reset();
81 });
82 }
83
84 conn->async_method_call(
85 [](boost::system::error_code ec) {
86 if (ec)
87 {
88 std::cerr << "failed to start Crashdump\n";
89 }
90 },
91 "com.intel.crashdump", "/com/intel/crashdump",
92 "com.intel.crashdump.Stored", "GenerateStoredLog", triggerType);
93}
94
95} // namespace host_error_monitor