1 #include "../include/fmsapp.h"
\r
2 #include "../include/global.h"
\r
3 #include "../include/dbsetup.h"
\r
4 #include "../include/optionssetup.h"
\r
5 #include "../include/option.h"
\r
6 #include "../include/stringfunctions.h"
\r
7 #include "../include/http/httpthread.h"
\r
8 #include "../include/nntp/nntplistener.h"
\r
9 #include "../include/dbmaintenancethread.h"
\r
10 #include "../include/freenet/freenetmasterthread.h"
\r
11 #include "../include/threadwrapper/threadedexecutor.h"
\r
13 #include <Poco/Util/HelpFormatter.h>
\r
14 #include <Poco/FileChannel.h>
\r
15 #include <Poco/FormattingChannel.h>
\r
16 #include <Poco/PatternFormatter.h>
\r
26 #include <Poco/ScopedLock.h>
\r
27 #include <Poco/Runnable.h>
\r
28 #include <Poco/Thread.h>
\r
29 #include <Poco/ThreadPool.h>
\r
30 #include "../include/threadwrapper/cancelablerunnable.h"
\r
31 #include "../include/threadwrapper/cancelablethread.h"
\r
34 class TestRunner:public CancelableRunnable
\r
42 }while(!IsCancelled());
\r
46 FMSApp::FMSApp():m_displayhelp(false)
\r
51 void FMSApp::defineOptions(Poco::Util::OptionSet &options)
\r
53 ServerApplication::defineOptions(options);
\r
55 // add command line options here
\r
56 options.addOption(Poco::Util::Option("help","?","display help for command line arguments",false).repeatable(false).callback(Poco::Util::OptionCallback<FMSApp>(this,&FMSApp::handleHelp)));
\r
59 void FMSApp::displayHelp()
\r
61 Poco::Util::HelpFormatter helpFormatter(options());
\r
62 helpFormatter.setCommand(commandName());
\r
63 helpFormatter.setUsage("OPTIONS");
\r
64 helpFormatter.setHeader("The Freenet Message System.");
\r
65 helpFormatter.format(std::cout);
\r
68 void FMSApp::handleHelp(const std::string &name, const std::string &value)
\r
72 stopOptionsProcessing();
\r
75 void FMSApp::initialize(Poco::Util::Application &self)
\r
77 ServerApplication::initialize(self);
\r
79 // set working directory to program directory
\r
80 int rval=chdir(config().getString("application.dir").c_str());
\r
83 SetupDefaultOptions();
\r
85 config().setString("application.logger","logfile");
\r
88 void FMSApp::initializeLogger()
\r
90 int initiallevel=Poco::Message::PRIO_TRACE;
\r
92 std::string tempval="";
\r
93 if(Option::Instance()->Get("LogLevel",tempval))
\r
95 StringFunctions::Convert(tempval,initiallevel);
\r
98 Poco::AutoPtr<Poco::FormattingChannel> formatter=new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S | %p | %t"));
\r
99 Poco::AutoPtr<Poco::FileChannel> fc=new Poco::FileChannel("fms.log");
\r
100 fc->setProperty("rotation","daily"); // rotate log file daily
\r
101 fc->setProperty("times","utc"); // utc date/times for log entries
\r
102 fc->setProperty("archive","timestamp"); // add timestamp to old logs
\r
103 fc->setProperty("purgeCount","30"); // purge old logs after 30 logs have accumulated
\r
104 fc->setProperty("compress","true"); // gz compress old log files
\r
105 formatter->setChannel(fc);
\r
107 setLogger(Poco::Logger::create("logfile",formatter,initiallevel));
\r
110 int FMSApp::main(const std::vector<std::string> &args)
\r
113 if(m_displayhelp==false)
\r
115 logger().information("FMS startup v"FMS_VERSION);
\r
119 waitForTerminationRequest();
\r
121 m_threads.Cancel();
\r
124 logger().information("FMS shutdown");
\r
127 return FMSApp::EXIT_OK;
\r
130 void FMSApp::StartThreads()
\r
132 std::string tempval="";
\r
134 // always start the DB maintenance thread
\r
135 m_threads.Start(new DBMaintenanceThread());
\r
137 Option::Instance()->Get("StartHTTP",tempval);
\r
138 if(tempval=="true")
\r
140 m_threads.Start(new HTTPThread());
\r
144 Option::Instance()->Get("StartNNTP",tempval);
\r
145 if(tempval=="true")
\r
147 m_threads.Start(new NNTPListener());
\r
151 Option::Instance()->Get("StartFreenetUpdater",tempval);
\r
152 if(tempval=="true")
\r
154 m_threads.Start(new FreenetMasterThread());
\r