1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Banner.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "DatabaseLoader.h"
#include "IoContext.h"
#include "Log.h"
#include "MySQLThreading.h"
#include "OpenSSLCrypto.h"
#include "Util.h"
#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <csignal>
#include <filesystem>
#include <iostream>
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#ifndef _ACORE_DB_IMPORT_CONFIG
#define _ACORE_DB_IMPORT_CONFIG "dbimport.conf"
#endif
using namespace boost::program_options;
namespace fs = std::filesystem;
bool StartDB();
void StopDB();
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile);
/// Launch the db import server
int main(int argc, char** argv)
{
signal(SIGABRT, &Acore::AbortHandler);
// Command line parsing
auto configFile = fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG));
auto vm = GetConsoleArguments(argc, argv, configFile);
// exit if help is enabled
if (vm.count("help"))
return 0;
// Add file and args in config
sConfigMgr->Configure(configFile.generic_string(), std::vector<std::string>(argv, argv + argc));
if (!sConfigMgr->LoadAppConfigs())
return 1;
std::vector<std::string> overriddenKeys = sConfigMgr->OverrideWithEnvVariablesIfAny();
// Init logging
sLog->Initialize();
Acore::Banner::Show("dbimport",
[](std::string_view text)
{
LOG_INFO("dbimport", text);
},
[]()
{
LOG_INFO("dbimport", "> Using configuration file: {}", sConfigMgr->GetFilename());
LOG_INFO("dbimport", "> Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
LOG_INFO("dbimport", "> Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
}
);
for (std::string const& key : overriddenKeys)
LOG_INFO("dbimport", "Configuration field {} was overridden with environment variable.", key);
OpenSSLCrypto::threadsSetup();
std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
// Initialize the database connection
if (!StartDB())
return 1;
std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
LOG_INFO("dbimport", "Halting process...");
return 0;
}
/// Initialize connection to the database
bool StartDB()
{
MySQL::Library_Init();
// Load databases
DatabaseLoader loader("dbimport");
loader
.AddDatabase(LoginDatabase, "Login")
.AddDatabase(CharacterDatabase, "Character")
.AddDatabase(WorldDatabase, "World");
if (!loader.Load())
return false;
LOG_INFO("dbimport", "Started database connection pool.");
return true;
}
/// Close the connection to the database
void StopDB()
{
CharacterDatabase.Close();
WorldDatabase.Close();
LoginDatabase.Close();
MySQL::Library_End();
}
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile)
{
options_description all("Allowed options");
all.add_options()
("help,h", "print usage message")
("version,v", "print version build info")
("dry-run,d", "Dry run")
("config,c", value<fs::path>(&configFile)->default_value(fs::path(sConfigMgr->GetConfigPath() + std::string(_ACORE_DB_IMPORT_CONFIG))), "use <arg> as configuration file");
variables_map variablesMap;
try
{
store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
notify(variablesMap);
}
catch (std::exception const& e)
{
std::cerr << e.what() << "\n";
}
if (variablesMap.count("help"))
{
std::cout << all << "\n";
}
else if (variablesMap.count("dry-run"))
{
sConfigMgr->setDryRun(true);
}
return variablesMap;
}
|