125 lines
2.5 KiB
C++
Executable File
125 lines
2.5 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/log.h"
|
|
#include "core/app.h"
|
|
#include "core/plugin.h"
|
|
|
|
// !! chwilowo
|
|
#include "core/db.h"
|
|
|
|
|
|
Log log;
|
|
Log nlog; // notify log (used by another thread)
|
|
Plugin plugin;
|
|
|
|
|
|
|
|
/*
|
|
application object
|
|
*/
|
|
App app;
|
|
|
|
|
|
void signal_term(int)
|
|
{
|
|
plugin.Call(WINIX_CLOSE);
|
|
app.Close();
|
|
log << log1 << "winix stopped" << logend << logsave;
|
|
|
|
// !! sprawdzic czemu ta flaga zatrzymania nie dzialala
|
|
// i sprobowac pozbyc sie tego exita tutaj
|
|
exit(0);
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
app.system.system_start = time(0);
|
|
app.config.config_file = argc[1];
|
|
|
|
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
|
|
return 2;
|
|
|
|
if( app.stdout_is_closed )
|
|
app.config.log_stdout = false;
|
|
|
|
// 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( !app.config.log_stdout )
|
|
{
|
|
close(1);
|
|
app.stdout_is_closed = true;
|
|
}
|
|
|
|
|
|
log.Init(app.config.log_level, app.config.log_file, app.config.log_stdout, app.config.log_request);
|
|
nlog.Init(app.config.log_level, app.config.log_notify_file, false, 1);
|
|
app.db.Init(app.config.db_database, app.config.db_user, app.config.db_pass);
|
|
|
|
// app.config.base_server can be changed (stripped from 'http://' or a last slash)
|
|
// it is done when the config is read
|
|
log << log3 << "base_server: " << app.config.base_server << logend;
|
|
|
|
// load plugins before loading sessions - session_manager.LoadSessions()
|
|
// because some of the plugins can init your own session dates
|
|
plugin.LoadPlugins(app.config.plugin_file);
|
|
//plugin.Call(WINIX_PLUGIN_INIT);
|
|
|
|
if( !app.Init() )
|
|
return 1;
|
|
|
|
|
|
app.notify.ReadTemplates(); // wrzucic do notify.Init() ?
|
|
|
|
signal(SIGTERM, signal_term);
|
|
signal(SIGINT, signal_term);
|
|
|
|
log << log1 << "winix started" << logend << logsavenow;
|
|
|
|
// !! wywalic to sprawdzanie
|
|
//log << log2 << "checking for table consistency:" << logend;
|
|
// !! zrobic wyjatek dla root
|
|
//app.db.CheckAllUrlSubject();
|
|
|
|
app.Start();
|
|
|
|
plugin.Call(WINIX_CLOSE);
|
|
app.Close();
|
|
log << log1 << "winix stopped" << logend << logsave;
|
|
|
|
return 0;
|
|
}
|