xref: /openbmc/bmcweb/src/webserver_run.cpp (revision 9838eb20341568971b9543c2187372d20daf64aa)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #include "webserver_run.hpp"
4 
5 #include "bmcweb_config.h"
6 
7 #include "app.hpp"
8 #include "dbus_monitor.hpp"
9 #include "dbus_singleton.hpp"
10 #include "event_service_manager.hpp"
11 #include "google/google_service_root.hpp"
12 #include "hostname_monitor.hpp"
13 #include "ibm/management_console_rest.hpp"
14 #include "image_upload.hpp"
15 #include "io_context_singleton.hpp"
16 #include "kvm_websocket.hpp"
17 #include "logging.hpp"
18 #include "login_routes.hpp"
19 #include "obmc_console.hpp"
20 #include "openbmc_dbus_rest.hpp"
21 #include "redfish.hpp"
22 #include "redfish_aggregator.hpp"
23 #include "user_monitor.hpp"
24 #include "vm_websocket.hpp"
25 #include "webassets.hpp"
26 
27 #include <boost/asio/io_context.hpp>
28 #include <sdbusplus/asio/connection.hpp>
29 #include <sdbusplus/asio/object_server.hpp>
30 
31 #include <algorithm>
32 #include <memory>
33 #include <string>
34 #include <string_view>
35 
setLogLevel(const std::string & logLevel)36 static void setLogLevel(const std::string& logLevel)
37 {
38     const std::basic_string_view<char>* iter =
39         std::ranges::find(crow::mapLogLevelFromName, logLevel);
40     if (iter == crow::mapLogLevelFromName.end())
41     {
42         BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
43         return;
44     }
45     crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
46     BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
47 }
48 
run()49 int run()
50 {
51     boost::asio::io_context& io = getIoContext();
52     App app;
53 
54     std::shared_ptr<sdbusplus::asio::connection> systemBus =
55         std::make_shared<sdbusplus::asio::connection>(io);
56     crow::connections::systemBus = systemBus.get();
57 
58     auto server = sdbusplus::asio::object_server(systemBus);
59 
60     std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
61         server.add_interface("/xyz/openbmc_project/bmcweb",
62                              "xyz.openbmc_project.bmcweb");
63 
64     iface->register_method("SetLogLevel", setLogLevel);
65 
66     iface->initialize();
67 
68     // Static assets need to be initialized before Authorization, because auth
69     // needs to build the whitelist from the static routes
70 
71     if constexpr (BMCWEB_STATIC_HOSTING)
72     {
73         crow::webassets::requestRoutes(app);
74     }
75 
76     if constexpr (BMCWEB_KVM)
77     {
78         crow::obmc_kvm::requestRoutes(app);
79     }
80 
81     if constexpr (BMCWEB_REDFISH)
82     {
83         redfish::RedfishService redfish(app);
84 
85         // Create EventServiceManager instance and initialize Config
86         redfish::EventServiceManager::getInstance();
87 
88         if constexpr (BMCWEB_REDFISH_AGGREGATION)
89         {
90             // Create RedfishAggregator instance and initialize Config
91             redfish::RedfishAggregator::getInstance();
92         }
93     }
94 
95     if constexpr (BMCWEB_REST)
96     {
97         crow::dbus_monitor::requestRoutes(app);
98         crow::image_upload::requestRoutes(app);
99         crow::openbmc_mapper::requestRoutes(app);
100     }
101 
102     if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
103     {
104         crow::obmc_console::requestRoutes(app);
105     }
106 
107     crow::obmc_vm::requestRoutes(app);
108 
109     if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
110     {
111         crow::ibm_mc::requestRoutes(app);
112     }
113 
114     if constexpr (BMCWEB_GOOGLE_API)
115     {
116         crow::google_api::requestRoutes(app);
117     }
118 
119     crow::login_routes::requestRoutes(app);
120 
121     if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
122     {
123         BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
124         crow::hostname_monitor::registerHostnameSignal();
125     }
126 
127     bmcweb::registerUserRemovedSignal();
128 
129     app.run();
130 
131     systemBus->request_name("xyz.openbmc_project.bmcweb");
132 
133     io.run();
134 
135     crow::connections::systemBus = nullptr;
136 
137     return 0;
138 }
139