X-Git-Url: https://git.pterodactylus.net/?p=fms.git;a=blobdiff_plain;f=src%2Ffmsapp.cpp;h=89bb9d7d69d76b232ceb9bf6df5763766b60e0b9;hp=ebebe4a8fa194e40c74bad2374363757efd97fd7;hb=HEAD;hpb=cd75427de26fc2ebc9baad558b1c0a081faa3b43 diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index ebebe4a..89bb9d7 100644 --- a/src/fmsapp.cpp +++ b/src/fmsapp.cpp @@ -26,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 @@ -108,8 +113,23 @@ void FMSApp::initialize(Poco::Util::Application &self) } 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"); } @@ -119,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); } @@ -153,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) @@ -162,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) @@ -176,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(); @@ -206,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 @@ -221,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()) { @@ -238,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 { @@ -256,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 { @@ -268,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 {