From 1e0bec7f1d5ecfd0d8fd56afc90e34da7d5be0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Thu, 23 Jul 2015 13:12:41 +0200 Subject: [PATCH 1/5] mongodb: add recipe --- ...-fix-compilation-errors-with-v8-3.25.patch | 74 +++++++++++++++ ...ing-boost-library-in-third-party-src.patch | 25 ++++++ ...-missing-search-for-system-asio-libs.patch | 51 +++++++++++ ...ation-context-to-allow-dereferencing.patch | 24 +++++ ...ate-execution-environment-into-SCons.patch | 25 ++++++ ...rguments-to-boost-mutex-constructors.patch | 34 +++++++ .../0001-remove-debug-flag-from-build.patch | 24 +++++ recipes/mongodb/mongodb.inc | 90 +++++++++++++++++++ recipes/mongodb/mongodb_3.1.6.oe | 1 + recipes/mongodb/mongodb_3.1.6.oe.sig | 1 + 10 files changed, 349 insertions(+) create mode 100644 recipes/mongodb/files/0001-fix-compilation-errors-with-v8-3.25.patch create mode 100644 recipes/mongodb/files/0001-fix-missing-boost-library-in-third-party-src.patch create mode 100644 recipes/mongodb/files/0001-fix-missing-search-for-system-asio-libs.patch create mode 100644 recipes/mongodb/files/0001-include-operation-context-to-allow-dereferencing.patch create mode 100644 recipes/mongodb/files/0001-propagate-execution-environment-into-SCons.patch create mode 100644 recipes/mongodb/files/0001-remove-char-arguments-to-boost-mutex-constructors.patch create mode 100644 recipes/mongodb/files/0001-remove-debug-flag-from-build.patch create mode 100644 recipes/mongodb/mongodb.inc create mode 100644 recipes/mongodb/mongodb_3.1.6.oe create mode 100644 recipes/mongodb/mongodb_3.1.6.oe.sig diff --git a/recipes/mongodb/files/0001-fix-compilation-errors-with-v8-3.25.patch b/recipes/mongodb/files/0001-fix-compilation-errors-with-v8-3.25.patch new file mode 100644 index 000000000..e6fb55ede --- /dev/null +++ b/recipes/mongodb/files/0001-fix-compilation-errors-with-v8-3.25.patch @@ -0,0 +1,74 @@ +From be4275d5af4f59024ebcfeb677706687c670611a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Wed, 22 Jul 2015 15:12:27 +0200 +Subject: [PATCH] fix compilation errors with v8-3.25 + +--- + src/mongo/scripting/engine_v8-3.25.cpp | 6 +++--- + src/mongo/scripting/v8-3.25_db.cpp | 5 +++-- + 2 files changed, 6 insertions(+), 5 deletions(-) + +diff --git a/src/mongo/scripting/engine_v8-3.25.cpp b/src/mongo/scripting/engine_v8-3.25.cpp +index 14b2a43..bfbb3ce 100644 +--- a/src/mongo/scripting/engine_v8-3.25.cpp ++++ b/src/mongo/scripting/engine_v8-3.25.cpp +@@ -1501,7 +1501,7 @@ v8::Local V8Scope::mongoToV8Element(const BSONElement& elem, bool rea + case mongo::Object: + return mongoToLZV8(elem.embeddedObject(), readOnly); + case mongo::Date: +- return v8::Date::New(_isolate, static_cast(elem.date.toMillisSinceEpoch())); ++ return v8::Date::New(_isolate, static_cast(elem.Date().toMillisSinceEpoch())); + case mongo::Bool: + return v8::Boolean::New(_isolate, elem.boolean()); + case mongo::EOO: +@@ -1536,7 +1536,7 @@ v8::Local V8Scope::mongoToV8Element(const BSONElement& elem, bool rea + case mongo::bsonTimestamp: { + v8::TryCatch tryCatch; + +- argv[0] = v8::Number::New(_isolate, elem.timestampTime() / 1000); ++ argv[0] = v8::Number::New(_isolate, elem.timestampTime().toMillisSinceEpoch() / 1000); + argv[1] = v8::Number::New(_isolate, elem.timestampInc()); + + v8::Local ret = TimestampFT()->GetFunction()->NewInstance(2, argv); +@@ -1721,7 +1721,7 @@ void V8Scope::v8ToMongoElement(BSONObjBuilder& b, + } + if (value->IsDate()) { + long long dateval = (long long)(v8::Date::Cast(*value)->NumberValue()); +- b.appendDate(sname, Date_t((unsigned long long)dateval)); ++ b.appendDate(sname, Date_t().fromMillisSinceEpoch((unsigned long long)dateval)); + return; + } + if (value->IsExternal()) +diff --git a/src/mongo/scripting/v8-3.25_db.cpp b/src/mongo/scripting/v8-3.25_db.cpp +index e4fd6d8..9e81974 100644 +--- a/src/mongo/scripting/v8-3.25_db.cpp ++++ b/src/mongo/scripting/v8-3.25_db.cpp +@@ -42,6 +42,7 @@ + #include "mongo/util/base64.h" + #include "mongo/util/hex.h" + #include "mongo/util/text.h" ++#include "mongo/bson/timestamp.h" + + using namespace std; + using std::unique_ptr; +@@ -135,7 +136,7 @@ v8::Local mongoConsExternal(V8Scope* scope, + verify(scope->MongoFT()->HasInstance(args.This())); + + auto statusWithHost = ConnectionString::parse(host); +- if (!status.isOK()) { ++ if (!statusWithHost.isOK()) { + return v8AssertionException(statusWithHost.getStatus().reason()); + } + +@@ -774,7 +775,7 @@ v8::Local dbTimestampInit(V8Scope* scope, + return v8AssertionException("Timestamp increment must be a number"); + } + int64_t t = args[0]->IntegerValue(); +- int64_t largestVal = int64_t(OpTime::max().getSecs()); ++ int64_t largestVal = int64_t(Timestamp::max().getSecs()); + if (t > largestVal) + return v8AssertionException(str::stream() << "The first argument must be in seconds; " + << t << " is too large (max " << largestVal +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-fix-missing-boost-library-in-third-party-src.patch b/recipes/mongodb/files/0001-fix-missing-boost-library-in-third-party-src.patch new file mode 100644 index 000000000..3141022df --- /dev/null +++ b/recipes/mongodb/files/0001-fix-missing-boost-library-in-third-party-src.patch @@ -0,0 +1,25 @@ +From 4bafababda82061329c705f80c58e555bb21d407 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Tue, 21 Jul 2015 08:18:17 +0200 +Subject: [PATCH] fix missing boost library in third party src + +--- + SConstruct | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/SConstruct b/SConstruct +index 5c8d414..aa22aed 100644 +--- a/SConstruct ++++ b/SConstruct +@@ -729,7 +729,7 @@ def printLocalInfo(): + + printLocalInfo() + +-boostLibs = [ "thread" , "filesystem" , "program_options", "system" ] ++boostLibs = [ "thread" , "filesystem" , "program_options", "system", "chrono" ] + + onlyServer = len( COMMAND_LINE_TARGETS ) == 0 or ( len( COMMAND_LINE_TARGETS ) == 1 and str( COMMAND_LINE_TARGETS[0] ) in [ "mongod" , "mongos" , "test" ] ) + +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-fix-missing-search-for-system-asio-libs.patch b/recipes/mongodb/files/0001-fix-missing-search-for-system-asio-libs.patch new file mode 100644 index 000000000..724462f82 --- /dev/null +++ b/recipes/mongodb/files/0001-fix-missing-search-for-system-asio-libs.patch @@ -0,0 +1,51 @@ +From e79f7c8ae7b0ff2459a8136106a0692594ba0202 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Tue, 21 Jul 2015 11:17:19 +0200 +Subject: [PATCH] fix missing search for system asio libs + +--- + SConstruct | 3 +++ + src/third_party/SConscript | 6 ++---- + 2 files changed, 5 insertions(+), 4 deletions(-) + +diff --git a/SConstruct b/SConstruct +index 1f38ab7..ba91d2a 100644 +--- a/SConstruct ++++ b/SConstruct +@@ -2203,6 +2203,9 @@ def doConfigure(myenv): + """): + conf.env.SetConfigHeaderDefine('MONGO_CONFIG_HAVE_FIPS_MODE_SET') + ++ if use_system_version_of_library("asio"): ++ conf.CheckCXXHeader("boost/asio.hpp") ++ + return conf.Finish() + + env = doConfigure( env ) +diff --git a/src/third_party/SConscript b/src/third_party/SConscript +index 594ea27..e1b4b88 100644 +--- a/src/third_party/SConscript ++++ b/src/third_party/SConscript +@@ -162,6 +162,7 @@ if use_system_version_of_library("zlib"): + SYSLIBDEPS=[ + env['LIBDEPS_ZLIB_SYSLIBDEP'], + ]) ++ print("syslibdep: {}".format(env['LIBDEPS_ZLIB_SYSLIBDEP'])) + else: + zlibEnv = env.Clone() + zlibEnv.InjectThirdPartyIncludePaths(libraries=['zlib']) +@@ -304,10 +305,7 @@ if wiredtiger: + ]) + + if use_system_version_of_library("asio"): +- asioEnv = env.Clone( +- SYSLIBDEPS=[ +- env['LIBDEPS_ASIO_SYSLIBDEP'], +- ]) ++ asioEnv = env.Clone([]) + else: + asioEnv = env.Clone() + asioEnv.InjectThirdPartyIncludePaths(libraries=['asio']) +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-include-operation-context-to-allow-dereferencing.patch b/recipes/mongodb/files/0001-include-operation-context-to-allow-dereferencing.patch new file mode 100644 index 000000000..c950648a4 --- /dev/null +++ b/recipes/mongodb/files/0001-include-operation-context-to-allow-dereferencing.patch @@ -0,0 +1,24 @@ +From 53f27a872a3ec7591a437a35c577509033a35d19 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Thu, 23 Jul 2015 10:35:34 +0200 +Subject: [PATCH] include operation context to allow dereferencing + +--- + src/mongo/scripting/v8-3.25_db.cpp | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/mongo/scripting/v8-3.25_db.cpp b/src/mongo/scripting/v8-3.25_db.cpp +index e4fd6d8..bef068c 100644 +--- a/src/mongo/scripting/v8-3.25_db.cpp ++++ b/src/mongo/scripting/v8-3.25_db.cpp +@@ -35,6 +35,7 @@ + #include "mongo/base/init.h" + #include "mongo/client/sasl_client_authenticate.h" + #include "mongo/db/namespace_string.h" ++#include "mongo/db/operation_context.h" + #include "mongo/s/d_state.h" + #include "mongo/scripting/engine_v8-3.25.h" + #include "mongo/scripting/v8-3.25_utils.h" +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-propagate-execution-environment-into-SCons.patch b/recipes/mongodb/files/0001-propagate-execution-environment-into-SCons.patch new file mode 100644 index 000000000..c286aebf2 --- /dev/null +++ b/recipes/mongodb/files/0001-propagate-execution-environment-into-SCons.patch @@ -0,0 +1,25 @@ +From 271460f8cad7d6c114e62b4d91859b1864c07716 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Tue, 21 Jul 2015 07:25:27 +0200 +Subject: [PATCH] propagate execution environment into SCons + +--- + SConstruct | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/SConstruct b/SConstruct +index 2a7ee46..0f05ee9 100644 +--- a/SConstruct ++++ b/SConstruct +@@ -791,7 +791,7 @@ envDict = dict(BUILD_ROOT=buildDir, + CONFIG_HEADER_DEFINES={}, + ) + +-env = Environment(variables=env_vars, **envDict) ++env = Environment(variables=env_vars, ENV=os.environ, **envDict) + del envDict + + env.AddMethod(env_os_is_wrapper, 'TargetOSIs') +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-remove-char-arguments-to-boost-mutex-constructors.patch b/recipes/mongodb/files/0001-remove-char-arguments-to-boost-mutex-constructors.patch new file mode 100644 index 000000000..5e009cdfa --- /dev/null +++ b/recipes/mongodb/files/0001-remove-char-arguments-to-boost-mutex-constructors.patch @@ -0,0 +1,34 @@ +From 26c0780746aecedf9d6fb73f0171620790638000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Wed, 22 Jul 2015 14:26:03 +0200 +Subject: [PATCH] remove char arguments to boost::mutex constructors + +--- + src/mongo/scripting/engine_v8-3.25.cpp | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/mongo/scripting/engine_v8-3.25.cpp b/src/mongo/scripting/engine_v8-3.25.cpp +index b7f241c..14b2a43 100644 +--- a/src/mongo/scripting/engine_v8-3.25.cpp ++++ b/src/mongo/scripting/engine_v8-3.25.cpp +@@ -382,7 +382,7 @@ void gcCallback(v8::GCType type, v8::GCCallbackFlags flags) { + } + + V8ScriptEngine::V8ScriptEngine() +- : _globalInterruptLock("GlobalV8InterruptLock"), _opToScopeMap(), _deadlineMonitor() {} ++ : _globalInterruptLock(), _opToScopeMap(), _deadlineMonitor() {} + + V8ScriptEngine::~V8ScriptEngine() {} + +@@ -525,7 +525,7 @@ V8Scope::V8Scope(V8ScriptEngine* engine) + : _engine(engine), + _connectState(NOT), + _cpuProfiler(), +- _interruptLock("ScopeInterruptLock"), ++ _interruptLock(), + _inNativeExecution(true), + _pendingKill(false), + _opId(0), +-- +2.4.6 + diff --git a/recipes/mongodb/files/0001-remove-debug-flag-from-build.patch b/recipes/mongodb/files/0001-remove-debug-flag-from-build.patch new file mode 100644 index 000000000..4626fde83 --- /dev/null +++ b/recipes/mongodb/files/0001-remove-debug-flag-from-build.patch @@ -0,0 +1,24 @@ +From fa0455b9e9cb61afd90e07c5fdf9fb3517bd06c4 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Thu, 23 Jul 2015 11:57:23 +0200 +Subject: [PATCH] remove debug flag from build + +--- + SConstruct | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/SConstruct b/SConstruct +index 0a3273a..908d726 100644 +--- a/SConstruct ++++ b/SConstruct +@@ -1216,7 +1216,6 @@ if env.TargetOSIs('posix'): + env.Append( CCFLAGS=["-fno-omit-frame-pointer", + "-fPIC", + "-fno-strict-aliasing", +- "-ggdb", + "-pthread", + "-Wall", + "-Wsign-compare", +-- +2.4.6 + diff --git a/recipes/mongodb/mongodb.inc b/recipes/mongodb/mongodb.inc new file mode 100644 index 000000000..b4e762166 --- /dev/null +++ b/recipes/mongodb/mongodb.inc @@ -0,0 +1,90 @@ +DESCRIPTION = "MongoDB is the next-generation database that lets you create applications never before possible." +LICENSE = "AGPL-3.0 Apache-2.0" + +inherit scons c++ auto-package-utils + +DEPENDS = " \ + libv8 \ + libv8-dev \ + openssl \ + libpthread \ + libpcre \ + pcre-libpcrecpp \ + libpcap \ + libz \ + libsnappy \ + libsnappy-dev \ + libstemmer \ + libstemmer-dev \ + libyaml-cpp \ + libyaml-cpp-dev \ + gperftools-dev \ + gperftools-libtcmalloc \ + gperftools-libtcmalloc-dev \ + boost-dev \ + libprogram-options \ + libsystem \ + libfilesystem \ + libchrono \ + libthread \ + asio-dev \ +" + +SRC_URI = " \ + https://fastdl.mongodb.org/src/mongodb-src-r${PV}.tar.gz \ + file://0001-fix-compilation-errors-with-v8-3.25.patch \ + file://0001-fix-missing-search-for-system-asio-libs.patch \ + file://0001-propagate-execution-environment-into-SCons.patch \ + file://0001-fix-missing-boost-library-in-third-party-src.patch \ + file://0001-remove-char-arguments-to-boost-mutex-constructors.patch \ + file://0001-include-operation-context-to-allow-dereferencing.patch \ + file://0001-remove-debug-flag-from-build.patch \ +" + +S = "${SRCDIR}/mongodb-src-r${PV}/" + +EXTRA_OESCONS = "--ssl \ + --wiredtiger=off \ + --use-system-all \ + --js-engine=v8-3.25 \ + --disable-warnings-as-errors \ + --release \ + TARGET_ARCH=arm \ + TARGET_OS=linux \ + LINKFLAGS=-L${MACHINE_SYSROOT}/usr/lib \ + all \ +" + +AUTO_PACKAGE_UTILS = "mongo mongod mongoperf mongos mongosniff" + +RDEPENDS_COMMON = " \ + libpcre \ + libpcrecpp \ + libprogram-options \ + libfilesystem \ + libthread \ + libsystem \ + libchrono \ + libyaml-cpp \ + libv8-3 \ + gperftools-libtcmalloc \ + openssl \ + librt \ + libdl \ + libstdc++ \ + libm \ + libgcc \ + libpthread \ + libc \ +" + +DEPENDS_${PN}-mongo = "${RDEPENDS_COMMON}" +DEPENDS_${PN}-mongod = "${RDEPENDS_COMMON} libsnappy" +DEPENDS_${PN}-mongoperf = "${RDEPENDS_COMMON} libsnappy" +DEPENDS_${PN}-mongos = "${RDEPENDS_COMMON} libsnappy" +DEPENDS_${PN}-mongosniff = "${RDEPENDS_COMMON} libpcap libsnappy" +RDEPENDS_${PN}-mongo = "${RDEPENDS_COMMON}" +RDEPENDS_${PN}-mongod = "${RDEPENDS_COMMON} libsnappy" +RDEPENDS_${PN}-mongoperf = "${RDEPENDS_COMMON} libsnappy" +RDEPENDS_${PN}-mongos = "${RDEPENDS_COMMON} libsnappy" +RDEPENDS_${PN}-mongosniff = "${RDEPENDS_COMMON} libpcap libsnappy" diff --git a/recipes/mongodb/mongodb_3.1.6.oe b/recipes/mongodb/mongodb_3.1.6.oe new file mode 100644 index 000000000..7c90b135b --- /dev/null +++ b/recipes/mongodb/mongodb_3.1.6.oe @@ -0,0 +1 @@ +require mongodb.inc diff --git a/recipes/mongodb/mongodb_3.1.6.oe.sig b/recipes/mongodb/mongodb_3.1.6.oe.sig new file mode 100644 index 000000000..1030a7827 --- /dev/null +++ b/recipes/mongodb/mongodb_3.1.6.oe.sig @@ -0,0 +1 @@ +dd4a67562d55dd784de60c7d55948f54a5dfc9e3 mongodb-src-r3.1.6.tar.gz From 82c3da853df84d7a63c6893a676dbc74ebfbd3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Tue, 29 Sep 2015 12:56:13 +0200 Subject: [PATCH 2/5] mongodb: change libv8-3 in rdepends to libv8 the trailing dash was a leftover from the development process. --- recipes/mongodb/mongodb.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/mongodb/mongodb.inc b/recipes/mongodb/mongodb.inc index b4e762166..11b7ed170 100644 --- a/recipes/mongodb/mongodb.inc +++ b/recipes/mongodb/mongodb.inc @@ -66,7 +66,7 @@ RDEPENDS_COMMON = " \ libsystem \ libchrono \ libyaml-cpp \ - libv8-3 \ + libv8 \ gperftools-libtcmalloc \ openssl \ librt \ From 1557d66c74927383043a365b3df5eed77c957694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Thu, 29 Oct 2015 23:16:06 +0100 Subject: [PATCH 3/5] mongodb: add init script Add init script to mongodb recipe. The script runs mongod --repair if lock file is present, and, if case recover fails, wipes the database! The default data base path (/data/db) can be changed by setting USE_mongodb_db_path. --- recipes/mongodb/files/init | 112 ++++++++++++++++++++++++++++++++++++ recipes/mongodb/mongodb.inc | 22 ++++++- 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100755 recipes/mongodb/files/init diff --git a/recipes/mongodb/files/init b/recipes/mongodb/files/init new file mode 100755 index 000000000..5a51a6534 --- /dev/null +++ b/recipes/mongodb/files/init @@ -0,0 +1,112 @@ +#!/bin/sh +# +# Do not configure this file. Edit /etc/default/mongodb instead +# + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/bin/mongod +NAME=mongod +DESC="Mongo Database Server" + +MONGOD_PID_FILE="/var/run/mongod.pid" +MONGOD_DB_PATH="/data/db" +MONGOD_LOCK_FILE="$MONGOD_DB_PATH/mongod.lock" +MONGOD_STORAGE_ENGINE="mmapv1" +MONGOD_EXTRA_ARGS="" + +set -e + +test -r /etc/default/mongod && . /etc/default/mongod +test -x "$DAEMON" || exit 0 + +init_is_running() { + [ -e $MONGOD_PID_FILE ] || return 1 + [ -d /proc/$(cat $MONGOD_PID_FILE) ] || return 1 + return 0 +} + +init_start() { + [ -d $MONGOD_DB_PATH ] || mkdir -p $MONGOD_DB_PATH + + echo -n "Starting $DESC: " + start-stop-daemon -S \ + -x "$DAEMON" \ + -p $MONGOD_PID_FILE -- \ + --syslog \ + --fork \ + --quiet \ + --dbpath $MONGOD_DB_PATH \ + --pidfilepath $MONGOD_PID_FILE \ + --storageEngine $MONGOD_STORAGE_ENGINE \ + $MONGOD_EXTRA_ARGS \ + 2>&1 | logger + echo "$NAME" +} + +init_start_repair() { + echo -n "Repairing database: " + $DAEMON \ + --syslog \ + --quiet \ + --dbpath $MONGOD_DB_PATH \ + --storageEngine $MONGOD_STORAGE_ENGINE \ + --repair \ + 2>&1 | logger + + if [ -s $MONGOD_LOCK_FILE ]; then + echo "FAIL" + echo -n "Wiping database path: " + rm -rf $MONGOD_DB_PATH/* + echo "OK" + else + echo "OK" + fi +} + +init_stop() { + ignore_error=$1 + echo -n "Stopping $DESC: " + start-stop-daemon -K \ + -x "$DAEMON" \ + -p $MONGOD_PID_FILE \ + -s 2 \ + 2>&1 | logger && echo "OK" + rm -f $MONGOD_PID_FILE +} + +init_stop_wait() { + echo -n "Waiting for daemon to exit: " + for i in $(seq 10) "failed"; do + [ -s $MONGOD_LOCK_FILE ] || break + echo -n "." + sleep 1 + done + + if [ $i == "failed" ]; then + echo "FAIL" + else + echo "OK" + fi +} + +case "$1" in + start) + [ -s $MONGOD_LOCK_FILE ] && ! init_is_running && init_start_repair + init_start + ;; + stop) + [ -s $MONGOD_LOCK_FILE ] && init_stop + ;; + restart) + init_is_running && init_stop && init_stop_wait + [ -s $MONGOD_LOCK_FILE ] && init_start_repair + init_start + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/recipes/mongodb/mongodb.inc b/recipes/mongodb/mongodb.inc index 11b7ed170..aab38bd1f 100644 --- a/recipes/mongodb/mongodb.inc +++ b/recipes/mongodb/mongodb.inc @@ -1,7 +1,7 @@ DESCRIPTION = "MongoDB is the next-generation database that lets you create applications never before possible." LICENSE = "AGPL-3.0 Apache-2.0" -inherit scons c++ auto-package-utils +inherit scons c++ auto-package-utils sysvinit DEPENDS = " \ libv8 \ @@ -32,6 +32,7 @@ DEPENDS = " \ SRC_URI = " \ https://fastdl.mongodb.org/src/mongodb-src-r${PV}.tar.gz \ + file://init \ file://0001-fix-compilation-errors-with-v8-3.25.patch \ file://0001-fix-missing-search-for-system-asio-libs.patch \ file://0001-propagate-execution-environment-into-SCons.patch \ @@ -57,6 +58,25 @@ EXTRA_OESCONS = "--ssl \ AUTO_PACKAGE_UTILS = "mongo mongod mongoperf mongos mongosniff" +RECIPE_FLAGS += "mongodb_db_path mongodb_sysvinit_start mongodb_sysvinit_stop" +SYSVINIT_SCRIPT_mongodb = "mongod" +DEFAULT_USE_mongodb_sysvinit_start = "70" +DEFAULT_USE_mongodb_sysvinit_stop = "0" +DEFAULT_USE_mongodb_db_path = "" + +do_install[postfuncs] =+ "do_install_init" +do_install_init[expand] = 3 # Expand empty use flag +do_install_init() { + sysvinit_install_script ${SRCDIR}/init ${SYSVINIT_SCRIPT_mongodb} + + if [ -n "${USE_mongodb_db_path}" ]; then + install -d ${D}${sysconfdir}/default + echo MONGOD_DB_PATH=${USE_mongodb_db_path} >> ${D}${sysconfdir}/default/mongod + fi +} + +FILES_${PN}-mongod += "${sysconfdir}/" + RDEPENDS_COMMON = " \ libpcre \ libpcrecpp \ From 17d11abfda6b9ddd543e600289dfee5f73e846ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Mon, 23 Nov 2015 14:03:02 +0100 Subject: [PATCH 4/5] mongodb: fix check for unclean shutdown in init script When using a non-default path for the mongo database files (e.g. /db), the check for existing lock file looked at the wrong path (/data/db). This caused the initscript to fail starting after unclean shutdowns. Fix this by avoid expansion of $MONGOD_DB_PATH when assigning the value for $MONGOD_LOCK_FILE, and use the former explicitly when checking the lock file. --- recipes/mongodb/files/init | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/recipes/mongodb/files/init b/recipes/mongodb/files/init index 5a51a6534..e5b513eef 100755 --- a/recipes/mongodb/files/init +++ b/recipes/mongodb/files/init @@ -10,7 +10,7 @@ DESC="Mongo Database Server" MONGOD_PID_FILE="/var/run/mongod.pid" MONGOD_DB_PATH="/data/db" -MONGOD_LOCK_FILE="$MONGOD_DB_PATH/mongod.lock" +MONGOD_LOCK_FILE="mongod.lock" MONGOD_STORAGE_ENGINE="mmapv1" MONGOD_EXTRA_ARGS="" @@ -53,7 +53,7 @@ init_start_repair() { --repair \ 2>&1 | logger - if [ -s $MONGOD_LOCK_FILE ]; then + if [ -s $MONGOD_DB_PATH/$MONGOD_LOCK_FILE ]; then echo "FAIL" echo -n "Wiping database path: " rm -rf $MONGOD_DB_PATH/* @@ -77,7 +77,7 @@ init_stop() { init_stop_wait() { echo -n "Waiting for daemon to exit: " for i in $(seq 10) "failed"; do - [ -s $MONGOD_LOCK_FILE ] || break + [ -s $MONGOD_DB_PATH/$MONGOD_LOCK_FILE ] || break echo -n "." sleep 1 done @@ -91,15 +91,15 @@ init_stop_wait() { case "$1" in start) - [ -s $MONGOD_LOCK_FILE ] && ! init_is_running && init_start_repair + [ -s $MONGOD_DB_PATH/$MONGOD_LOCK_FILE ] && ! init_is_running && init_start_repair init_start ;; stop) - [ -s $MONGOD_LOCK_FILE ] && init_stop + [ -s $MONGOD_DB_PATH/$MONGOD_LOCK_FILE ] && init_stop ;; restart) init_is_running && init_stop && init_stop_wait - [ -s $MONGOD_LOCK_FILE ] && init_start_repair + [ -s $MONGOD_DB_PATH/$MONGOD_LOCK_FILE ] && init_start_repair init_start ;; *) From 7f75b87ba8f8aba7f0e3d98621b2aceeb4687a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= Date: Thu, 3 Dec 2015 21:18:44 +0100 Subject: [PATCH 5/5] mongodb: patch out startup logging to db Since the startup logging in mongodb might fail due to the unique id being composed of system host and milliseconds since epoch (which might always be reset due to missing rtc), the logging is patched out. --- ...ip-logging-to-startup_log-at-startup.patch | 88 +++++++++++++++++++ recipes/mongodb/mongodb.inc | 1 + 2 files changed, 89 insertions(+) create mode 100644 recipes/mongodb/files/0001-skip-logging-to-startup_log-at-startup.patch diff --git a/recipes/mongodb/files/0001-skip-logging-to-startup_log-at-startup.patch b/recipes/mongodb/files/0001-skip-logging-to-startup_log-at-startup.patch new file mode 100644 index 000000000..d71207ee3 --- /dev/null +++ b/recipes/mongodb/files/0001-skip-logging-to-startup_log-at-startup.patch @@ -0,0 +1,88 @@ +From 03ebd530208718687f81f3fc8c943d25ba8c5ee2 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Hundeb=C3=B8ll?= +Date: Thu, 3 Dec 2015 08:56:24 +0100 +Subject: [PATCH] skip logging to startup_log at startup + +When running from embedded devices without RTC, the startup logging +sometimes fails due to a time collision in startup_log. This is caused +by creating the index key from the system hostname appended with the +milliseconds since epoch, which in the embedded case is always approx. +the same. + +Fix this by removing the logging at startup log. + +startup_log: +https://docs.mongodb.org/manual/reference/local-database/#local.startup_log + +upstream bug report: +https://jira.mongodb.org/browse/SERVER-21751 +--- + src/mongo/db/db.cpp | 45 --------------------------------------------- + 1 file changed, 45 deletions(-) + +diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp +index 2b4ab0e..03735c1 100644 +--- a/src/mongo/db/db.cpp ++++ b/src/mongo/db/db.cpp +@@ -198,49 +198,6 @@ public: + } + }; + +-static void logStartup() { +- BSONObjBuilder toLog; +- stringstream id; +- id << getHostNameCached() << "-" << jsTime().asInt64(); +- toLog.append("_id", id.str()); +- toLog.append("hostname", getHostNameCached()); +- +- toLog.appendTimeT("startTime", time(0)); +- toLog.append("startTimeLocal", dateToCtimeString(Date_t::now())); +- +- toLog.append("cmdLine", serverGlobalParams.parsedOpts); +- toLog.append("pid", ProcessId::getCurrent().asLongLong()); +- +- +- BSONObjBuilder buildinfo(toLog.subobjStart("buildinfo")); +- appendBuildInfo(buildinfo); +- appendStorageEngineList(&buildinfo); +- buildinfo.doneFast(); +- +- BSONObj o = toLog.obj(); +- +- OperationContextImpl txn; +- +- ScopedTransaction transaction(&txn, MODE_X); +- Lock::GlobalWrite lk(txn.lockState()); +- AutoGetOrCreateDb autoDb(&txn, "local", mongo::MODE_X); +- Database* db = autoDb.getDb(); +- const std::string ns = "local.startup_log"; +- Collection* collection = db->getCollection(ns); +- WriteUnitOfWork wunit(&txn); +- if (!collection) { +- BSONObj options = BSON("capped" << true << "size" << 10 * 1024 * 1024); +- bool shouldReplicateWrites = txn.writesAreReplicated(); +- txn.setReplicatedWrites(false); +- ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, &txn, shouldReplicateWrites); +- uassertStatusOK(userCreateNS(&txn, db, ns, options)); +- collection = db->getCollection(ns); +- } +- invariant(collection); +- uassertStatusOK(collection->insertDocument(&txn, o, false).getStatus()); +- wunit.commit(); +-} +- + static void checkForIdIndexes(OperationContext* txn, Database* db) { + if (db->name() == "local") { + // we do not need an _id index on anything in the local database +@@ -581,8 +538,6 @@ static void _initAndListen(int listenPort) { + + PeriodicTask::startRunningPeriodicTasks(); + +- logStartup(); +- + // MessageServer::run will return when exit code closes its socket + server->run(); + } +-- +2.6.2 + diff --git a/recipes/mongodb/mongodb.inc b/recipes/mongodb/mongodb.inc index aab38bd1f..a1ccf3f40 100644 --- a/recipes/mongodb/mongodb.inc +++ b/recipes/mongodb/mongodb.inc @@ -40,6 +40,7 @@ SRC_URI = " \ file://0001-remove-char-arguments-to-boost-mutex-constructors.patch \ file://0001-include-operation-context-to-allow-dereferencing.patch \ file://0001-remove-debug-flag-from-build.patch \ + file://0001-skip-logging-to-startup_log-at-startup.patch \ " S = "${SRCDIR}/mongodb-src-r${PV}/"