Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 1 | #include "webserver_run.hpp" |
| 2 | |
| 3 | #include "bmcweb_config.h" |
| 4 | |
| 5 | #include "app.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 6 | #include "dbus_monitor.hpp" |
| 7 | #include "dbus_singleton.hpp" |
| 8 | #include "event_service_manager.hpp" |
| 9 | #include "google/google_service_root.hpp" |
| 10 | #include "hostname_monitor.hpp" |
| 11 | #include "ibm/management_console_rest.hpp" |
| 12 | #include "image_upload.hpp" |
| 13 | #include "kvm_websocket.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 14 | #include "logging.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 15 | #include "login_routes.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 16 | #include "obmc_console.hpp" |
| 17 | #include "openbmc_dbus_rest.hpp" |
| 18 | #include "redfish.hpp" |
| 19 | #include "redfish_aggregator.hpp" |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 20 | #include "user_monitor.hpp" |
| 21 | #include "vm_websocket.hpp" |
| 22 | #include "webassets.hpp" |
| 23 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 24 | #include <boost/asio/io_context.hpp> |
| 25 | #include <sdbusplus/asio/connection.hpp> |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 26 | #include <sdbusplus/asio/object_server.hpp> |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 27 | |
Ed Tanous | 41fe81c | 2024-09-02 15:08:41 -0700 | [diff] [blame] | 28 | #include <algorithm> |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 29 | #include <memory> |
Ed Tanous | 41fe81c | 2024-09-02 15:08:41 -0700 | [diff] [blame] | 30 | #include <string> |
| 31 | #include <string_view> |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 32 | |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 33 | static void setLogLevel(const std::string& logLevel) |
| 34 | { |
| 35 | const std::basic_string_view<char>* iter = |
| 36 | std::ranges::find(crow::mapLogLevelFromName, logLevel); |
| 37 | if (iter == crow::mapLogLevelFromName.end()) |
| 38 | { |
| 39 | BMCWEB_LOG_ERROR("log-level {} not found", logLevel); |
| 40 | return; |
| 41 | } |
| 42 | crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel); |
| 43 | BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel); |
| 44 | } |
| 45 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 46 | int run() |
| 47 | { |
| 48 | auto io = std::make_shared<boost::asio::io_context>(); |
| 49 | App app(io); |
| 50 | |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 51 | std::shared_ptr<sdbusplus::asio::connection> systemBus = |
| 52 | std::make_shared<sdbusplus::asio::connection>(*io); |
| 53 | crow::connections::systemBus = systemBus.get(); |
| 54 | |
| 55 | auto server = sdbusplus::asio::object_server(systemBus); |
| 56 | |
| 57 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface = |
| 58 | server.add_interface("/xyz/openbmc_project/bmcweb", |
| 59 | "xyz.openbmc_project.bmcweb"); |
| 60 | |
| 61 | iface->register_method("SetLogLevel", setLogLevel); |
| 62 | |
| 63 | iface->initialize(); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 64 | |
| 65 | // Static assets need to be initialized before Authorization, because auth |
| 66 | // needs to build the whitelist from the static routes |
| 67 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 68 | if constexpr (BMCWEB_STATIC_HOSTING) |
| 69 | { |
| 70 | crow::webassets::requestRoutes(app); |
| 71 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 72 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 73 | if constexpr (BMCWEB_KVM) |
| 74 | { |
| 75 | crow::obmc_kvm::requestRoutes(app); |
| 76 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 77 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 78 | if constexpr (BMCWEB_REDFISH) |
| 79 | { |
| 80 | redfish::RedfishService redfish(app); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 81 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 82 | // Create EventServiceManager instance and initialize Config |
| 83 | redfish::EventServiceManager::getInstance(&*io); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 84 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 85 | if constexpr (BMCWEB_REDFISH_AGGREGATION) |
| 86 | { |
| 87 | // Create RedfishAggregator instance and initialize Config |
| 88 | redfish::RedfishAggregator::getInstance(&*io); |
| 89 | } |
| 90 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 91 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 92 | if constexpr (BMCWEB_REST) |
| 93 | { |
| 94 | crow::dbus_monitor::requestRoutes(app); |
| 95 | crow::image_upload::requestRoutes(app); |
| 96 | crow::openbmc_mapper::requestRoutes(app); |
| 97 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 98 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 99 | if constexpr (BMCWEB_HOST_SERIAL_SOCKET) |
| 100 | { |
| 101 | crow::obmc_console::requestRoutes(app); |
| 102 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 103 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 104 | crow::obmc_vm::requestRoutes(app); |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 105 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 106 | if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE) |
| 107 | { |
| 108 | crow::ibm_mc::requestRoutes(app); |
| 109 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 110 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 111 | if constexpr (BMCWEB_GOOGLE_API) |
| 112 | { |
| 113 | crow::google_api::requestRoutes(app); |
| 114 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 115 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 116 | crow::login_routes::requestRoutes(app); |
| 117 | |
Jayaprakash Mutyala | ff0a088 | 2024-06-26 09:08:53 +0000 | [diff] [blame] | 118 | if constexpr (!BMCWEB_REDFISH_DBUS_LOG) |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 119 | { |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 120 | int rc = redfish::EventServiceManager::startEventLogMonitor(*io); |
| 121 | if (rc != 0) |
| 122 | { |
| 123 | BMCWEB_LOG_ERROR("Redfish event handler setup failed..."); |
| 124 | return rc; |
| 125 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 126 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 127 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 128 | if constexpr (!BMCWEB_INSECURE_DISABLE_SSL) |
Ed Tanous | 8db8374 | 2024-04-13 09:11:15 -0700 | [diff] [blame] | 129 | { |
| 130 | BMCWEB_LOG_INFO("Start Hostname Monitor Service..."); |
| 131 | crow::hostname_monitor::registerHostnameSignal(); |
| 132 | } |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 133 | |
| 134 | bmcweb::registerUserRemovedSignal(); |
| 135 | |
| 136 | app.run(); |
Aushim Nagarkatti | bd1299b | 2024-08-12 17:11:04 -0700 | [diff] [blame] | 137 | |
| 138 | systemBus->request_name("xyz.openbmc_project.bmcweb"); |
| 139 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 140 | io->run(); |
| 141 | |
| 142 | crow::connections::systemBus = nullptr; |
| 143 | |
Ed Tanous | 9ed3f90 | 2024-07-15 17:54:31 -0700 | [diff] [blame] | 144 | // TODO(ed) Make event log monitor an RAII object instead of global vars |
| 145 | redfish::EventServiceManager::stopEventLogMonitor(); |
| 146 | |
Ed Tanous | 3cd7072 | 2024-04-06 09:24:01 -0700 | [diff] [blame] | 147 | return 0; |
| 148 | } |