Added a check for the DB and a delay at start up if the database is not available (#148)
This commit is contained in:
@@ -12,8 +12,24 @@ using Microsoft.OpenApi.Models;
|
||||
Logging.WriteToDiskOnly = true;
|
||||
Logging.Log(Logging.LogType.Information, "Startup", "Starting Gaseous Server " + Assembly.GetExecutingAssembly().GetName().Version);
|
||||
|
||||
// set up db
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
|
||||
// check db availability
|
||||
bool dbOnline = false;
|
||||
do
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "Startup", "Waiting for database...");
|
||||
if (db.TestConnection() == true)
|
||||
{
|
||||
dbOnline = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
}
|
||||
} while (dbOnline == true);
|
||||
|
||||
// set up db
|
||||
db.InitDB();
|
||||
|
||||
// load app settings
|
||||
|
@@ -206,6 +206,18 @@ namespace gaseous_tools
|
||||
}
|
||||
}
|
||||
|
||||
public bool TestConnection()
|
||||
{
|
||||
switch (_ConnectorType)
|
||||
{
|
||||
case databaseType.MySql:
|
||||
MySQLServerConnector conn = new MySQLServerConnector(_ConnectionString);
|
||||
return conn.TestConnection();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class SQLTransactionItem
|
||||
{
|
||||
public SQLTransactionItem()
|
||||
@@ -314,6 +326,20 @@ namespace gaseous_tools
|
||||
return cmd;
|
||||
}
|
||||
|
||||
public bool TestConnection()
|
||||
{
|
||||
MySqlConnection conn = new MySqlConnection(DBConn);
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
conn.Close();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user