allow to specify how many times we can try to connect to the database at startup
add config options: db_startup_connection_max_attempts - default 0 (infinite) db_startup_connection_attempt_delay - delay in seconds between attempts (default 5) BREAKING CHANGE: WINIX_PLUGIN_INIT plugin message requires to set result status, you have to set the result status to true (env.res) if your plugin was initialized correctly, otherwise winix will not start
This commit is contained in:
@@ -178,7 +178,7 @@ Log & App::GetMainLog()
|
||||
|
||||
|
||||
|
||||
void App::InitPlugins()
|
||||
void App::LoadPlugins()
|
||||
{
|
||||
plugin.LoadPlugins(config.plugins_dir, config.plugin_file);
|
||||
}
|
||||
@@ -350,8 +350,26 @@ bool App::TryToMakeDatabaseMigration()
|
||||
}
|
||||
|
||||
|
||||
bool App::InitializePlugins()
|
||||
{
|
||||
PluginRes plugin_res = plugin.Call((Session*)0, WINIX_PLUGIN_INIT);
|
||||
|
||||
if( plugin_res.res_false > 0 )
|
||||
{
|
||||
log << log1 << "App: " << plugin_res.res_false << " plugin(s) cannot initialize itself, exiting" << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool App::Init()
|
||||
{
|
||||
// load plugins before loading sessions - session_manager.LoadSessions()
|
||||
// because some of the plugins can init its own sessions dates
|
||||
LoadPlugins();
|
||||
|
||||
if( !config.db_conn_string.empty() )
|
||||
postgresql_connector.set_conn_param(config.db_conn_string);
|
||||
else
|
||||
@@ -359,7 +377,11 @@ bool App::Init()
|
||||
|
||||
postgresql_connector.set_logger(log);
|
||||
postgresql_connector.set_log_queries(config.log_db_query);
|
||||
postgresql_connector.wait_for_connection();
|
||||
|
||||
if( !postgresql_connector.wait_for_connection(config.db_startup_connection_max_attempts, config.db_startup_connection_attempt_delay) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
model_connector.set_flat_connector(json_connector);
|
||||
model_connector.set_db_connector(postgresql_connector);
|
||||
@@ -378,6 +400,7 @@ bool App::Init()
|
||||
model_connector.set_winix_time_zones(&system.time_zones);
|
||||
model_connector.set_winix_pattern_cacher(&TemplatesFunctions::pattern_cacher);
|
||||
|
||||
// CHECKME this will call WINIX_MAKE_DATABASE_MIGRATION, but WINIX_PLUGIN_INIT was not called yet, it is correct?
|
||||
if( !TryToMakeDatabaseMigration() )
|
||||
return false;
|
||||
|
||||
@@ -387,13 +410,17 @@ bool App::Init()
|
||||
else
|
||||
db_conn.SetConnParam(config.db_host, config.db_hostaddr, config.db_port, config.db_database, config.db_user, config.db_pass);
|
||||
|
||||
db_conn.WaitForConnection();
|
||||
if( !db_conn.WaitForConnection(config.db_startup_connection_max_attempts, config.db_startup_connection_attempt_delay) )
|
||||
return false;
|
||||
|
||||
db.LogQueries(config.log_db_query);
|
||||
|
||||
cur.request->Clear();
|
||||
compress.set_dependency(&winix_base);
|
||||
compress.Init();
|
||||
system.Init();
|
||||
|
||||
if( !system.Init() )
|
||||
return false;
|
||||
|
||||
functions.Init();
|
||||
templates.Init(); // init templates after functions are created
|
||||
@@ -414,9 +441,10 @@ bool App::Init()
|
||||
|
||||
cookie_parser.set_dependency(&winix_model);
|
||||
|
||||
plugin.Call((Session*)0, WINIX_PLUGIN_INIT);
|
||||
if( !AddSystemThreads() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return InitializePlugins();
|
||||
}
|
||||
|
||||
|
||||
@@ -2788,6 +2816,15 @@ int sig;
|
||||
}
|
||||
|
||||
|
||||
bool App::AddSystemThreads()
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
ok = ok && system.thread_manager.Add(&session_manager, L"session_manager");
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
void App::StartThreads()
|
||||
{
|
||||
@@ -2797,7 +2834,7 @@ void App::StartThreads()
|
||||
// special thread only for signals
|
||||
pthread_create(&signal_thread, 0, SpecialThreadForSignals, this);
|
||||
|
||||
system.thread_manager.Add(&session_manager, L"session_manager");
|
||||
// start all threads from thread manager
|
||||
system.thread_manager.StartAll();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user