| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #include <csignal>
- #include <iostream>
- #include "runner_service.hpp"
- #include "logging/logger.hpp"
- #include "config/config_loader.hpp"
- #include "common/config_arg.hpp"
- using namespace smartbotic;
- std::atomic<bool> g_shutdown{false};
- void signalHandler(int signal) {
- LOG_INFO("Received signal {}, shutting down...", signal);
- g_shutdown = true;
- }
- int main(int argc, char* argv[]) {
- // Initialize logging
- logging::LogConfig log_config;
- log_config.name = "runner";
- log_config.level = logging::LogLevel::Info;
- logging::Logger::init(log_config);
- LOG_INFO("SmartBotic Runner starting...");
- // Load configuration
- const auto config_arg = common::parseConfigArg(argc, argv, "./config/runner.json");
- const std::filesystem::path config_path = config_arg.path;
- runner::RunnerServiceConfig config;
- if (std::filesystem::exists(config_path)) {
- config = runner::RunnerService::loadConfig(config_path);
- LOG_INFO("Loaded configuration from {}", config_path.string());
- } else if (config_arg.explicitly_given) {
- // See the webserver's main for why this is fatal rather than a warning.
- 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 {
- LOG_WARN("Config file not found at {}, using defaults", config_path.string());
- }
- // Setup signal handlers
- std::signal(SIGINT, signalHandler);
- std::signal(SIGTERM, signalHandler);
- // Create and start service
- runner::RunnerService service(config);
- try {
- service.start();
- // Wait for shutdown signal
- while (!g_shutdown) {
- std::this_thread::sleep_for(std::chrono::milliseconds(100));
- }
- service.stop();
- } catch (const std::exception& e) {
- LOG_ERROR("Fatal error: {}", e.what());
- return 1;
- }
- LOG_INFO("SmartBotic Runner stopped");
- logging::Logger::shutdown();
- return 0;
- }
|