X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffmsapp.cpp;h=8a462e292a9b966f530b016ca7a839e022f6c288;hb=07319f767b4c4f0e06e9957f217d5107b196617b;hp=99712c59533fa5d995abf91e2b71dd6dc808bbb9;hpb=023b2219068d481cd6a300982427c99bacd88a12;p=fms.git diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index 99712c5..8a462e2 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,8 +100,13 @@ 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()); SetupDB(); SetupDefaultOptions(); @@ -145,8 +160,7 @@ 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) { @@ -163,6 +177,14 @@ int FMSApp::main(const std::vector &args) { logger().information("FMS startup v"FMS_VERSION); + std::string tempval=""; + Option::Instance()->Get("VacuumOnStartup",tempval); + if(tempval=="true") + { + logger().information("VACUUMing database"); + SQLite3DB::DB::Instance()->Execute("VACUUM;"); + } + StartThreads(); if(isInteractive()==true) @@ -172,6 +194,11 @@ int FMSApp::main(const std::vector &args) waitForTerminationRequest(); + if(isInteractive()==true) + { + std::cout << "Please wait while FMS shuts down." << std::endl << std::endl; + } + logger().trace("FMSApp::main cancelling threads"); m_threads.Cancel(); logger().trace("FMSApp::main joining threads"); @@ -231,6 +258,10 @@ void FMSApp::StartThreads() logger().trace("FMSApp::StartThreads starting HTTPThread"); m_threads.Start(new HTTPThread()); } + else + { + logger().trace("FMSApp::StartThreads not starting HTTPThread"); + } tempval=""; Option::Instance()->Get("StartNNTP",tempval); @@ -239,6 +270,10 @@ void FMSApp::StartThreads() logger().trace("FMSApp::StartThreads starting NNTPListener"); m_threads.Start(new NNTPListener()); } + else + { + logger().trace("FMSApp::StartThreads not starting NNTPListener"); + } tempval=""; Option::Instance()->Get("StartFreenetUpdater",tempval); @@ -247,5 +282,9 @@ void FMSApp::StartThreads() logger().trace("FMSApp::StartThreads starting FreenetMasterThread"); m_threads.Start(new FreenetMasterThread()); } + else + { + logger().trace("FMSApp::StartThreads not starting FreenetMasterThread"); + } }