blob: 50136699e9c507b8a7fc2152b6f475eced6093a0 [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>
Ed Tanous5b904292024-04-16 11:10:17 -070026
27#include <memory>
Ed Tanous3cd70722024-04-06 09:24:01 -070028
Ed Tanous3cd70722024-04-06 09:24:01 -070029int 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
Ed Tanous25b54db2024-04-17 15:40:31 -070040 if constexpr (BMCWEB_STATIC_HOSTING)
41 {
42 crow::webassets::requestRoutes(app);
43 }
Ed Tanous3cd70722024-04-06 09:24:01 -070044
Ed Tanous25b54db2024-04-17 15:40:31 -070045 if constexpr (BMCWEB_KVM)
46 {
47 crow::obmc_kvm::requestRoutes(app);
48 }
Ed Tanous3cd70722024-04-06 09:24:01 -070049
Ed Tanous25b54db2024-04-17 15:40:31 -070050 if constexpr (BMCWEB_REDFISH)
51 {
52 redfish::RedfishService redfish(app);
Ed Tanous3cd70722024-04-06 09:24:01 -070053
Ed Tanous25b54db2024-04-17 15:40:31 -070054 // Create EventServiceManager instance and initialize Config
55 redfish::EventServiceManager::getInstance(&*io);
Ed Tanous3cd70722024-04-06 09:24:01 -070056
Ed Tanous25b54db2024-04-17 15:40:31 -070057 if constexpr (BMCWEB_REDFISH_AGGREGATION)
58 {
59 // Create RedfishAggregator instance and initialize Config
60 redfish::RedfishAggregator::getInstance(&*io);
61 }
62 }
Ed Tanous3cd70722024-04-06 09:24:01 -070063
Ed Tanous25b54db2024-04-17 15:40:31 -070064 if constexpr (BMCWEB_REST)
65 {
66 crow::dbus_monitor::requestRoutes(app);
67 crow::image_upload::requestRoutes(app);
68 crow::openbmc_mapper::requestRoutes(app);
69 }
Ed Tanous3cd70722024-04-06 09:24:01 -070070
Ed Tanous25b54db2024-04-17 15:40:31 -070071 if constexpr (BMCWEB_HOST_SERIAL_SOCKET)
72 {
73 crow::obmc_console::requestRoutes(app);
74 }
Ed Tanous3cd70722024-04-06 09:24:01 -070075
Ed Tanous3cd70722024-04-06 09:24:01 -070076 crow::obmc_vm::requestRoutes(app);
Ed Tanous3cd70722024-04-06 09:24:01 -070077
Ed Tanous25b54db2024-04-17 15:40:31 -070078 if constexpr (BMCWEB_IBM_MANAGEMENT_CONSOLE)
79 {
80 crow::ibm_mc::requestRoutes(app);
81 }
Ed Tanous3cd70722024-04-06 09:24:01 -070082
Ed Tanous25b54db2024-04-17 15:40:31 -070083 if constexpr (BMCWEB_GOOGLE_API)
84 {
85 crow::google_api::requestRoutes(app);
86 }
Ed Tanous3cd70722024-04-06 09:24:01 -070087
Ed Tanous3cd70722024-04-06 09:24:01 -070088 crow::login_routes::requestRoutes(app);
89
Jayaprakash Mutyalaff0a0882024-06-26 09:08:53 +000090 if constexpr (!BMCWEB_REDFISH_DBUS_LOG)
Ed Tanous3cd70722024-04-06 09:24:01 -070091 {
Ed Tanous25b54db2024-04-17 15:40:31 -070092 int rc = redfish::EventServiceManager::startEventLogMonitor(*io);
93 if (rc != 0)
94 {
95 BMCWEB_LOG_ERROR("Redfish event handler setup failed...");
96 return rc;
97 }
Ed Tanous3cd70722024-04-06 09:24:01 -070098 }
Ed Tanous3cd70722024-04-06 09:24:01 -070099
Ed Tanous25b54db2024-04-17 15:40:31 -0700100 if constexpr (!BMCWEB_INSECURE_DISABLE_SSL)
Ed Tanous8db83742024-04-13 09:11:15 -0700101 {
102 BMCWEB_LOG_INFO("Start Hostname Monitor Service...");
103 crow::hostname_monitor::registerHostnameSignal();
104 }
Ed Tanous3cd70722024-04-06 09:24:01 -0700105
106 bmcweb::registerUserRemovedSignal();
107
108 app.run();
109 io->run();
110
111 crow::connections::systemBus = nullptr;
112
Ed Tanous9ed3f902024-07-15 17:54:31 -0700113 // TODO(ed) Make event log monitor an RAII object instead of global vars
114 redfish::EventServiceManager::stopEventLogMonitor();
115
Ed Tanous3cd70722024-04-06 09:24:01 -0700116 return 0;
117}