From d395862212f241dc922e377a832cd4fa352ea2df Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Thu, 21 Nov 2024 02:31:38 +0000 Subject: [PATCH 1/4] feat: add sym link and pid file name functions --- core/app_config/AppConfig.cpp | 19 ++++++++++++++++++- core/app_config/AppConfig.h | 4 +++- core/common/version.h | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/app_config/AppConfig.cpp b/core/app_config/AppConfig.cpp index e9ecf50e61..a3c3374a47 100644 --- a/core/app_config/AppConfig.cpp +++ b/core/app_config/AppConfig.cpp @@ -25,6 +25,7 @@ #include "common/FileSystemUtil.h" #include "common/JsonUtil.h" #include "common/LogtailCommonFlags.h" +#include "common/version.h" #include "config/InstanceConfigManager.h" #include "config/watcher/InstanceConfigWatcher.h" #include "file_server/ConfigManager.h" @@ -520,7 +521,7 @@ std::string GetAgentName() { return "ilogtail"; } else { return "loongcollector"; - } + } } std::string GetMonitorInfoFileName() { @@ -531,6 +532,22 @@ std::string GetMonitorInfoFileName() { } } +std::string GetSymLinkName() { + if (BOOL_FLAG(logtail_mode)) { + return GetProcessExecutionDir() + "ilogtail"; + } else { + return GetProcessExecutionDir() + "loongcollector"; + } +} + +std::string GetPidFileName() { + if (BOOL_FLAG(logtail_mode)) { + return GetProcessExecutionDir() + ILOGTAIL_PREFIX + ILOGTAIL_VERSION + ILOGTAIL_PIDFILE_SUFFIX; + } else { + return GetAgentRunDir() + "loongcollector.pid"; + } +} + AppConfig::AppConfig() { LOG_INFO(sLogger, ("AppConfig AppConfig", "success")); SetIlogtailConfigJson(""); diff --git a/core/app_config/AppConfig.h b/core/app_config/AppConfig.h index e2f9929c38..1b7f8019cb 100644 --- a/core/app_config/AppConfig.h +++ b/core/app_config/AppConfig.h @@ -60,6 +60,8 @@ std::string GetVersionTag(); std::string GetGoPluginCheckpoint(); std::string GetAgentName(); std::string GetMonitorInfoFileName(); +std::string GetSymLinkName(); +std::string GetPidFileName(); template class DoubleBuffer { @@ -304,7 +306,7 @@ class AppConfig { public: AppConfig(); - ~AppConfig() {}; + ~AppConfig(){}; void LoadInstanceConfig(const std::map>&); diff --git a/core/common/version.h b/core/common/version.h index 6256797df1..f0c5fa2eb0 100644 --- a/core/common/version.h +++ b/core/common/version.h @@ -24,5 +24,6 @@ extern const char* const ILOGTAIL_BUILD_DATE; #define ILOGTAIL_PREFIX "ilogtail_" #define ILOGTAIL_PIDFILE_SUFFIX ".pid" +#define LOONGCOLLECTOR_PREFIX "loongcollector_" #endif \ No newline at end of file From 60ac3d56ad71062d71a276aec5f2ab72d8724395 Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Thu, 21 Nov 2024 02:37:17 +0000 Subject: [PATCH 2/4] GetAgentPrefix() --- core/app_config/AppConfig.cpp | 8 ++++++++ core/app_config/AppConfig.h | 1 + 2 files changed, 9 insertions(+) diff --git a/core/app_config/AppConfig.cpp b/core/app_config/AppConfig.cpp index a3c3374a47..9556a554e3 100644 --- a/core/app_config/AppConfig.cpp +++ b/core/app_config/AppConfig.cpp @@ -548,6 +548,14 @@ std::string GetPidFileName() { } } +std::string GetAgentPrefix() { + if (BOOL_FLAG(logtail_mode)) { + return ILOGTAIL_PREFIX; + } else { + return LOONGCOLLECTOR_PREFIX; + } +} + AppConfig::AppConfig() { LOG_INFO(sLogger, ("AppConfig AppConfig", "success")); SetIlogtailConfigJson(""); diff --git a/core/app_config/AppConfig.h b/core/app_config/AppConfig.h index 1b7f8019cb..df9f50b88e 100644 --- a/core/app_config/AppConfig.h +++ b/core/app_config/AppConfig.h @@ -62,6 +62,7 @@ std::string GetAgentName(); std::string GetMonitorInfoFileName(); std::string GetSymLinkName(); std::string GetPidFileName(); +std::string GetAgentPrefix(); template class DoubleBuffer { From 5c793c387d99501bcd524e1adda0408d390b4a62 Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Thu, 21 Nov 2024 02:57:56 +0000 Subject: [PATCH 3/4] fix --- core/app_config/AppConfig.cpp | 4 ++++ core/common/version.h | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/app_config/AppConfig.cpp b/core/app_config/AppConfig.cpp index 9556a554e3..f2b1b4750e 100644 --- a/core/app_config/AppConfig.cpp +++ b/core/app_config/AppConfig.cpp @@ -40,6 +40,10 @@ using namespace std; +#define ILOGTAIL_PREFIX "ilogtail_" +#define ILOGTAIL_PIDFILE_SUFFIX ".pid" +#define LOONGCOLLECTOR_PREFIX "loongcollector_" + DEFINE_FLAG_BOOL(logtail_mode, "logtail mode", false); DEFINE_FLAG_INT32(max_buffer_num, "max size", 40); DEFINE_FLAG_INT32(pub_max_buffer_num, "max size", 8); diff --git a/core/common/version.h b/core/common/version.h index f0c5fa2eb0..bd72e863c7 100644 --- a/core/common/version.h +++ b/core/common/version.h @@ -22,8 +22,4 @@ extern const char* const ILOGTAIL_UPDATE_SUFFIX; extern const char* const ILOGTAIL_GIT_HASH; extern const char* const ILOGTAIL_BUILD_DATE; -#define ILOGTAIL_PREFIX "ilogtail_" -#define ILOGTAIL_PIDFILE_SUFFIX ".pid" -#define LOONGCOLLECTOR_PREFIX "loongcollector_" - #endif \ No newline at end of file From ed3a326696faefe08eea27e302a19fd1fc8aed79 Mon Sep 17 00:00:00 2001 From: quzard <1191890118@qq.com> Date: Fri, 22 Nov 2024 07:55:54 +0000 Subject: [PATCH 4/4] rename --- core/app_config/AppConfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/app_config/AppConfig.cpp b/core/app_config/AppConfig.cpp index f2b1b4750e..6831470410 100644 --- a/core/app_config/AppConfig.cpp +++ b/core/app_config/AppConfig.cpp @@ -1538,8 +1538,8 @@ void AppConfig::ReadFlagsFromMap(const std::unordered_map sIgnoreKeySet = {"data_server_list", "legacy_data_server_list"}; - const static unordered_set sForceKeySet = {"config_server_address_list", "config_server_list"}; + const static unordered_set sIgnoreKeySet = {"data_server_list", "data_servers"}; + const static unordered_set sForceKeySet = {"config_server_address_list", "config_servers"}; for (auto name : confJson.getMemberNames()) { auto jsonvalue = confJson[name]; string fullName;