X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffmsapp.cpp;h=2daf6c817304d252eed8064e4ecb5a9d3c8fc5c1;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=318244382475fd013734060e7e85f9eec3d77910;hpb=cd97061e86eeecf5b77dea35f0549e73a50eb200;p=fms.git diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index 3182443..2daf6c8 100644 --- a/src/fmsapp.cpp +++ b/src/fmsapp.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #ifdef _WIN32 #include @@ -24,9 +26,17 @@ #include #endif -FMSApp::FMSApp():m_displayhelp(false),m_showoptions(false),m_setoption(false),m_logtype("file") +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 + char wd[1024]; + char *wdptr=NULL; + memset(wd,0,1024); + wdptr=getcwd(wd,1023); + if(wdptr) + { + m_workingdirectory=wdptr; + } } void FMSApp::defineOptions(Poco::Util::OptionSet &options) @@ -90,11 +100,31 @@ void FMSApp::initialize(Poco::Util::Application &self) { ServerApplication::initialize(self); - // set working directory to program directory - int rval=chdir(config().getString("application.dir").c_str()); + // set working directory - fall back on application.dir if working directory isn't set + // 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()); + +#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 - SetupDB(); - SetupDefaultOptions(); + LoadDatabase(); + SetupDB(m_db); + SetupDefaultOptions(m_db); initializeLogger(); config().setString("application.logger","logfile"); } @@ -104,7 +134,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); } @@ -138,6 +170,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) @@ -145,10 +178,14 @@ int FMSApp::main(const std::vector &args) // running as a daemon would reset the working directory to / before calling main // so we need to set the working directory again - // set working directory to program directory - int rval=chdir(config().getString("application.dir").c_str()); + 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) @@ -162,6 +199,16 @@ 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;"); + } StartThreads(); @@ -192,10 +239,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 @@ -207,7 +255,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()) { @@ -224,17 +272,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 { @@ -242,11 +295,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 { @@ -254,11 +311,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 {