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