X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8e80bb9cec2c90dd61f810fb1525932a434288eb..ebd170a764ab9660adee464588cda1801c7986b4:/projects/stargazer/main.cpp diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 825cba58..acc826f7 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -29,7 +29,7 @@ #include "traffcounter_impl.h" #include "settings_impl.h" #include "pidfile.h" -#include "eventloop.h" +#include "async_pool.h" #include "stg_timer.h" #include "stg/user.h" @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -55,10 +56,6 @@ #include // S_IRUSR #include // create -#ifdef DEBUG - #define NO_DAEMON (1) -#endif - #define START_FILE "/._ST_ART_ED_" using STG::SettingsImpl; @@ -155,13 +152,8 @@ int StartScriptExecuter(char*, int msgKey, int* msgID) return 0; } //----------------------------------------------------------------------------- -#ifndef NO_DAEMON int ForkAndWait(const std::string& confDir) -#else -int ForkAndWait(const std::string&) -#endif { -#ifndef NO_DAEMON const auto pid = fork(); const auto startFile = confDir + START_FILE; unlink(startFile.c_str()); @@ -194,9 +186,9 @@ int ForkAndWait(const std::string&) exit(1); break; } -#endif return 0; } + //----------------------------------------------------------------------------- void KillExecuters() { @@ -208,6 +200,21 @@ void KillExecuters() ++pid; } } + +void PrintHelp(const std::string& programName) +{ + std::cout << "Usage: " << programName << "[-h/--help] [-v/--version] [-f/--foreground] []\n" + << "\t --help, -h - print this help;\n" + << "\t --version, -v - print version;\n" + << "\t --foreground, -f - do not go into background;\n" + << "\t - path to the directory where the configuration file is located.\n"; +} + +void PrintVersion(const std::string& programName) +{ + std::cout << programName << "\n" + << "Stargazer version" << " " << SERVER_VERSION << "\n"; +} //----------------------------------------------------------------------------- } // namespace anonymous //----------------------------------------------------------------------------- @@ -223,7 +230,34 @@ int main(int argc, char* argv[]) return 1; } - SettingsImpl settings(argc == 2 ? argv[1] : ""); + std::string path; + bool noDaemon(false); + + if (argc == 1) + path = ""; + else + { + for (int i = 1; i < argc; ++i) + { + const std::string arg(argv[i]); + if (arg == "--help" || arg == "-h") + { + PrintHelp(argv[0]); + return 0; + } + if (arg == "--version" || arg == "-v") + { + PrintVersion(argv[0]); + return 0; + } + if (arg == "--foreground" || arg == "-f") + noDaemon = true; + else + path = arg; + } + } + + SettingsImpl settings(path); if (settings.ReadSettings()) { @@ -236,14 +270,13 @@ int main(int argc, char* argv[]) return -1; } -#ifndef NO_DAEMON - const auto startFile = settings.GetConfDir() + START_FILE; -#endif - - if (ForkAndWait(settings.GetConfDir()) < 0) + if (!noDaemon) { - STG::Logger::get()("Fork error!"); - return -1; + if (ForkAndWait(settings.GetConfDir()) < 0) + { + STG::Logger::get()("Fork error!"); + return -1; + } } auto& WriteServLog = STG::Logger::get(); @@ -282,7 +315,7 @@ int main(int argc, char* argv[]) return -1; } - auto& loop = EVENT_LOOP_SINGLETON::GetInstance(); + STG::AsyncPoolST::start(); StoreLoader storeLoader(settings); if (storeLoader.load()) @@ -292,18 +325,12 @@ int main(int argc, char* argv[]) return -1; } - if (loop.Start()) - { - printfd(__FILE__, "Event loop not started.\n"); - WriteServLog("Event loop not started."); - return -1; - } - auto& store = storeLoader.get(); WriteServLog("Storage plugin: %s. Loading successfull.", store.GetVersion().c_str()); AdminsImpl admins(store); TariffsImpl tariffs(&store); + tariffs.ReadTariffs(); ServicesImpl services(&store); CorporationsImpl corps(&store); UsersImpl users(&settings, &store, &tariffs, services, admins.sysAdmin()); @@ -327,9 +354,11 @@ int main(int argc, char* argv[]) WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); -#ifndef NO_DAEMON - creat(startFile.c_str(), S_IRUSR); -#endif + if (!noDaemon) + { + const auto startFile = settings.GetConfDir() + START_FILE; + creat(startFile.c_str(), S_IRUSR); + } bool running = true; while (running) @@ -376,8 +405,7 @@ int main(int argc, char* argv[]) manager.stop(); - if (loop.Stop()) - WriteServLog("Event loop not stopped."); + STG::AsyncPoolST::stop(); if (!traffCnt.Stop()) WriteServLog("Traffcounter: Stop successfull.");