1 #include "FileDescriptor.h"
2 #include "SessionListener.h"
3 #include "HostListener.h"
5 #include "Configuration.h"
6 #include "MMSException.h"
10 #include "libutil/File.h"
12 using namespace remote
;
13 using namespace remote::mcs
;
14 using namespace remote::util
;
18 log("Shutting down\n");
19 remove(Configuration::vm
["pidFile"].as
<std::string
>().c_str());
22 int main(int argc
,char** argv
)
24 std::ostringstream oss
;
27 Configuration::read(argc
,argv
);
29 if (Configuration::vm
["daemonize"].as
<int>())
31 printf("Daemonizing!\n");
37 if (NULL
== freopen(Configuration::vm
["log-file"].as
<std::string
>().c_str(),"a",stdout
))
39 fprintf(stderr
,"Unable to open file %s for logging! Bailing out!\n",Configuration::vm
["log-file"].as
<std::string
>().c_str());
42 if (NULL
== freopen(Configuration::vm
["errorlog-file"].as
<std::string
>().c_str(),"a",stderr
))
48 log("Starting mote server\n");
52 oss
<< getpid() << std::endl
;
55 if (!File::writeFile(Configuration::vm
["pidFile"].as
<std::string
>(),
56 pid
.c_str(), pid
.size()))
57 log("Failed to create .pid file\n");
60 dbConn
.connect( Configuration::vm
["dbName"].as
<std::string
>(),
61 Configuration::vm
["dbHost"].as
<std::string
>(),
62 Configuration::vm
["dbUser"].as
<std::string
>(),
63 Configuration::vm
["dbPassword"].as
<std::string
>());
64 log("Connected to database\n");
66 log("Deleted old mote data\n");
68 log("Deleted old session data\n");
69 HostListener
hostListener(Configuration::vm
["hostListenerPort"].as
<unsigned int>());
70 SessionListener
sessionListener(Configuration::vm
["sessionListenerPort"].as
<unsigned int>());
71 log("Entering service loop\n");
73 } while (FileDescriptor::serviceLoop());