Fix syntax error in the remote.sh UDEV script
[remote/remote-mci.git] / diku_mcs / moteserver.cc
blobc83f740c8248f282e8e3f3e3b815380b58d78e39
1 #include "FileDescriptor.h"
2 #include "SessionListener.h"
3 #include "HostListener.h"
4 #include "database.h"
5 #include "Configuration.h"
6 #include "MMSException.h"
7 #include "macros.h"
8 #include <exception>
9 #include <unistd.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");
20 if (fork()) exit(0);
21 setsid();
22 fclose(stdin);
23 close(1);
24 // reopen stdout
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());
28 return -1;
30 if (NULL == freopen(Configuration::vm["errorlog-file"].as<std::string>().c_str(),"a",stderr))
32 return -1;
36 log("Starting mote server\n");
38 while (1)
40 // try
41 // {
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");
47 Mote::resetDb();
48 log("Deleted old mote data\n");
49 Session::resetDb();
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();
55 /* }
56 catch (std::exception e)
58 log("Caught exception: %s - restarting listeners in 30 seconds\n",e.what());
59 usleep(30000000);
60 }*/