You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2025/09/16 12:59:33 UTC
(nifi-minifi-cpp) 04/04: MINIFICPP-2627 Fix ${MINIFI_HOME} in config files
This is an automated email from the ASF dual-hosted git repository.
szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 857ed5bf20112e8d4a15e7d22fbc8cb912060be9
Author: Martin Zink <ma...@apache.org>
AuthorDate: Tue Sep 16 14:46:11 2025 +0200
MINIFICPP-2627 Fix ${MINIFI_HOME} in config files
Closes #2027
Signed-off-by: Marton Szasz <sz...@apache.org>
---
CONFIGURE.md | 2 +-
bin/CMakeLists.txt | 4 +++-
bin/minifi.service.in | 1 +
controller/MiNiFiController.cpp | 2 +-
core-framework/include/Defaults.h | 4 ++--
core-framework/include/utils/Locations.h | 14 +++++++++++---
docker/installed/rpm.Dockerfile | 2 +-
minifi_main/MainHelper.cpp | 10 +++-------
minifi_main/MiNiFiMain.cpp | 2 +-
9 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/CONFIGURE.md b/CONFIGURE.md
index 40df3bbb8..1745d6d7f 100644
--- a/CONFIGURE.md
+++ b/CONFIGURE.md
@@ -80,7 +80,7 @@
The `MINIFI_HOME` environment variable should point to the installation directory, if `MINIFI_HOME` is not defined, MiNiFi will try to infer it from binary's location.
### Filesystem Hierarchy Standard installation (from .rpm package)
-The `MINIFI_HOME` environment variable should be set to `FHS`. If `MINIFI_HOME` is not defined but the binary is in the `/usr/bin` directory it will try to run as an FHS application.
+The `MINIFI_INSTALLATION_TYPE` environment variable should be set to `FHS`. If `MINIFI_HOME` and `MINIFI_INSTALLATION_TYPE` are both undefined but the binary is in the `/usr/bin` directory it will try to run as an FHS application.
## Configuring
diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt
index f1869fbdd..0f6efb680 100644
--- a/bin/CMakeLists.txt
+++ b/bin/CMakeLists.txt
@@ -25,9 +25,11 @@ endif()
if (MINIFI_PACKAGING_TYPE STREQUAL "RPM")
- set(MINIFI_HOME_ENV_VALUE "FHS")
+ set(MINIFI_INSTALLATION_TYPE_ENV_VALUE "FHS")
+ set(MINIFI_HOME_ENV_VALUE "")
set(MINIFI_EXEC_PATH "/usr/bin/minifi")
elseif (MINIFI_PACKAGING_TYPE STREQUAL "TGZ")
+ set(MINIFI_INSTALLATION_TYPE_ENV_VALUE "")
set(MINIFI_HOME_ENV_VALUE "/opt/minifi-cpp")
set(MINIFI_EXEC_PATH "/opt/minifi-cpp/bin/minifi")
else()
diff --git a/bin/minifi.service.in b/bin/minifi.service.in
index eb78573ce..2c7f84068 100644
--- a/bin/minifi.service.in
+++ b/bin/minifi.service.in
@@ -5,6 +5,7 @@ After=network.target
[Service]
Type=simple
Environment=MINIFI_HOME=@MINIFI_HOME_ENV_VALUE@
+Environment=MINIFI_INSTALLATION_TYPE=@MINIFI_INSTALLATION_TYPE_ENV_VALUE@
ExecStart=@MINIFI_EXEC_PATH@
Restart=on-failure
RestartSec=3
diff --git a/controller/MiNiFiController.cpp b/controller/MiNiFiController.cpp
index c2542e331..3b52599be 100644
--- a/controller/MiNiFiController.cpp
+++ b/controller/MiNiFiController.cpp
@@ -98,7 +98,7 @@ int main(int argc, char **argv) {
// determineLocations already logged everything we need
return -1;
}
- minifi::utils::Environment::setEnvironmentVariable(std::string(MINIFI_WORKING_DIR).c_str(), locations->working_dir_.string().c_str());
+ minifi::utils::Environment::setEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str(), locations->working_dir_.string().c_str());
const auto configuration = std::make_shared<minifi::ConfigureImpl>();
diff --git a/core-framework/include/Defaults.h b/core-framework/include/Defaults.h
index 2f809914c..899566297 100644
--- a/core-framework/include/Defaults.h
+++ b/core-framework/include/Defaults.h
@@ -28,5 +28,5 @@ const inline std::filesystem::path DEFAULT_UID_PROPERTIES_FILE = std::filesystem
const inline std::filesystem::path DEFAULT_BOOTSTRAP_FILE = std::filesystem::path("conf") / "bootstrap.conf";
constexpr inline std::string_view MINIFI_HOME_ENV_KEY = "MINIFI_HOME";
-constexpr inline std::string_view MINIFI_WORKING_DIR = "MINIFI_WORKING_DIR";
-constexpr inline std::string_view MINIFI_HOME_ENV_VALUE_FHS = "FHS";
+constexpr inline std::string_view MINIFI_INSTALLATION_TYPE_ENV_KEY = "MINIFI_INSTALLATION_TYPE";
+constexpr inline std::string_view MINIFI_INSTALLATION_TYPE_FHS = "FHS";
diff --git a/core-framework/include/utils/Locations.h b/core-framework/include/utils/Locations.h
index 89e127422..0083acdd5 100644
--- a/core-framework/include/utils/Locations.h
+++ b/core-framework/include/utils/Locations.h
@@ -18,22 +18,30 @@
#include <filesystem>
+#include "Defaults.h"
#include "Environment.h"
#include "file/FileUtils.h"
-#include "Defaults.h"
namespace org::apache::nifi::minifi::utils {
+inline bool isFhsMode() {
+ const auto minifi_installation_type_env = utils::Environment::getEnvironmentVariable(std::string(MINIFI_INSTALLATION_TYPE_ENV_KEY).c_str());
+ const auto minifi_home_env = utils::Environment::getEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str());
+ const auto executable_path = utils::file::get_executable_path();
+ return minifi_installation_type_env == MINIFI_INSTALLATION_TYPE_FHS
+ || (!minifi_home_env.has_value() && executable_path.parent_path() == "/usr/bin");
+}
+
inline std::string_view getDefaultExtensionsPattern() {
static constexpr std::string_view DEFAULT_EXTENSION_PATH = "../extensions/*";
static constexpr std::string_view DEFAULT_EXTENSION_PATH_RPM = RPM_LIB_DIR "/extensions/*";
- if (Environment::getEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str()) == MINIFI_HOME_ENV_VALUE_FHS || file::get_executable_path().parent_path() == "/usr/bin") {
+ if (isFhsMode()) {
return DEFAULT_EXTENSION_PATH_RPM;
}
return DEFAULT_EXTENSION_PATH;
}
inline std::filesystem::path getMinifiDir() {
- if (const auto working_dir_from_env = Environment::getEnvironmentVariable(std::string(MINIFI_WORKING_DIR).c_str())) {
+ if (const auto working_dir_from_env = Environment::getEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str())) {
return *working_dir_from_env;
}
diff --git a/docker/installed/rpm.Dockerfile b/docker/installed/rpm.Dockerfile
index 374aebcf5..e17371c3f 100644
--- a/docker/installed/rpm.Dockerfile
+++ b/docker/installed/rpm.Dockerfile
@@ -27,7 +27,7 @@ ARG UID=1001
ARG GID=1001
ENV USER minificpp
-ENV MINIFI_HOME="FHS"
+ENV MINIFI_INSTALLATION_TYPE="FHS"
COPY ${ARCHIVE_LOCATION} /tmp/minifi.rpm
diff --git a/minifi_main/MainHelper.cpp b/minifi_main/MainHelper.cpp
index a2bb8af61..bf6842acd 100644
--- a/minifi_main/MainHelper.cpp
+++ b/minifi_main/MainHelper.cpp
@@ -18,12 +18,11 @@
#include "MainHelper.h"
-#include "utils/Environment.h"
-#include "utils/StringUtils.h"
#include "Defaults.h"
+#include "utils/Environment.h"
+#include "utils/Locations.h"
#include "utils/file/FileUtils.h"
-
namespace org::apache::nifi::minifi {
bool validHome(const std::filesystem::path& home_path) {
return utils::file::exists(home_path / DEFAULT_NIFI_PROPERTIES_FILE);
@@ -134,10 +133,7 @@ Locations getFromFHS() {
}
std::optional<Locations> determineLocations(const std::shared_ptr<core::logging::Logger>& logger) {
- const auto minifi_home_env = utils::Environment::getEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str());
- const auto executable_path = utils::file::get_executable_path();
-
- if (minifi_home_env == MINIFI_HOME_ENV_VALUE_FHS || (!minifi_home_env && executable_path.parent_path() == "/usr/bin")) {
+ if (utils::isFhsMode()) {
return getFromFHS();
}
diff --git a/minifi_main/MiNiFiMain.cpp b/minifi_main/MiNiFiMain.cpp
index 6588bbd06..e7891d83c 100644
--- a/minifi_main/MiNiFiMain.cpp
+++ b/minifi_main/MiNiFiMain.cpp
@@ -272,7 +272,7 @@ int main(int argc, char **argv) {
// determineLocations already logged everything we need
return -1;
}
- minifi::utils::Environment::setEnvironmentVariable(std::string(MINIFI_WORKING_DIR).c_str(), locations->working_dir_.string().c_str());
+ minifi::utils::Environment::setEnvironmentVariable(std::string(MINIFI_HOME_ENV_KEY).c_str(), locations->working_dir_.string().c_str());
logger->log_info("MiNiFi Locations={}", *locations);
utils::FileMutex minifi_home_mtx(locations->lock_path_);