xref: /openbmc/bmcweb/src/webserver_run.cpp (revision 720c9898)
1 #include "webserver_run.hpp"
2 
3 #include "bmcweb_config.h"
4 
5 #include "app.hpp"
6 #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"
14 #include "logging.hpp"
15 #include "login_routes.hpp"
16 #include "obmc_console.hpp"
17 #include "openbmc_dbus_rest.hpp"
18 #include "redfish.hpp"
19 #include "redfish_aggregator.hpp"
20 #include "user_monitor.hpp"
21 #include "vm_websocket.hpp"
22 #include "webassets.hpp"
23 
24 #include <boost/asio/io_context.hpp>
25 #include <sdbusplus/asio/connection.hpp>
26 
27 #include <memory>
28 
29 int run()
30 {
31     auto io = std::make_shared<boost::asio::io_context>();
32     App app(io);
33 
34     sdbusplus::asio::connection systemBus(*io);
35     crow::connections::systemBus = &systemBus;
36 
37     // Static assets need to be initialized before Authorization, because auth
38     // needs to build the whitelist from the static routes
39 
40     if constexpr (BMCWEB_STATIC_HOSTING)
41     {
42         crow::webassets::requestRoutes(app);
43     }
44 
45     if constexpr (BMCWEB_KVM)
46     {
47         crow::obmc_kvm::requestRoutes(app);
48     }
49 
50     if constexpr (BMCWEB_REDFISH)
51     {
52         redfish::RedfishService redfish(app);
53 
54         // Create EventServiceManager instance and initialize Config
55         redfish::EventServiceManager::getInstance(&*io);
56 
57         if constexpr (BMCWEB_REDFISH_AGGREGATION)
58         {
59             // Create RedfishAggregator instance and initialize Config
60             redfish::RedfishAggregator::getInstance(&*io);
61         }
62     }
63 
64     if constexpr (BMCWEB_REST)
65     {
66         crow::dbus_monitor::requestRoutes(app);
67         crow::image_upload::requestRoutes(app);
68         crow::openbmc_mapper::requestRoutes(app);
69     }
70 
71     if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
72     {
73         crow::obmc_console::requestRoutes(app);
74     }
75 
76     crow::obmc_vm::requestRoutes(app);
77 
78     if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
79     {
80         crow::ibm_mc::requestRoutes(app);
81     }
82 
83     if constexpr (BMCWEB_GOOGLE_API)
84     {
85         crow::google_api::requestRoutes(app);
86     }
87 
88     crow::login_routes::requestRoutes(app);
89 
90     if constexpr (BMCWEB_REDFISH_DBUS_LOG)
91     {
92         int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
93         if (rc != 0)
94         {
95             BMCWEB_LOG_ERROR("Redfish event handler setup failed...");
96             return rc;
97         }
98     }
99 
100     if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
101     {
102         BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
103         crow::hostname_monitor::registerHostnameSignal();
104     }
105 
106     bmcweb::registerUserRemovedSignal();
107 
108     app.run();
109     io->run();
110 
111     crow::connections::systemBus = nullptr;
112 
113     return 0;
114 }
115