1
0
Fork 0

Implement scheme to more clever pass the directories from the build process to the run-time

We will now try to evaluate the toplevel install directory from the configured binary dir.
We will use this toplever directory when searching for other directories.
This commit is contained in:
Wilfried Goesgens 2016-08-24 14:45:08 +02:00
parent 71db758e35
commit 1f162ac882
20 changed files with 159 additions and 36 deletions

View File

@ -568,6 +568,8 @@ if (WIN32)
DESTINATION "bin/share/arangodb/"
RENAME ${ICU_DT_DEST})
else()
# other platforms don't install ICU:
set(ICU_DT_DEST "" PARENT_SCOPE)
add_custom_target(nonthinV8
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../../Installation/archive-de-thinner.sh ${V8_REL_TARGET_PATH}
COMMENT de-thins V8 .a files)

View File

@ -23,6 +23,7 @@
#include "DatabaseFeature.h"
#include "Basics/StringUtils.h"
#include "Basics/ArangoGlobalContext.h"
#include "Cluster/ServerState.h"
#include "Cluster/v8-cluster.h"
#include "GeneralServer/GeneralServerFeature.h"
@ -129,6 +130,15 @@ void DatabaseFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
// strip trailing separators
_databasePath = StringUtils::rTrim(_directory, TRI_DIR_SEPARATOR_STR);
auto ctx = ArangoGlobalContext::CONTEXT;
if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}
ctx->getCheckPath(_databasePath, "database.directory");
if (_maximalJournalSize < TRI_JOURNAL_MINIMAL_SIZE) {
LOG(FATAL) << "invalid value for '--database.maximal-journal-size'. "
"expected at least "

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "Basics/tri-strings.h"
#include "Actions/ActionFeature.h"
@ -80,7 +81,7 @@ using namespace arangodb;
using namespace arangodb::wal;
static int runServer(int argc, char** argv) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, SBIN_DIRECTORY);
context.installSegv();
context.runStartupChecks();

View File

@ -28,6 +28,7 @@
#include "Basics/ConditionLocker.h"
#include "Basics/StringUtils.h"
#include "Basics/WorkMonitor.h"
#include "Basics/ArangoGlobalContext.h"
#include "Cluster/ServerState.h"
#include "Dispatcher/DispatcherFeature.h"
#include "Dispatcher/DispatcherThread.h"
@ -147,6 +148,15 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
// remove trailing / from path and set path
_startupPath = StringUtils::rTrim(_startupPath, TRI_DIR_SEPARATOR_STR);
auto ctx = ArangoGlobalContext::CONTEXT;
if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}
ctx->getCheckPath(_startupPath, "javascript.startup-directory");
_startupLoader.setDirectory(_startupPath);
ServerState::instance()->setJavaScriptPath(_startupPath);
@ -156,6 +166,8 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
FATAL_ERROR_EXIT();
}
ctx->getCheckPath(_appPath, "javascript.app-directory");
// use a minimum of 1 second for GC
if (_gcFrequency < 1) {
_gcFrequency = 1;

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
@ -41,7 +42,7 @@ using namespace arangodb::basics;
using namespace arangodb::rest;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
@ -38,7 +39,7 @@ using namespace arangodb;
using namespace arangodb::application_features;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
@ -39,7 +40,7 @@ using namespace arangodb;
using namespace arangodb::application_features;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
@ -39,7 +40,7 @@ using namespace arangodb;
using namespace arangodb::application_features;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(

View File

@ -27,6 +27,7 @@
#include "Basics/StringUtils.h"
#include "Basics/Utf8Helper.h"
#include "Basics/shell-colors.h"
#include "Basics/ArangoGlobalContext.h"
#include "Logger/Logger.h"
#include "ProgramOptions/ProgramOptions.h"
#include "ProgramOptions/Section.h"
@ -809,6 +810,15 @@ void V8ShellFeature::initGlobals() {
TRI_V8_ASCII_STRING2(_isolate, "ARANGO_QUIET"),
v8::Boolean::New(_isolate, _console->quiet()));
auto ctx = ArangoGlobalContext::CONTEXT;
if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}
ctx->getCheckPath(_startupDirectory, "javascript.startup-directory");
// initialize standard modules
std::string modules =
FileUtils::buildFilename(_startupDirectory, "client/modules") + ";" +

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/LanguageFeature.h"
@ -43,7 +44,7 @@ using namespace arangodb;
using namespace arangodb::application_features;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::string name = context.binaryName();

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/Common.h"
#include "Basics/directories.h"
#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
@ -36,7 +37,7 @@ using namespace arangodb;
using namespace arangodb::application_features;
int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();
std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(

View File

@ -17,8 +17,6 @@ set(CMAKE_INSTALL_SYSCONFDIR_ARANGO "${CMAKE_INSTALL_SYSCONFDIR}/arangodb3")
set(CMAKE_INSTALL_FULL_SYSCONFDIR_ARANGO "${CMAKE_INSTALL_FULL_SYSCONFDIR}/arangodb3")
file(TO_NATIVE_PATH "${CMAKE_INSTALL_FULL_SYSCONFDIR_ARANGO}" ETCDIR_NATIVE)
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_NATIVE}")
add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")
# database directory
FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb3")
@ -84,6 +82,15 @@ install(
DIRECTORY ${PROJECT_BINARY_DIR}/var/lib/arangodb3-apps
DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib)
################################################################################
### @brief propagate the locations into our programms:
################################################################################
configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/directories.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/lib/Basics/directories.h"
NEWLINE_STYLE UNIX
)
# sub directories --------------------------------------------------------------
@ -106,8 +113,8 @@ install(
#--------------------------------------------------------------------------------
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
#--------------------------------------------------------------------------------

View File

@ -40,7 +40,7 @@ set(PROJECT_SOURCE_DIR @PROJECT_SOURCE_DIR@)
################################################################################
# Get the final values for cpack:
################################################################################
set(CPACK_GENERATOR "DEB")
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_VERSION "${ARANGODB_VERSION}")
set(CPACK_PACKAGE_NAME "arangodb3-client")
set(CPACK_PACKAGE_CONTACT ${ARANGODB_PACKAGE_CONTACT})

View File

@ -24,8 +24,10 @@
#include <iostream>
#include "Basics/directories.h"
#include "Basics/FileUtils.h"
#include "Basics/StringUtils.h"
#include "Basics/ArangoGlobalContext.h"
#include "Logger/Logger.h"
#include "ProgramOptions/IniFileParser.h"
#include "ProgramOptions/ProgramOptions.h"
@ -119,38 +121,49 @@ void ConfigFeature::loadConfigFile(std::shared_ptr<ProgramOptions> options,
//
// clang-format on
auto context = ArangoGlobalContext::CONTEXT;
std::string basename = name + ".conf";
std::string filename =
FileUtils::buildFilename(FileUtils::currentDirectory(), basename);
std::string filename;
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (context != nullptr) {
filename = FileUtils::buildFilename(FileUtils::buildFilename(context->runRoot(), _SYSCONFDIR_), basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
}
if (!FileUtils::exists(filename)) {
filename = FileUtils::buildFilename(FileUtils::currentDirectory(),
"etc/relative/" + basename);
if (filename.length() == 0 || !FileUtils::exists(filename)) {
filename = FileUtils::buildFilename(FileUtils::currentDirectory(), basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (!FileUtils::exists(filename)) {
filename =
FileUtils::buildFilename(FileUtils::homeDirectory(), basename);
filename = FileUtils::buildFilename(FileUtils::currentDirectory(),
"etc/relative/" + basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (!FileUtils::exists(filename)) {
filename =
FileUtils::buildFilename(FileUtils::configDirectory(), basename);
FileUtils::buildFilename(FileUtils::homeDirectory(), basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (!FileUtils::exists(filename)) {
LOG_TOPIC(DEBUG, Logger::CONFIG) << "cannot find any config file";
return;
filename =
FileUtils::buildFilename(FileUtils::configDirectory(), basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (!FileUtils::exists(filename)) {
LOG_TOPIC(DEBUG, Logger::CONFIG) << "cannot find any config file";
return;
}
}
}
}
}
IniFileParser parser(options.get());
std::string local = filename + ".local";

View File

@ -28,9 +28,7 @@
#include "Basics/debugging.h"
#include "Basics/files.h"
#ifdef __arm__
#include "Basics/FileUtils.h"
#endif
#include "Logger/LogAppender.h"
#include "Logger/Logger.h"
#include "Rest/InitializeRest.h"
@ -110,8 +108,11 @@ LONG CALLBACK unhandledExceptionHandler(EXCEPTION_POINTERS* e) {
ArangoGlobalContext* ArangoGlobalContext::CONTEXT = nullptr;
ArangoGlobalContext::ArangoGlobalContext(int argc, char* argv[])
: _binaryName(TRI_BinaryName(argv[0])), _ret(EXIT_FAILURE), _useEventLog(true) {
ArangoGlobalContext::ArangoGlobalContext(int argc, char* argv[], const char *InstallDirectory)
: _binaryName(TRI_BinaryName(argv[0])),
_runRoot(TRI_GetInstallRoot(TRI_LocateBinaryPath(argv[0]), InstallDirectory)),
_ret(EXIT_FAILURE),
_useEventLog(true) {
static char const* serverName = "arangod";
if (_binaryName.size() < strlen(serverName) ||
@ -271,3 +272,15 @@ void ArangoGlobalContext::tempPathAvailable() {
"\\minidump_" + std::to_string(GetCurrentProcessId()) + ".dmp";
#endif
}
void ArangoGlobalContext::getCheckPath(std::string &path, const char *whichPath) {
if (!arangodb::basics::FileUtils::exists(path)) {
std::string directory;
directory = arangodb::basics::FileUtils::buildFilename(_runRoot, path);
if (!arangodb::basics::FileUtils::exists(directory)) {
LOG(ERR) << "failed to locate " << whichPath << " directory, its neither available in '" << path << "' nor in '" << directory << "'";
FATAL_ERROR_EXIT();
}
path = directory;
}
}

View File

@ -31,11 +31,13 @@ class ArangoGlobalContext {
static ArangoGlobalContext* CONTEXT;
public:
ArangoGlobalContext(int argc, char* argv[]);
ArangoGlobalContext(int argc, char* argv[], const char *InstallDirectory);
~ArangoGlobalContext();
public:
std::string binaryName() { return _binaryName; }
std::string runRoot() { return _runRoot; }
void getCheckPath(std::string &path, const char *whichPath);
int exit(int ret);
void installHup();
void installSegv();
@ -47,6 +49,7 @@ class ArangoGlobalContext {
private:
std::string _binaryName;
std::string _runRoot;
int _ret;
bool _useEventLog;
};

View File

@ -0,0 +1,7 @@
#define LOCCAL_STATE_DIR "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@"
#define _SYSCONFDIR_ "@ETCDIR_NATIVE@"
#define STARTUP_DIRECTORY "@PKGDATADIR@/js"
#define DESTINATION_DIR "@CMAKE_INSTALL_DATAROOTDIR_ARANGO@/js"
#define ICU_DESTINATION_DIRECTORY "@ICU_DT_DEST@"
#define SBIN_DIRECTORY "@CMAKE_INSTALL_SBINDIR@"
#define BIN_DIRECTORY "@CMAKE_INSTALL_BINDIR@"

View File

@ -27,6 +27,7 @@
#include <tchar.h>
#endif
#include "Basics/directories.h"
#include "Basics/FileUtils.h"
#include "Basics/Mutex.h"
#include "Basics/MutexLocker.h"
@ -1647,6 +1648,9 @@ std::string TRI_LocateBinaryPath(char const* argv0) {
binaryPath = TRI_DuplicateString("");
TRI_FreeString(TRI_CORE_MEM_ZONE, dir);
}
else {
binaryPath = dir;
}
}
// check PATH variable
@ -1693,6 +1697,34 @@ std::string TRI_LocateBinaryPath(char const* argv0) {
return result;
}
std::string TRI_GetInstallRoot(std::string const& binaryPath,
char const *installBinaryPath) {
// First lets remove trailing (back) slashes from the bill:
long ibpLength = strlen(installBinaryPath);
if (installBinaryPath[ibpLength - 1] == TRI_DIR_SEPARATOR_CHAR) {
ibpLength --;
}
long bpLength = binaryPath.length();
const char *pbPath = binaryPath.c_str();
if (pbPath[bpLength - 1] == TRI_DIR_SEPARATOR_CHAR) {
bpLength --;
}
if (ibpLength > bpLength) {
return TRI_DIR_SEPARATOR_STR;
}
for (int i = 1; i < ibpLength; i ++) {
if (pbPath[bpLength -i] != installBinaryPath[ibpLength - i]) {
return TRI_DIR_SEPARATOR_STR;
}
}
return std::string(pbPath, bpLength - ibpLength);
}
static bool CopyFileContents(int srcFD, int dstFD, ssize_t fileSize,
std::string& error) {
bool rc = true;
@ -2329,11 +2361,7 @@ char* TRI_LocateConfigDirectory() {
std::string r = TRI_LocateInstallDirectory();
#ifdef _SYSCONFDIR_
r += _SYSCONFDIR_;
#else
r += "etc\\arangodb3";
#endif
r += std::string(1, TRI_DIR_SEPARATOR_CHAR);

View File

@ -256,6 +256,16 @@ std::string TRI_BinaryName(char const* argv0);
std::string TRI_LocateBinaryPath(char const* argv0);
////////////////////////////////////////////////////////////////////////////////
/// @brief locates toplevel install directory
/// tries to substract InstallBinaryPath righthandside from binaryPath
/// (if equal) and returns either "/" if not, or the part of binaryPath
/// that is left of InstallBinaryPath:
/// /opt/usr/bin /usr/bin/ => /opt/
////////////////////////////////////////////////////////////////////////////////
std::string TRI_GetInstallRoot(std::string const& binaryPath, char const *installBinaryPath);
////////////////////////////////////////////////////////////////////////////////
/// @brief locates the home directory
////////////////////////////////////////////////////////////////////////////////

View File

@ -36,6 +36,7 @@
#include "Basics/files.h"
#include "Basics/StringUtils.h"
#include "Basics/tri-strings.h"
#include "Basics/directories.h"
using namespace arangodb::basics;
@ -319,7 +320,7 @@ void TRI_FixIcuDataEnv() {
std::string p = TRI_LocateInstallDirectory();
if (!p.empty()) {
std::string e = "ICU_DATA=" + p + "share\\arangodb3\\";
std::string e = "ICU_DATA=" + p + ICU_DESTINATION_DIRECTORY;
e = StringUtils::replace(e, "\\", "\\\\");
putenv(e.c_str());
} else {