diff options
author | Amalia Hawkins <amalia.hawkins@10gen.com> | 2014-09-10 15:18:25 -0400 |
---|---|---|
committer | Amalia Hawkins <amalia.hawkins@10gen.com> | 2014-09-11 17:28:26 -0400 |
commit | a47da32cea1c07e2e1c23fa16499017fc665a38d (patch) | |
tree | 6f155bbee36eb92a15e870636e0bf5d71ff18c75 | |
parent | c082c215f671a7b8475d8407ed8f3c37e176e7ad (diff) | |
download | mongo-a47da32cea1c07e2e1c23fa16499017fc665a38d.tar.gz |
SERVER-12637: log a startup warning when mongod/mongos is run as root.
-rw-r--r-- | src/mongo/SConscript | 3 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/startup_warnings_common.cpp | 87 | ||||
-rw-r--r-- | src/mongo/db/startup_warnings_common.h | 33 | ||||
-rw-r--r-- | src/mongo/db/startup_warnings_mongod.cpp (renamed from src/mongo/db/startup_warnings.cpp) | 37 | ||||
-rw-r--r-- | src/mongo/db/startup_warnings_mongod.h (renamed from src/mongo/db/startup_warnings.h) | 7 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 4 |
7 files changed, 137 insertions, 38 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 75ae9a234f6..b483b18c83a 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -490,6 +490,7 @@ coredbEnv.Library("coredb", [ "db/pipeline/value.cpp", "db/projection.cpp", "db/stats/timer_stats.cpp", + "db/startup_warnings_common.cpp", "s/shardconnection.cpp", ] + tcmallocServerStatus @@ -648,7 +649,7 @@ serverOnlyFiles = [ "db/curop.cpp", "db/dbcommands.cpp", "db/dbcommands_admin.cpp", "db/write_concern.cpp", - "db/startup_warnings.cpp", + "db/startup_warnings_mongod.cpp", "db/storage_options.cpp", "db/storage/storage_init.cpp", "db/ops/update_lifecycle_impl.cpp", diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index e5b013ffc68..ca84004d9d9 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -78,7 +78,7 @@ #include "mongo/db/repl/rs.h" #include "mongo/db/restapi.h" #include "mongo/db/server_parameters.h" -#include "mongo/db/startup_warnings.h" +#include "mongo/db/startup_warnings_mongod.h" #include "mongo/db/stats/counters.h" #include "mongo/db/stats/snapshots.h" #include "mongo/db/storage/storage_engine.h" @@ -545,7 +545,7 @@ namespace mongo { l << ( is32bit ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << endl; } DEV log(LogComponent::kDefault) << "_DEBUG build (which is slower)" << endl; - logStartupWarnings(); + logMongodStartupWarnings(); #if defined(_WIN32) printTargetMinOS(); #endif diff --git a/src/mongo/db/startup_warnings_common.cpp b/src/mongo/db/startup_warnings_common.cpp new file mode 100644 index 00000000000..24087ba7b2c --- /dev/null +++ b/src/mongo/db/startup_warnings_common.cpp @@ -0,0 +1,87 @@ +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects +* for all of the code used other than as permitted herein. If you modify +* file(s) with this exception, you may extend this exception to your +* version of the file(s), but you are not obligated to do so. If you do not +* wish to do so, delete this exception statement from your version. If you +* delete this exception statement from all source files in the program, +* then also delete it in the license file. +*/ + +#include "mongo/platform/basic.h" + +#include "mongo/db/startup_warnings_common.h" + +#include <boost/filesystem/operations.hpp> +#include <fstream> + +#include "mongo/util/log.h" +#include "mongo/util/processinfo.h" +#include "mongo/util/version.h" + +namespace mongo { + + // + // system warnings + // + void logCommonStartupWarnings() { + // each message adds a leading and a trailing newline + + bool warned = false; + { + const char * foo = strchr(versionString , '.') + 1; + int bar = atoi(foo); + if ((2 * (bar / 2)) != bar) { + log() << startupWarningsLog; + log() << "** NOTE: This is a development version (" << versionString + << ") of MongoDB." << startupWarningsLog; + log() << "** Not recommended for production." << startupWarningsLog; + warned = true; + } + } + +#if defined(_WIN32) && !defined(_WIN64) + // Warn user that they are running a 32-bit app on 64-bit Windows + BOOL wow64Process; + BOOL retWow64 = IsWow64Process(GetCurrentProcess(), &wow64Process); + if (retWow64 && wow64Process) { + log() << "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating" + << startupWarningsLog; + log() << "** system. Switch to a 64-bit build of MongoDB to" + << startupWarningsLog; + log() << "** support larger databases." << startupWarningsLog; + warned = true; + } +#endif + +#if !defined(_WIN32) + if (getuid() == 0) { + log() << "** WARNING: You are running this process as the root user, " + << "which is not recommended." << startupWarningsLog; + warned = true; + } +#endif + + if (warned) { + log() << startupWarningsLog; + } + } +} // namespace mongo diff --git a/src/mongo/db/startup_warnings_common.h b/src/mongo/db/startup_warnings_common.h new file mode 100644 index 00000000000..9cccfd35592 --- /dev/null +++ b/src/mongo/db/startup_warnings_common.h @@ -0,0 +1,33 @@ +/** +* Copyright (C) 2014 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* As a special exception, the copyright holders give permission to link the +* code of portions of this program with the OpenSSL library under certain +* conditions as described in each individual source file and distribute +* linked combinations including the program with the OpenSSL library. You +* must comply with the GNU Affero General Public License in all respects +* for all of the code used other than as permitted herein. If you modify +* file(s) with this exception, you may extend this exception to your +* version of the file(s), but you are not obligated to do so. If you do not +* wish to do so, delete this exception statement from your version. If you +* delete this exception statement from all source files in the program, +* then also delete it in the license file. +*/ + +namespace mongo { + // Checks various startup conditions and logs any necessary warnings that + // are common to both mongod and mongos processes. + void logCommonStartupWarnings(); +} // namespace mongo diff --git a/src/mongo/db/startup_warnings.cpp b/src/mongo/db/startup_warnings_mongod.cpp index 15570c973c6..0e88708737f 100644 --- a/src/mongo/db/startup_warnings.cpp +++ b/src/mongo/db/startup_warnings_mongod.cpp @@ -1,5 +1,5 @@ /** -* Copyright (C) 2013 10gen Inc. +* Copyright (C) 2014 MongoDB Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, @@ -28,11 +28,12 @@ #include "mongo/platform/basic.h" -#include "mongo/db/startup_warnings.h" +#include "mongo/db/startup_warnings_mongod.h" #include <boost/filesystem/operations.hpp> #include <fstream> +#include "mongo/db/startup_warnings_common.h" #include "mongo/db/storage_options.h" #include "mongo/util/log.h" #include "mongo/util/processinfo.h" @@ -42,24 +43,10 @@ namespace mongo { extern bool useExperimentalDocLocking; - // - // system warnings - // - void logStartupWarnings() { - // each message adds a leading and a trailing newline + void logMongodStartupWarnings() { + logCommonStartupWarnings(); bool warned = false; - { - const char * foo = strchr(versionString , '.') + 1; - int bar = atoi(foo); - if ((2 * (bar / 2)) != bar) { - log() << startupWarningsLog; - log() << "** NOTE: This is a development version (" << versionString - << ") of MongoDB." << startupWarningsLog; - log() << "** Not recommended for production." << startupWarningsLog; - warned = true; - } - } if (sizeof(int*) == 4) { log() << startupWarningsLog; @@ -86,20 +73,6 @@ namespace mongo { warned = true; } -#if defined(_WIN32) && !defined(_WIN64) - // Warn user that they are running a 32-bit app on 64-bit Windows - BOOL wow64Process; - BOOL retWow64 = IsWow64Process(GetCurrentProcess(), &wow64Process); - if (retWow64 && wow64Process) { - log() << "** NOTE: This is a 32-bit MongoDB binary running on a 64-bit operating" - << startupWarningsLog; - log() << "** system. Switch to a 64-bit build of MongoDB to" - << startupWarningsLog; - log() << "** support larger databases." << startupWarningsLog; - warned = true; - } -#endif - if (!ProcessInfo::blockCheckSupported()) { log() << startupWarningsLog; log() << "** NOTE: your operating system version does not support the method that " diff --git a/src/mongo/db/startup_warnings.h b/src/mongo/db/startup_warnings_mongod.h index 35a33210159..fc49df950f0 100644 --- a/src/mongo/db/startup_warnings.h +++ b/src/mongo/db/startup_warnings_mongod.h @@ -1,5 +1,5 @@ /** -* Copyright (C) 2013 10gen Inc. +* Copyright (C) 2014 MongoDB Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, @@ -27,6 +27,7 @@ */ namespace mongo { - // Checks various startup conditions and logs any necessary warnings - void logStartupWarnings(); + // Checks various startup conditions and logs any necessary warnings that + // are specific to the mongod process. + void logMongodStartupWarnings(); } // namespace mongo diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 22ae0028e45..459af3f2bab 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -55,6 +55,7 @@ #include "mongo/db/lasterror.h" #include "mongo/db/log_process_details.h" #include "mongo/db/operation_context_noop.h" +#include "mongo/db/startup_warnings_common.h" #include "mongo/platform/process_id.h" #include "mongo/s/balance.h" #include "mongo/s/chunk.h" @@ -432,6 +433,9 @@ int mongoSMain(int argc, char* argv[], char** envp) { startupConfigActions(std::vector<std::string>(argv, argv + argc)); cmdline_utils::censorArgvArray(argc, argv); + + mongo::logCommonStartupWarnings(); + try { int exitCode = _main(); return exitCode; |