#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"
#include <fstream>
#include <vector>
+#include <string>
#include <set>
#include <csignal>
#include <cerrno>
#include <sys/stat.h> // S_IRUSR
#include <fcntl.h> // create
-#ifdef DEBUG
- #define NO_DAEMON (1)
-#endif
-
#define START_FILE "/._ST_ART_ED_"
using STG::SettingsImpl;
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());
exit(1);
break;
}
-#endif
return 0;
}
+
//-----------------------------------------------------------------------------
void KillExecuters()
{
++pid;
}
}
+
+void PrintHelp(const std::string& programName)
+{
+ std::cout << "Usage: " << programName << "[-h/--help] [-v/--version] [-f/--foreground] [<conf-dir-path>]\n"
+ << "\t --help, -h - print this help;\n"
+ << "\t --version, -v - print version;\n"
+ << "\t --foreground, -f - do not go into background;\n"
+ << "\t <conf-dir-path> - 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
//-----------------------------------------------------------------------------
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())
{
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();
return -1;
}
- auto& loop = EVENT_LOOP_SINGLETON::GetInstance();
+ STG::AsyncPoolST::start();
StoreLoader storeLoader(settings);
if (storeLoader.load())
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());
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)
manager.stop();
- if (loop.Stop())
- WriteServLog("Event loop not stopped.");
+ STG::AsyncPoolST::stop();
if (!traffCnt.Stop())
WriteServLog("Traffcounter: Stop successfull.");