|
@@ -3,6 +3,7 @@
|
|
|
#include "webserver_service.hpp"
|
|
#include "webserver_service.hpp"
|
|
|
#include "logging/logger.hpp"
|
|
#include "logging/logger.hpp"
|
|
|
#include "config/config_loader.hpp"
|
|
#include "config/config_loader.hpp"
|
|
|
|
|
+#include "common/config_arg.hpp"
|
|
|
|
|
|
|
|
using namespace smartbotic;
|
|
using namespace smartbotic;
|
|
|
|
|
|
|
@@ -23,15 +24,21 @@ int main(int argc, char* argv[]) {
|
|
|
LOG_INFO("SmartBotic WebServer starting...");
|
|
LOG_INFO("SmartBotic WebServer starting...");
|
|
|
|
|
|
|
|
// Load configuration
|
|
// Load configuration
|
|
|
- std::filesystem::path config_path = "./config/webserver.json";
|
|
|
|
|
- if (argc > 1) {
|
|
|
|
|
- config_path = argv[1];
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const auto config_arg = common::parseConfigArg(argc, argv, "./config/webserver.json");
|
|
|
|
|
+ const std::filesystem::path config_path = config_arg.path;
|
|
|
|
|
|
|
|
webserver::WebServerServiceConfig config;
|
|
webserver::WebServerServiceConfig config;
|
|
|
if (std::filesystem::exists(config_path)) {
|
|
if (std::filesystem::exists(config_path)) {
|
|
|
config = webserver::WebServerService::loadConfig(config_path);
|
|
config = webserver::WebServerService::loadConfig(config_path);
|
|
|
LOG_INFO("Loaded configuration from {}", config_path.string());
|
|
LOG_INFO("Loaded configuration from {}", config_path.string());
|
|
|
|
|
+ } else if (config_arg.explicitly_given) {
|
|
|
|
|
+ // Someone named this file, so starting on defaults would run the
|
|
|
|
|
+ // service against a different database, project namespace and port
|
|
|
|
|
+ // than they asked for - and the only sign would be a warning nobody
|
|
|
|
|
+ // reads. Refuse to start instead.
|
|
|
|
|
+ LOG_ERROR("Config file not found at {}. It was given on the command line, "
|
|
|
|
|
+ "so refusing to start on built-in defaults", config_path.string());
|
|
|
|
|
+ return 1;
|
|
|
} else {
|
|
} else {
|
|
|
LOG_WARN("Config file not found at {}, using defaults", config_path.string());
|
|
LOG_WARN("Config file not found at {}, using defaults", config_path.string());
|
|
|
}
|
|
}
|