1 #include "FileDescriptor.h"
2 #include "SessionListener.h"
3 #include "HostListener.h"
5 #include "Configuration.h"
6 #include "MMSException.h"
11 using namespace remote
;
12 using namespace remote::diku_mcs
;
14 int main(int argc
,char** argv
)
16 Configuration::read(argc
,argv
);
17 if (Configuration::vm
["daemonize"].as
<int>())
19 printf("Daemonizing!\n");
25 if (NULL
== freopen(Configuration::vm
["log-file"].as
<std::string
>().c_str(),"a",stdout
))
27 fprintf(stderr
,"Unable to open file %s for logging! Bailing out!\n",Configuration::vm
["log-file"].as
<std::string
>().c_str());
30 if (NULL
== freopen(Configuration::vm
["errorlog-file"].as
<std::string
>().c_str(),"a",stderr
))
36 log("Starting mote server\n");
42 dbConn
.connect( Configuration::vm
["dbName"].as
<std::string
>(),
43 Configuration::vm
["dbHost"].as
<std::string
>(),
44 Configuration::vm
["dbUser"].as
<std::string
>(),
45 Configuration::vm
["dbPassword"].as
<std::string
>());
46 log("Connected to database\n");
48 log("Deleted old mote data\n");
50 log("Deleted old session data\n");
51 HostListener
hostListener(Configuration::vm
["hostListenerPort"].as
<unsigned int>());
52 SessionListener
sessionListener(Configuration::vm
["sessionListenerPort"].as
<unsigned int>());
53 log("Entering service loop\n");
54 FileDescriptor::serviceLoop();
56 catch (std::exception e)
58 log("Caught exception: %s - restarting listeners in 30 seconds\n",e.what());