142 lines
2.8 KiB
C++
Executable File
142 lines
2.8 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#include <signal.h>
|
|
#include <iostream>
|
|
|
|
#include "../core/requestcontroller.h"
|
|
#include "../core/data.h"
|
|
#include "../core/log.h"
|
|
#include "../core/request.h"
|
|
#include "../core/db.h"
|
|
#include "../core/config.h"
|
|
#include "../core/notify.h"
|
|
#include "../core/plugin.h"
|
|
|
|
|
|
// singletons
|
|
// first 'data' then 'log' then 'request'
|
|
Data data;
|
|
Log log;
|
|
Log nlog; // notify log (used by another thread)
|
|
Request request;
|
|
Db db;
|
|
Config config;
|
|
RequestController req_controller;
|
|
Notify notify;
|
|
Plugin plugin;
|
|
|
|
|
|
|
|
void signal_term(int)
|
|
{
|
|
plugin.Call(WINIX_CLOSE);
|
|
|
|
req_controller.SaveSessions();
|
|
req_controller.DeleteAllPluginsData();
|
|
log << log1 << "cmslu stopped" << logend << logsave;
|
|
|
|
exit(0);
|
|
}
|
|
|
|
|
|
|
|
void signal_hup(int)
|
|
{
|
|
log << log1 << "SIGHUP received" << logend;
|
|
data.signal_hup = true;
|
|
//config.ReadConfig(false); /* errors not to stdout */
|
|
// plugins are not ready for reloading
|
|
}
|
|
|
|
|
|
|
|
void print_syntax()
|
|
{
|
|
std::cout << "Syntax:" << std::endl;
|
|
std::cout << " cmslu.fcgi config_file" << std::endl;
|
|
}
|
|
|
|
|
|
|
|
int main(int argv, char ** argc)
|
|
{
|
|
std::srand(std::time(0));
|
|
|
|
if( argv != 2 )
|
|
{
|
|
print_syntax();
|
|
return 1;
|
|
}
|
|
|
|
data.system_start = time(0);
|
|
data.config_file = argc[1];
|
|
|
|
if( !config.ReadConfig(true) ) /* errors to stdout */
|
|
return 2;
|
|
|
|
// closing descriptors only at the beginning
|
|
// !! temporary we do not close standard output for errors
|
|
// client postgresql uses it for reporting warnings (I don't know why)
|
|
//close(2);
|
|
|
|
if( !data.log_stdout )
|
|
{
|
|
close(1);
|
|
data.stdout_is_closed = true;
|
|
}
|
|
|
|
|
|
log.Init(data.log_level, data.log_file, data.log_stdout, data.log_request);
|
|
nlog.Init(data.log_level, data.log_notify_file, false, 1);
|
|
db.Init(data.db_database, data.db_user, data.db_pass);
|
|
|
|
// data.base_server can be changed (stripped from 'http://' or a last slash)
|
|
// it is done when the config is read
|
|
log << log3 << "base_server: " << data.base_server << logend;
|
|
|
|
// load plugins before loading sessions - req_controller.LoadSessions()
|
|
plugin.LoadPlugins(data.plugin_file);
|
|
plugin.Call(WINIX_PLUGIN_INIT);
|
|
|
|
request.Init();
|
|
|
|
if( !req_controller.Init() )
|
|
return 1;
|
|
|
|
// !! teraz mamy dwa katalogi z templetami
|
|
if( !notify.Init() )
|
|
return 2;
|
|
|
|
notify.ReadTemplates();
|
|
|
|
signal(SIGTERM, signal_term);
|
|
signal(SIGINT, signal_term);
|
|
signal(SIGHUP, signal_hup);
|
|
|
|
req_controller.LoadSessions();
|
|
log << log1 << "cmslu started" << logend << logsavenow;
|
|
|
|
while( true )
|
|
{
|
|
//log << log2 << "checking for table consistency:" << logend;
|
|
// !! zrobic wyjatek dla root
|
|
//db.CheckAllUrlSubject();
|
|
|
|
req_controller.Loop();
|
|
|
|
if( data.signal_hup )
|
|
data.signal_hup = false;
|
|
}
|
|
|
|
return 0;
|
|
}
|