SERVER-705 return return code when stopping mongod program

This commit is contained in:
Aaron
2010-03-08 12:54:39 -08:00
parent 97515db5b8
commit 063f651c6b
2 changed files with 11 additions and 7 deletions

View File

@@ -321,12 +321,13 @@ namespace mongo {
return undefined_;
}
void killDb( int port, pid_t _pid, int signal ) {
int killDb( int port, pid_t _pid, int signal ) {
pid_t pid;
int exitCode = 0;
if ( port > 0 ) {
if( dbs.count( port ) != 1 ) {
cout << "No db started on port: " << port << endl;
return;
return 0;
}
pid = dbs[ port ].first;
} else {
@@ -346,6 +347,7 @@ namespace mongo {
}
int temp;
int ret = waitpid( pid, &temp, WNOHANG );
exitCode = WEXITSTATUS( temp );
if ( ret == pid )
break;
sleepms( 1000 );
@@ -368,6 +370,8 @@ namespace mongo {
if ( i > 4 || signal == SIGKILL ) {
sleepms( 4000 ); // allow operating system to reclaim resources
}
return exitCode;
}
int getSignal( const BSONObj &a ) {
@@ -386,18 +390,18 @@ namespace mongo {
assert( a.nFields() == 1 || a.nFields() == 2 );
assert( a.firstElement().isNumber() );
int port = int( a.firstElement().number() );
killDb( port, 0, getSignal( a ) );
int code = killDb( port, 0, getSignal( a ) );
cout << "shell: stopped mongo program on port " << port << endl;
return undefined_;
return BSON( "" << code );
}
BSONObj StopMongoProgramByPid( const BSONObj &a ) {
assert( a.nFields() == 1 || a.nFields() == 2 );
assert( a.firstElement().isNumber() );
int pid = int( a.firstElement().number() );
killDb( 0, pid, getSignal( a ) );
int code = killDb( 0, pid, getSignal( a ) );
cout << "shell: stopped mongo program on pid " << pid << endl;
return undefined_;
return BSON( "" << code );
}
void KillMongoProgramInstances() {