blob: eddfc5b890080507c0edbc7a6aa9489ad4740d7f [file] [log] [blame]
Ed Tanous3cd70722024-04-06 09:24:01 -07001#include "webserver_run.hpp"
2
3#include "bmcweb_config.h"
4
5#include "app.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -07006#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 Tanous5b904292024-04-16 11:10:17 -070014#include "logging.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070015#include "login_routes.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070016#include "obmc_console.hpp"
17#include "openbmc_dbus_rest.hpp"
18#include "redfish.hpp"
19#include "redfish_aggregator.hpp"
Ed Tanous3cd70722024-04-06 09:24:01 -070020#include "user_monitor.hpp"
21#include "vm_websocket.hpp"
22#include "webassets.hpp"
23
Ed Tanous3cd70722024-04-06 09:24:01 -070024#include <boost/asio/io_context.hpp>
25#include <sdbusplus/asio/connection.hpp>
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070026#include <sdbusplus/asio/object_server.hpp>
Ed Tanous5b904292024-04-16 11:10:17 -070027
Ed Tanous41fe81c2024-09-02 15:08:41 -070028#include <algorithm>
Ed Tanous5b904292024-04-16 11:10:17 -070029#include <memory>
Ed Tanous41fe81c2024-09-02 15:08:41 -070030#include <string>
31#include <string_view>
Ed Tanous3cd70722024-04-06 09:24:01 -070032
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070033static 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 Tanous3cd70722024-04-06 09:24:01 -070046int run()
47{
48 auto io = std::make_shared<boost::asio::io_context>();
49 App app(io);
50
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -070051 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 Tanous3cd70722024-04-06 09:24:01 -070064
65 // Static assets need to be initialized before Authorization, because auth
66 // needs to build the whitelist from the static routes
67
Ed Tanous25b54db2024-04-17 15:40:31 -070068 if constexpr (BMCWEB_STATIC_HOSTING)
69 {
70 crow::webassets::requestRoutes(app);
71 }
Ed Tanous3cd70722024-04-06 09:24:01 -070072
Ed Tanous25b54db2024-04-17 15:40:31 -070073 if constexpr (BMCWEB_KVM)
74 {
75 crow::obmc_kvm::requestRoutes(app);
76 }
Ed Tanous3cd70722024-04-06 09:24:01 -070077
Ed Tanous25b54db2024-04-17 15:40:31 -070078 if constexpr (BMCWEB_REDFISH)
79 {
80 redfish::RedfishService redfish(app);
Ed Tanous2ac69852024-11-22 11:47:08 -080081 if constexpr (!BMCWEB_REDFISH_DBUS_LOG)
82 {
83 redfish::EventServiceManager::getInstance(&*io);
84 }
Ed Tanous3cd70722024-04-06 09:24:01 -070085
Ed Tanous25b54db2024-04-17 15:40:31 -070086 if constexpr (BMCWEB_REDFISH_AGGREGATION)
87 {
88 // Create RedfishAggregator instance and initialize Config
89 redfish::RedfishAggregator::getInstance(&*io);
90 }
91 }
Ed Tanous3cd70722024-04-06 09:24:01 -070092
Ed Tanous25b54db2024-04-17 15:40:31 -070093 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 Tanous3cd70722024-04-06 09:24:01 -070099
Ed Tanous25b54db2024-04-17 15:40:31 -0700100 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
101 {
102 crow::obmc_console::requestRoutes(app);
103 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700104
Ed Tanous3cd70722024-04-06 09:24:01 -0700105 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -0700106
Ed Tanous25b54db2024-04-17 15:40:31 -0700107 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
108 {
109 crow::ibm_mc::requestRoutes(app);
110 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700111
Ed Tanous25b54db2024-04-17 15:40:31 -0700112 if constexpr (BMCWEB_GOOGLE_API)
113 {
114 crow::google_api::requestRoutes(app);
115 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700116
Ed Tanous3cd70722024-04-06 09:24:01 -0700117 crow::login_routes::requestRoutes(app);
118
Ed Tanous25b54db2024-04-17 15:40:31 -0700119 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700120 {
121 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
122 crow::hostname_monitor::registerHostnameSignal();
123 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700124
125 bmcweb::registerUserRemovedSignal();
126
127 app.run();
Aushim Nagarkattibd1299b2024-08-12 17:11:04 -0700128
129 systemBus->request_name("xyz.openbmc_project.bmcweb");
130
Ed Tanous3cd70722024-04-06 09:24:01 -0700131 io->run();
132
133 crow::connections::systemBus = nullptr;
134
Ed Tanous3cd70722024-04-06 09:24:01 -0700135 return 0;
136}