diff options
Diffstat (limited to 'src/mongo/s/server.cpp')
-rw-r--r-- | src/mongo/s/server.cpp | 177 |
1 files changed, 14 insertions, 163 deletions
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index fec01840b6b..c8b9c494902 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -57,8 +57,10 @@ #include "mongo/s/grid.h" #include "mongo/s/mongos_options.h" #include "mongo/s/request.h" +#include "mongo/s/version_mongos.h" #include "mongo/scripting/engine.h" #include "mongo/util/admin_access.h" +#include "mongo/util/cmdline_utils/censor_cmdline.h" #include "mongo/util/concurrency/task.h" #include "mongo/util/concurrency/thread_name.h" #include "mongo/util/exception_filter_win32.h" @@ -70,19 +72,15 @@ #include "mongo/util/ntservice.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" +#include "mongo/util/options_parser/options_parser.h" #include "mongo/util/processinfo.h" #include "mongo/util/ramlog.h" #include "mongo/util/signal_handlers.h" #include "mongo/util/stacktrace.h" -#include "mongo/util/startup_test.h" #include "mongo/util/stringutils.h" #include "mongo/util/text.h" #include "mongo/util/version.h" -namespace { - bool _isUpgradeSwitchSet = false; -} - namespace mongo { #if defined(_WIN32) @@ -94,14 +92,9 @@ namespace mongo { static void initService(); #endif - CmdLine cmdLine; - moe::Environment params; - moe::OptionSection options("Allowed options"); Database *database = 0; string mongosCommand; bool dbexitCalled = false; - static bool scriptingEnabled = true; - static vector<string> configdbs; bool inShutdown() { return dbexitCalled; @@ -269,27 +262,6 @@ namespace mongo { return 0; } - void printShardingVersionInfo( bool out ) { - if ( out ) { - cout << "MongoS version " << versionString << " starting: pid=" << - ProcessId::getCurrent() << " port=" << cmdLine.port << - ( sizeof(int*) == 4 ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << - " (--help for usage)" << endl; - DEV cout << "_DEBUG build" << endl; - cout << "git version: " << gitVersion() << endl; - cout << openSSLVersion("OpenSSL version: ") << endl; - cout << "build sys info: " << sysInfo() << endl; - } - else { - log() << "MongoS version " << versionString << " starting: pid=" << - ProcessId::getCurrent() << " port=" << cmdLine.port << - ( sizeof( int* ) == 4 ? " 32" : " 64" ) << "-bit host=" << getHostNameCached() << - " (--help for usage)" << endl; - DEV log() << "_DEBUG build" << endl; - logProcessDetails(); - } - } - } // namespace mongo using namespace mongo; @@ -312,7 +284,7 @@ static bool runMongosServer( bool doUpgrade ) { ReplicaSetMonitor::setConfigChangeHook( boost::bind( &ConfigServer::replicaSetChange , &configServer , _1 ) ); - if ( ! configServer.init( configdbs ) ) { + if (!configServer.init(mongosGlobalParams.configdbs)) { log() << "couldn't resolve config db address" << endl; return false; } @@ -350,10 +322,10 @@ static bool runMongosServer( bool doUpgrade ) { init(); #if !defined(_WIN32) - CmdLine::launchOk(); + mongo::signalForkSuccess(); #endif - if ( cmdLine.isHttpInterfaceEnabled ) + if (serverGlobalParams.isHttpInterfaceEnabled) boost::thread web( boost::bind(&webServerThread, new NoAdminAccess() /* takes ownership */) ); AuthorizationManager* authzManager = getGlobalAuthorizationManager(); @@ -366,8 +338,8 @@ static bool runMongosServer( bool doUpgrade ) { } MessageServer::Options opts; - opts.port = cmdLine.port; - opts.ipList = cmdLine.bind_ip; + opts.port = serverGlobalParams.port; + opts.ipList = serverGlobalParams.bind_ip; start(opts); // listen() will return when exit code closes its socket. @@ -375,128 +347,6 @@ static bool runMongosServer( bool doUpgrade ) { return true; } -static Status processCommandLineOptions(const std::vector<std::string>& argv) { - Status ret = addMongosOptions(&options); - if (!ret.isOK()) { - StringBuilder sb; - sb << "Error getting mongos options descriptions: " << ret.toString(); - return Status(ErrorCodes::InternalError, sb.str()); - } - - // parse options - ret = CmdLine::store(argv, options, params); - if (!ret.isOK()) { - std::cerr << "Error parsing command line: " << ret.toString() << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - - // The default value may vary depending on compile options, but for mongos - // we want durability to be disabled. - cmdLine.dur = false; - - if ( params.count( "help" ) ) { - std::cout << options.helpString() << std::endl; - ::_exit(EXIT_SUCCESS); - } - if ( params.count( "version" ) ) { - printShardingVersionInfo(true); - ::_exit(EXIT_SUCCESS); - } - - if ( params.count( "chunkSize" ) ) { - int csize = params["chunkSize"].as<int>(); - - // validate chunksize before proceeding - if ( csize == 0 ) { - std::cerr << "error: need a non-zero chunksize" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - - if ( !Chunk::setMaxChunkSizeSizeMB( csize ) ) { - std::cerr << "MaxChunkSize invalid" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - } - - if (params.count( "port" ) ) { - int port = params["port"].as<int>(); - if ( port <= 0 || port > 65535 ) { - out() << "error: port number must be between 1 and 65535" << endl; - ::_exit(EXIT_FAILURE); - } - } - - if ( params.count( "localThreshold" ) ) { - cmdLine.defaultLocalThresholdMillis = params["localThreshold"].as<int>(); - } - - if ( params.count( "ipv6" ) ) { - enableIPv6(); - } - - if ( params.count( "jsonp" ) ) { - cmdLine.jsonp = true; - } - - if ( params.count( "test" ) ) { - ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( - ::mongo::logger::LogSeverity::Debug(5)); - StartupTest::runTests(); - ::_exit(EXIT_SUCCESS); - } - - if (params.count("noscripting")) { - scriptingEnabled = false; - } - - if (params.count("httpinterface")) { - if (params.count("nohttpinterface")) { - std::cerr << "can't have both --httpinterface and --nohttpinterface" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - cmdLine.isHttpInterfaceEnabled = true; - } - - if (params.count("noAutoSplit")) { - warning() << "running with auto-splitting disabled" << endl; - Chunk::ShouldAutoSplit = false; - } - - if ( ! params.count( "configdb" ) ) { - std::cerr << "error: no args for --configdb" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - - splitStringDelim( params["configdb"].as<string>() , &configdbs , ',' ); - if ( configdbs.size() != 1 && configdbs.size() != 3 ) { - std::cerr << "need either 1 or 3 configdbs" << std::endl; - ::_exit(EXIT_BADOPTIONS); - } - - if( configdbs.size() == 1 ) { - warning() << "running with 1 config server should be done only for testing purposes and is not recommended for production" << endl; - } - - _isUpgradeSwitchSet = params.count("upgrade"); - - // dbpath currently must be linked in to mongos, but the directory should never be written to. - dbpath = ""; - - return Status::OK(); -} - -MONGO_INITIALIZER_GENERAL(ParseStartupConfiguration, - ("GlobalLogManager"), - ("default", "completedStartupConfig"))(InitializerContext* context) { - - Status ret = processCommandLineOptions(context->args()); - if (!ret.isOK()) { - return ret; - } - - return Status::OK(); -} - MONGO_INITIALIZER_GENERAL(ForkServerOrDie, ("completedStartupConfig"), ("default"))(InitializerContext* context) { @@ -513,7 +363,7 @@ static void startupConfigActions(const std::vector<std::string>& argv) { vector<string> disallowedOptions; disallowedOptions.push_back( "upgrade" ); ntservice::configureService(initService, - params, + serverParsedOptions, defaultServiceStrings, disallowedOptions, argv); @@ -526,12 +376,13 @@ static int _main() { return EXIT_FAILURE; // we either have a setting where all processes are in localhost or none are - for ( vector<string>::const_iterator it = configdbs.begin() ; it != configdbs.end() ; ++it ) { + for (std::vector<std::string>::const_iterator it = mongosGlobalParams.configdbs.begin(); + it != mongosGlobalParams.configdbs.end(); ++it) { try { HostAndPort configAddr( *it ); // will throw if address format is invalid - if ( it == configdbs.begin() ) { + if (it == mongosGlobalParams.configdbs.begin()) { grid.setAllowLocalHost( configAddr.isLocalHost() ); } @@ -555,7 +406,7 @@ static int _main() { } #endif - return !runMongosServer(_isUpgradeSwitchSet); + return !runMongosServer(mongosGlobalParams.upgrade); } #if defined(_WIN32) @@ -597,7 +448,7 @@ int mongoSMain(int argc, char* argv[], char** envp) { mongo::runGlobalInitializersOrDie(argc, argv, envp); startupConfigActions(std::vector<std::string>(argv, argv + argc)); - CmdLine::censor(argc, argv); + cmdline_utils::censorArgvArray(argc, argv); try { int exitCode = _main(); return exitCode; |