summaryrefslogtreecommitdiff
path: root/s/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 's/server.cpp')
-rw-r--r--s/server.cpp132
1 files changed, 86 insertions, 46 deletions
diff --git a/s/server.cpp b/s/server.cpp
index 4868caf..3644376 100644
--- a/s/server.cpp
+++ b/s/server.cpp
@@ -30,10 +30,10 @@
namespace mongo {
Database *database = 0;
+ string mongosCommand;
string ourHostname;
OID serverID;
bool dbexitCalled = false;
- CmdLine cmdLine;
bool inShutdown(){
return dbexitCalled;
@@ -47,12 +47,12 @@ namespace mongo {
assert( 0 );
return false;
}
-
+
void usage( char * argv[] ){
out() << argv[0] << " usage:\n\n";
- out() << " -v+ verbose\n";
+ out() << " -v+ verbose 1: general 2: more 3: per request 4: more\n";
out() << " --port <portno>\n";
- out() << " --configdb <configdbname> [<configdbname>...]\n";
+ out() << " --configdb <configdbname>,[<configdbname>,<configdbname>]\n";
out() << endl;
}
@@ -88,10 +88,20 @@ namespace mongo {
}
}
};
+
+ void sighandler(int sig){
+ dbexit(EXIT_CLEAN, (string("recieved signal ") + BSONObjBuilder::numStr(sig)).c_str());
+ }
+ void setupSignals(){
+ // needed for cmdLine, btu we do it in init()
+ }
+
void init(){
serverID.init();
setupSIGTRAPforGDB();
+ signal(SIGTERM, sighandler);
+ signal(SIGINT, sighandler);
}
void start() {
@@ -108,55 +118,83 @@ namespace mongo {
return 0;
}
+ void printShardingVersionInfo(){
+ log() << mongosCommand << " v0.3 (alpha 3) starting (--help for usage)" << endl;
+ printGitVersion();
+ printSysInfo();
+ }
+
} // namespace mongo
using namespace mongo;
+#include <boost/program_options.hpp>
+
+namespace po = boost::program_options;
+
int main(int argc, char* argv[], char *envp[] ) {
+ static StaticObserver staticObserver;
+ mongosCommand = argv[0];
+
+ po::options_description options("Sharding options");
+ po::options_description hidden("Hidden options");
+ po::positional_options_description positional;
- bool justTests = false;
- vector<string> configdbs;
+ CmdLine::addGlobalOptions( options , hidden );
- for (int i = 1; i < argc; i++) {
- if ( argv[i] == 0 ) continue;
- string s = argv[i];
- if ( s == "--port" ) {
- cmdLine.port = atoi(argv[++i]);
- }
- else if ( s == "--configdb" ) {
-
- while ( ++i < argc )
- configdbs.push_back(argv[i]);
-
- if ( configdbs.size() == 0 ) {
- out() << "error: no args for --configdb\n";
- return 4;
- }
-
- if ( configdbs.size() > 2 ) {
- out() << "error: --configdb does not support more than 2 parameters yet\n";
- return 5;
- }
- }
- else if ( s.find( "-v" ) == 0 ){
- logLevel = s.size() - 1;
- }
- else if ( s == "--test" ) {
- justTests = true;
- logLevel = 5;
- }
- else {
- usage( argv );
- return 3;
- }
- }
+ options.add_options()
+ ( "configdb" , po::value<string>() , "1 or 3 comma separated config servers" )
+ ( "test" , "just run unit tests" )
+ ;
+
+
+ // parse options
+ po::variables_map params;
+ if ( ! CmdLine::store( argc , argv , options , hidden , positional , params ) )
+ return 0;
- if ( justTests ){
+ if ( params.count( "help" ) ){
+ cout << options << endl;
+ return 0;
+ }
+
+ if ( params.count( "version" ) ){
+ printShardingVersionInfo();
+ return 0;
+ }
+
+
+ if ( params.count( "test" ) ){
+ logLevel = 5;
UnitTest::runTests();
cout << "tests passed" << endl;
return 0;
}
+ if ( ! params.count( "configdb" ) ){
+ out() << "error: no args for --configdb" << endl;
+ return 4;
+ }
+
+ vector<string> configdbs;
+ {
+ string s = params["configdb"].as<string>();
+ while ( true ){
+ size_t idx = s.find( ',' );
+ if ( idx == string::npos ){
+ configdbs.push_back( s );
+ break;
+ }
+ configdbs.push_back( s.substr( 0 , idx ) );
+ s = s.substr( idx + 1 );
+ }
+ }
+
+ if ( configdbs.size() != 1 && configdbs.size() != 3 ){
+ out() << "need either 1 or 3 configdbs" << endl;
+ return 5;
+ }
+
pool.addHook( &shardingConnectionHook );
if ( argc <= 1 ) {
@@ -170,24 +208,26 @@ int main(int argc, char* argv[], char *envp[] ) {
usage( argv );
return 1;
}
-
- log() << argv[0] << " v0.3- (alpha 3t) starting (--help for usage)" << endl;
- printGitVersion();
- printSysInfo();
+
+ printShardingVersionInfo();
if ( ! configServer.init( configdbs ) ){
cout << "couldn't connectd to config db" << endl;
return 7;
}
- assert( configServer.ok() );
+ if ( ! configServer.ok() ){
+ cout << "configServer startup check failed" << endl;
+ return 8;
+ }
int configError = configServer.checkConfigVersion();
if ( configError ){
cout << "config server error: " << configError << endl;
return configError;
}
-
+ configServer.reloadSettings();
+
init();
start();
dbexit( EXIT_CLEAN );