2016-12-14 15:34:44 +00:00
|
|
|
|
#include "ts_env.h"
|
|
|
|
|
|
|
|
|
|
TsEnv g_env;
|
|
|
|
|
|
|
|
|
|
TsEnv::TsEnv()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
TsEnv::~TsEnv()
|
|
|
|
|
{}
|
|
|
|
|
|
2017-03-12 05:02:38 +00:00
|
|
|
|
bool TsEnv::init(bool for_web)
|
2016-12-14 15:34:44 +00:00
|
|
|
|
{
|
|
|
|
|
EXLOG_LEVEL(EX_LOG_LEVEL_INFO);
|
|
|
|
|
|
|
|
|
|
ex_exec_file(m_exec_file);
|
|
|
|
|
|
|
|
|
|
m_exec_path = m_exec_file;
|
|
|
|
|
ex_dirname(m_exec_path);
|
|
|
|
|
|
2017-03-12 05:02:38 +00:00
|
|
|
|
if (!for_web)
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
// check development flag file, if exists, run in development mode for trace and debug.
|
|
|
|
|
ex_wstr dev_flag_file = m_exec_path;
|
|
|
|
|
ex_path_join(dev_flag_file, false, L"dev_mode", NULL);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
ex_wstr base_path = m_exec_path;
|
|
|
|
|
ex_wstr log_path;
|
|
|
|
|
ex_wstr conf_file;
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
if (ex_is_file_exists(dev_flag_file.c_str()))
|
2016-12-14 15:34:44 +00:00
|
|
|
|
{
|
2017-03-26 19:12:15 +00:00
|
|
|
|
EXLOGW("===== DEVELOPMENT MODE =====\n");
|
|
|
|
|
|
|
|
|
|
ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", NULL);
|
|
|
|
|
conf_file = base_path;
|
|
|
|
|
ex_path_join(conf_file, false, L"share", L"etc", L"web.ini.in", NULL);
|
|
|
|
|
|
|
|
|
|
log_path = base_path;
|
|
|
|
|
ex_path_join(log_path, false, L"share", L"log", NULL);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
}
|
2017-03-26 19:12:15 +00:00
|
|
|
|
else // not in development mode
|
2016-12-14 15:34:44 +00:00
|
|
|
|
{
|
|
|
|
|
base_path = m_exec_path;
|
2017-03-26 19:12:15 +00:00
|
|
|
|
ex_path_join(base_path, true, L"..", NULL);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
#ifdef EX_OS_WIN
|
2016-12-14 15:34:44 +00:00
|
|
|
|
conf_file = base_path;
|
2017-01-16 13:28:13 +00:00
|
|
|
|
ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
|
2017-03-26 19:12:15 +00:00
|
|
|
|
log_path = base_path;
|
|
|
|
|
ex_path_join(log_path, false, L"log", NULL);
|
|
|
|
|
#else
|
|
|
|
|
conf_file = L"/etc/teleport/web.ini";
|
|
|
|
|
log_path = L"/var/log/teleport";
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
#endif
|
2016-12-14 15:34:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
m_www_path = base_path;
|
|
|
|
|
ex_path_join(m_www_path, false, L"www", NULL);
|
|
|
|
|
|
|
|
|
|
// // <20><>λ log, etc, www ·<><C2B7>
|
|
|
|
|
// // Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>λ<EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD> ../ <20><><EFBFBD><EFBFBD>λ<EFBFBD>ã<EFBFBD>
|
|
|
|
|
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD>Ŀ¼<C4BF>µ<EFBFBD>shareĿ¼<C4BF>в<EFBFBD><D0B2>ҡ<EFBFBD>
|
|
|
|
|
// ex_wstr base_path = m_exec_path;
|
|
|
|
|
// ex_path_join(base_path, true, L"..", NULL);
|
|
|
|
|
//
|
|
|
|
|
// ex_wstr conf_file = base_path;
|
|
|
|
|
// ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
|
|
|
|
|
//
|
|
|
|
|
// if (ex_is_file_exists(conf_file.c_str()))
|
|
|
|
|
// {
|
|
|
|
|
// m_www_path = base_path;
|
|
|
|
|
// ex_path_join(m_www_path, false, L"www", NULL);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// EXLOGW("===== DEVELOPMENT MODE =====\n");
|
|
|
|
|
// base_path = m_exec_path;
|
|
|
|
|
// ex_path_join(base_path, true, L"..", L"..", L"..", L"..", L"server", L"share", NULL);
|
|
|
|
|
//
|
|
|
|
|
// conf_file = base_path;
|
|
|
|
|
// ex_path_join(conf_file, false, L"etc", L"web.ini", NULL);
|
|
|
|
|
//
|
|
|
|
|
// m_www_path = m_exec_path;
|
|
|
|
|
// ex_path_join(m_www_path, true, L"..", L"..", L"..", L"..", L"server", L"www", NULL);
|
|
|
|
|
// }
|
|
|
|
|
|
2016-12-14 15:34:44 +00:00
|
|
|
|
if (!ex_is_file_exists(conf_file.c_str()))
|
|
|
|
|
{
|
2017-03-26 19:12:15 +00:00
|
|
|
|
EXLOGE("[tpweb] web.ini not found.\n");
|
2016-12-14 15:34:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExIniFile cfg;
|
|
|
|
|
if (!cfg.LoadFromFile(conf_file))
|
|
|
|
|
{
|
2017-01-16 13:28:13 +00:00
|
|
|
|
EXLOGE("[tpweb] can not load web.ini.\n");
|
2016-12-14 15:34:44 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ex_wstr log_file;
|
|
|
|
|
ExIniSection* ps = cfg.GetDumySection();
|
|
|
|
|
if (!ps->GetStr(L"log_file", log_file))
|
|
|
|
|
{
|
2017-03-26 19:12:15 +00:00
|
|
|
|
// ex_wstr log_path = base_path;
|
|
|
|
|
// ex_path_join(log_path, false, L"log", NULL);
|
2016-12-14 15:34:44 +00:00
|
|
|
|
EXLOG_FILE(L"tpweb.log", log_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ex_remove_white_space(log_file);
|
|
|
|
|
if (log_file[0] == L'"' || log_file[0] == L'\'')
|
|
|
|
|
log_file.erase(0, 1);
|
|
|
|
|
if (log_file[ log_file.length() - 1 ] == L'"' || log_file[log_file.length() - 1] == L'\'')
|
|
|
|
|
log_file.erase(log_file.length() - 1, 1);
|
|
|
|
|
|
2017-03-26 19:12:15 +00:00
|
|
|
|
// ex_wstr log_path = log_file;
|
|
|
|
|
log_path = log_file;
|
2016-12-14 15:34:44 +00:00
|
|
|
|
ex_dirname(log_path);
|
|
|
|
|
ex_wstr file_name;
|
|
|
|
|
file_name.assign(log_file, log_path.length() + 1, log_file.length());
|
|
|
|
|
|
|
|
|
|
EXLOG_FILE(file_name.c_str(), log_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int log_level = EX_LOG_LEVEL_INFO;
|
|
|
|
|
if (ps->GetInt(L"log_level", log_level))
|
|
|
|
|
{
|
|
|
|
|
EXLOGV("[tpweb] log-level: %d\n", log_level);
|
|
|
|
|
EXLOG_LEVEL(log_level);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 16:20:03 +00:00
|
|
|
|
// EXLOGI("==============================\n");
|
|
|
|
|
// EXLOGI("[tpweb] start...\n");
|
2016-12-14 15:34:44 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|