added: program reads its configuration from a config file
added: confparser directory and confparser.h and confparser.cpp class ConfParser used to parse a config file this is a generic parser, can be used by another project added: config.h, config.cpp class Config used for assigning values from a config file into the data object added: function for signals: SIGINT, SIGHUP after receiving SIGHUP the program will read its config file again git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@463 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#include "log.h"
|
||||
#include "request.h"
|
||||
#include "db.h"
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
// singletons
|
||||
@@ -24,50 +26,92 @@ Data data;
|
||||
Log log;
|
||||
Request request;
|
||||
Db db;
|
||||
Config config;
|
||||
|
||||
|
||||
|
||||
|
||||
void signal_term(int)
|
||||
{
|
||||
log << log1 << "system aborted" << logend;
|
||||
|
||||
log << log1 << "cmslu stopped" << logend;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
void signal_hup(int)
|
||||
{
|
||||
std::srand(std::time(0));
|
||||
log << log3 << "SIGHUP received" << logend;
|
||||
data.signal_hup = true;
|
||||
config.ReadConfig(false); /* errors not to stdout */
|
||||
}
|
||||
|
||||
|
||||
log.Init(data.log_level, data.log_file, data.log_stdout);
|
||||
|
||||
void print_syntax()
|
||||
{
|
||||
std::cout << "Syntax:" << std::endl;
|
||||
std::cout << " cmslu.fcgi config_file" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argv, char ** argc)
|
||||
{
|
||||
RequestController req_controller;
|
||||
|
||||
//data.read_from_file();
|
||||
std::srand(std::time(0));
|
||||
|
||||
|
||||
db.Init(data.db_database, data.db_user, data.db_pass);
|
||||
|
||||
if( !req_controller.Init() )
|
||||
if( argv != 2 )
|
||||
{
|
||||
print_syntax();
|
||||
return 1;
|
||||
}
|
||||
|
||||
data.config_file = argc[1];
|
||||
|
||||
|
||||
|
||||
if( !config.ReadConfig(true) ) /* errors to stdout */
|
||||
return 2;
|
||||
|
||||
|
||||
// closing descriptors only at the beginning
|
||||
close(2);
|
||||
|
||||
if( !data.log_stdout )
|
||||
{
|
||||
close(1);
|
||||
data.stdout_is_closed = true;
|
||||
}
|
||||
|
||||
log << log1 << "system started" << logend;
|
||||
|
||||
signal(SIGTERM, signal_term);
|
||||
signal(SIGINT, signal_term);
|
||||
signal(SIGHUP, signal_hup);
|
||||
|
||||
|
||||
log << log1 << "checking for table consistency...";
|
||||
db.CheckAllUrlSubject();
|
||||
log << log1 << "done" << logend;
|
||||
while( true )
|
||||
{
|
||||
log.Init(data.log_level, data.log_file, data.log_stdout);
|
||||
db.Init(data.db_database, data.db_user, data.db_pass);
|
||||
|
||||
if( !req_controller.Init() )
|
||||
return 1;
|
||||
|
||||
req_controller.Loop();
|
||||
log << log2 << "checking for table consistency:" << logend;
|
||||
db.CheckAllUrlSubject();
|
||||
|
||||
log << log1 << "cmslu started" << logend;
|
||||
|
||||
log << log1 << "system stopped" << logend;
|
||||
req_controller.Loop();
|
||||
|
||||
if( data.signal_hup )
|
||||
data.signal_hup = false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user