X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffmsapp.cpp;h=89bb9d7d69d76b232ceb9bf6df5763766b60e0b9;hp=94443c4cd8440e298bda8018b8b986b4bbea85d4;hb=HEAD;hpb=026dc6b2bc548c945359c4e166eff514f2c47c6a diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index 94443c4..89bb9d7 100644 --- a/src/fmsapp.cpp +++ b/src/fmsapp.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #include @@ -24,6 +26,11 @@ #include #endif +#ifdef FROST_SUPPORT + #include + #include +#endif + FMSApp::FMSApp():m_displayhelp(false),m_showoptions(false),m_setoption(false),m_logtype("file"),m_workingdirectory("") { // get current working dir so we can go to it later @@ -99,14 +106,30 @@ void FMSApp::initialize(Poco::Util::Application &self) ServerApplication::initialize(self); // set working directory - fall back on application.dir if working directory isn't set - if(m_workingdirectory=="") + // if we are runing as a service, then working directory needs to be set to the application directory + if(m_workingdirectory=="" || config().getBool("application.runAsService",false)==true) { m_workingdirectory=config().getString("application.dir"); } int rval=chdir(m_workingdirectory.c_str()); - SetupDB(); - SetupDefaultOptions(); +#ifdef QUERY_LOG + { + Poco::AutoPtr formatter=new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S | %t")); + Poco::AutoPtr fc=new Poco::FileChannel("query.log"); + fc->setProperty("rotation","daily"); + fc->setProperty("times","utc"); + fc->setProperty("archive","timestamp"); + fc->setProperty("purgeCount","5"); + fc->setProperty("compress","true"); + formatter->setChannel(fc); + Poco::Logger::create("querylog",formatter,Poco::Message::PRIO_INFORMATION); + } +#endif + + LoadDatabase(); + SetupDB(m_db); + SetupDefaultOptions(m_db); initializeLogger(); config().setString("application.logger","logfile"); } @@ -116,7 +139,9 @@ void FMSApp::initializeLogger() int initiallevel=Poco::Message::PRIO_TRACE; std::string tempval=""; - if(Option::Instance()->Get("LogLevel",tempval)) + Option option(m_db); + + if(option.Get("LogLevel",tempval)) { StringFunctions::Convert(tempval,initiallevel); } @@ -150,6 +175,7 @@ void FMSApp::initializeLogger() setLogger(Poco::Logger::create("logfile",formatter,Poco::Message::PRIO_INFORMATION)); Poco::Logger::get("logfile").information("LogLevel set to "+tempval); Poco::Logger::get("logfile").setLevel(initiallevel); + } int FMSApp::main(const std::vector &args) @@ -159,7 +185,12 @@ int FMSApp::main(const std::vector &args) // so we need to set the working directory again int rval=chdir(m_workingdirectory.c_str()); - if(m_displayhelp) + if(VerifyDB(m_db)==false) + { + std::cout << "The FMS database failed verification. It is most likely corrupt!" << std::endl; + logger().fatal("The FMS database failed verification. It is most likely corrupt!"); + } + else if(m_displayhelp) { } else if(m_showoptions) @@ -173,6 +204,21 @@ int FMSApp::main(const std::vector &args) else { logger().information("FMS startup v"FMS_VERSION); + logger().information("Using SQLite "SQLITE_VERSION); + + std::string tempval(""); + Option option(m_db); + option.Get("VacuumOnStartup",tempval); + if(tempval=="true") + { + logger().information("VACUUMing database"); + m_db->Execute("VACUUM;"); + } + +#ifdef FROST_SUPPORT + ltc_mp=ltm_desc; + register_hash(&sha1_desc); +#endif StartThreads(); @@ -203,10 +249,11 @@ void FMSApp::setOptions() { for(std::map::iterator i=m_setoptions.begin(); i!=m_setoptions.end(); i++) { - std::string tempval=""; - if(Option::Instance()->Get((*i).first,tempval)) + std::string tempval(""); + Option option(m_db); + if(option.Get((*i).first,tempval)) { - Option::Instance()->Set((*i).first,(*i).second); + option.Set((*i).first,(*i).second); std::cout << "Option " << (*i).first << " set to " << (*i).second << std::endl; } else @@ -218,7 +265,7 @@ void FMSApp::setOptions() void FMSApp::showOptions() { - SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("SELECT Option, OptionValue FROM tblOption;"); + SQLite3DB::Statement st=m_db->Prepare("SELECT Option, OptionValue FROM tblOption;"); st.Step(); while(st.RowReturned()) { @@ -235,17 +282,22 @@ void FMSApp::showOptions() void FMSApp::StartThreads() { - std::string tempval=""; + std::string tempval(""); + Option option(m_db); // always start the DB maintenance thread logger().trace("FMSApp::StartThreads starting DBMaintenanceThread"); m_threads.Start(new DBMaintenanceThread()); - Option::Instance()->Get("StartHTTP",tempval); + option.Get("StartHTTP",tempval); if(tempval=="true") { logger().trace("FMSApp::StartThreads starting HTTPThread"); m_threads.Start(new HTTPThread()); + if(isInteractive()) + { + std::cout << "Started HTTP Thread" << std::endl; + } } else { @@ -253,11 +305,15 @@ void FMSApp::StartThreads() } tempval=""; - Option::Instance()->Get("StartNNTP",tempval); + option.Get("StartNNTP",tempval); if(tempval=="true") { logger().trace("FMSApp::StartThreads starting NNTPListener"); m_threads.Start(new NNTPListener()); + if(isInteractive()) + { + std::cout << "Started NNTP Thread" << std::endl; + } } else { @@ -265,11 +321,15 @@ void FMSApp::StartThreads() } tempval=""; - Option::Instance()->Get("StartFreenetUpdater",tempval); + option.Get("StartFreenetUpdater",tempval); if(tempval=="true") { logger().trace("FMSApp::StartThreads starting FreenetMasterThread"); m_threads.Start(new FreenetMasterThread()); + if(isInteractive()) + { + std::cout << "Started Freenet FCP Thread" << std::endl; + } } else {