xref: /openbmc/bmcweb/src/webserver_run.cpp (revision 3b28fa2b201513be89807dfb76b47b3ca7ee3f9b)
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_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 "watchdog.hpp"
26 #include "webassets.hpp"
27 
28 #include <boost/asio/io_context.hpp>
29 #include <sdbusplus/asio/connection.hpp>
30 #include <sdbusplus/asio/object_server.hpp>
31 
32 #include <algorithm>
33 #include <memory>
34 #include <string>
35 #include <string_view>
36 
setLogLevel(const std::string & logLevel)37 static void setLogLevel(const std::string& logLevel)
38 {
39     const std::basic_string_view<char>* iter =
40         std::ranges::find(crow::mapLogLevelFromName, logLevel);
41     if (iter == crow::mapLogLevelFromName.end())
42     {
43         BMCWEB_LOG_ERROR("log-level {} not found", logLevel);
44         return;
45     }
46     crow::getBmcwebCurrentLoggingLevel() = crow::getLogLevelFromName(logLevel);
47     BMCWEB_LOG_INFO("Requested log-level change to: {}", logLevel);
48 }
49 
run()50 int run()
51 {
52     boost::asio::io_context& io = getIoContext();
53     App app;
54 
55     std::shared_ptr<sdbusplus::asio::connection> systemBus =
56         std::make_shared<sdbusplus::asio::connection>(io);
57     crow::connections::systemBus = systemBus.get();
58 
59     auto server = sdbusplus::asio::object_server(systemBus);
60 
61     std::shared_ptr<sdbusplus::asio::dbus_interface> iface =
62         server.add_interface("/xyz/openbmc_project/bmcweb",
63                              "xyz.openbmc_project.bmcweb");
64 
65     iface->register_method("SetLogLevel", setLogLevel);
66 
67     iface->initialize();
68 
69     // Load the peristent data
70     persistent_data::getConfig();
71 
72     // Static assets need to be initialized before Authorization, because auth
73     // needs to build the whitelist from the static routes
74 
75     if constexpr (BMCWEB_STATIC_HOSTING)
76     {
77         crow::webassets::requestRoutes(app);
78     }
79 
80     if constexpr (BMCWEB_KVM)
81     {
82         crow::obmc_kvm::requestRoutes(app);
83     }
84 
85     if constexpr (BMCWEB_REDFISH)
86     {
87         redfish::RedfishService::getInstance(app);
88 
89         // Create EventServiceManager instance and initialize Config
90         redfish::EventServiceManager::getInstance();
91 
92         if constexpr (BMCWEB_REDFISH_AGGREGATION)
93         {
94             // Create RedfishAggregator instance and initialize Config
95             redfish::RedfishAggregator::getInstance();
96         }
97     }
98 
99     if constexpr (BMCWEB_REST)
100     {
101         crow::dbus_monitor::requestRoutes(app);
102         crow::image_upload::requestRoutes(app);
103         crow::openbmc_mapper::requestRoutes(app);
104     }
105 
106     if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
107     {
108         crow::obmc_console::requestRoutes(app);
109     }
110 
111     crow::obmc_vm::requestRoutes(app);
112 
113     if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
114     {
115         crow::ibm_mc::requestRoutes(app);
116     }
117 
118     if constexpr (BMCWEB_GOOGLE_API)
119     {
120         crow::google_api::requestRoutes(app);
121     }
122 
123     crow::login_routes::requestRoutes(app);
124 
125     if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
126     {
127         BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
128         crow::hostname_monitor::registerHostnameSignal();
129     }
130 
131     bmcweb::registerUserRemovedSignal();
132 
133     bmcweb::ServiceWatchdog watchdog;
134 
135     app.run();
136 
137     systemBus->request_name("xyz.openbmc_project.bmcweb");
138 
139     io.run();
140 
141     crow::connections::systemBus = nullptr;
142 
143     return 0;
144 }
145