blob: a717a8dc94c135cdb8d42dd8b04327a2a7e4ba76 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous3cd70722024-04-06 09:24:01 -07003#include "webserver_run.hpp"
4
5#include "bmcweb_config.h"
6
7#include "app.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -07008#include "dbus_monitor.hpp"
9#include "dbus_singleton.hpp"
10#include "event_service_manager.hpp"
Ed Tanous3b28fa22024-09-23 14:51:55 -070011#include "google_service_root.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070012#include "hostname_monitor.hpp"
Ed Tanous3b28fa22024-09-23 14:51:55 -070013#include "ibm_management_console_rest.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070014#include "image_upload.hpp"
Ed Tanous9838eb22025-01-29 16:24:42 -080015#include "io_context_singleton.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070016#include "kvm_websocket.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070017#include "logging.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070018#include "login_routes.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070019#include "obmc_console.hpp"
20#include "openbmc_dbus_rest.hpp"
Ed Tanous3577e442025-08-19 19:34:00 -070021#include "persistent_data.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070022#include "redfish.hpp"
23#include "redfish_aggregator.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070024#include "user_monitor.hpp"
25#include "vm_websocket.hpp"
rohitpaicf9085a2025-02-24 12:33:59 +053026#include "watchdog.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070027#include "webassets.hpp"
28
Ed Tanous3cd70722024-04-06 09:24:01 -070029#include <boost/asio/io_context.hpp>
30#include <sdbusplus/asio/connection.hpp>
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070031#include <sdbusplus/asio/object_server.hpp>
Ed Tanous5b904292024-04-16 11:10:17 -070032
Ed Tanous41fe81c2024-09-02 15:08:41 -070033#include <algorithm>
Ed Tanous5b904292024-04-16 11:10:17 -070034#include <memory>
Ed Tanous41fe81c2024-09-02 15:08:41 -070035#include <string>
36#include <string_view>
Ed Tanous3cd70722024-04-06 09:24:01 -070037
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070038static void setLogLevel(const std::string& logLevel)
39{
40 const std::basic_string_view<char>* iter =
41 std::ranges::find(crow::mapLogLevelFromName, logLevel);
42 if (iter == crow::mapLogLevelFromName.end())
43 {
44 BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
45 return;
46 }
47 crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
48 BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
49}
50
Ed Tanous3cd70722024-04-06 09:24:01 -070051int run()
52{
Ed Tanous9838eb22025-01-29 16:24:42 -080053 boost::asio::io_context& io = getIoContext();
54 App app;
Ed Tanous3cd70722024-04-06 09:24:01 -070055
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070056 std::shared_ptr<sdbusplus::asio::connection> systemBus =
Ed Tanous9838eb22025-01-29 16:24:42 -080057 std::make_shared<sdbusplus::asio::connection>(io);
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070058 crow::connections::systemBus = systemBus.get();
59
60 auto server = sdbusplus::asio::object_server(systemBus);
61
62 std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
63 server.add_interface("/xyz/openbmc_project/bmcweb",
64 "xyz.openbmc_project.bmcweb");
65
66 iface->register_method("SetLogLevel", setLogLevel);
67
68 iface->initialize();
Ed Tanous3cd70722024-04-06 09:24:01 -070069
Myung Bae6136e852025-05-14 07:53:45 -040070 // Load the peristent data
71 persistent_data::getConfig();
72
Ed Tanous3cd70722024-04-06 09:24:01 -070073 // Static assets need to be initialized before Authorization, because auth
74 // needs to build the whitelist from the static routes
75
Ed Tanous25b54db2024-04-17 15:40:31 -070076 if constexpr (BMCWEB_STATIC_HOSTING)
77 {
78 crow::webassets::requestRoutes(app);
79 }
Ed Tanous3cd70722024-04-06 09:24:01 -070080
Ed Tanous25b54db2024-04-17 15:40:31 -070081 if constexpr (BMCWEB_KVM)
82 {
83 crow::obmc_kvm::requestRoutes(app);
84 }
Ed Tanous3cd70722024-04-06 09:24:01 -070085
Ed Tanous25b54db2024-04-17 15:40:31 -070086 if constexpr (BMCWEB_REDFISH)
87 {
rohitpaic1a75eb2025-01-03 19:13:36 +053088 redfish::RedfishService::getInstance(app);
Alexander Hansen6c58a032024-11-21 15:27:04 -080089
90 // Create EventServiceManager instance and initialize Config
Ed Tanous9838eb22025-01-29 16:24:42 -080091 redfish::EventServiceManager::getInstance();
Ed Tanous3cd70722024-04-06 09:24:01 -070092
Ed Tanous25b54db2024-04-17 15:40:31 -070093 if constexpr (BMCWEB_REDFISH_AGGREGATION)
94 {
95 // Create RedfishAggregator instance and initialize Config
Ed Tanous9838eb22025-01-29 16:24:42 -080096 redfish::RedfishAggregator::getInstance();
Ed Tanous25b54db2024-04-17 15:40:31 -070097 }
98 }
Ed Tanous3cd70722024-04-06 09:24:01 -070099
Ed Tanous25b54db2024-04-17 15:40:31 -0700100 if constexpr (BMCWEB_REST)
101 {
102 crow::dbus_monitor::requestRoutes(app);
103 crow::image_upload::requestRoutes(app);
104 crow::openbmc_mapper::requestRoutes(app);
105 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700106
Ed Tanous25b54db2024-04-17 15:40:31 -0700107 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
108 {
109 crow::obmc_console::requestRoutes(app);
110 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700111
Ed Tanous3cd70722024-04-06 09:24:01 -0700112 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700113
Ed Tanous25b54db2024-04-17 15:40:31 -0700114 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
115 {
116 crow::ibm_mc::requestRoutes(app);
117 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700118
Ed Tanous25b54db2024-04-17 15:40:31 -0700119 if constexpr (BMCWEB_GOOGLE_API)
120 {
121 crow::google_api::requestRoutes(app);
122 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700123
Ed Tanous3cd70722024-04-06 09:24:01 -0700124 crow::login_routes::requestRoutes(app);
125
Ed Tanous25b54db2024-04-17 15:40:31 -0700126 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700127 {
128 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
129 crow::hostname_monitor::registerHostnameSignal();
130 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700131
132 bmcweb::registerUserRemovedSignal();
133
rohitpaicf9085a2025-02-24 12:33:59 +0530134 bmcweb::ServiceWatchdog watchdog;
135
Ed Tanous3cd70722024-04-06 09:24:01 -0700136 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700137
138 systemBus->request_name("xyz.openbmc_project.bmcweb");
139
Ed Tanous9838eb22025-01-29 16:24:42 -0800140 io.run();
Ed Tanous3cd70722024-04-06 09:24:01 -0700141
142 crow::connections::systemBus = nullptr;
143
Ed Tanous3cd70722024-04-06 09:24:01 -0700144 return 0;
145}