2008-11-29 20:01:58 -05:00
|
|
|
// dbwebserver.cpp
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2008 10gen 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "../util/miniwebserver.h"
|
|
|
|
|
#include "db.h"
|
2008-11-30 21:00:54 -05:00
|
|
|
#include "repl.h"
|
|
|
|
|
#include "replset.h"
|
2008-11-29 20:01:58 -05:00
|
|
|
|
|
|
|
|
extern int port;
|
2008-11-30 21:00:54 -05:00
|
|
|
extern string replInfo;
|
2008-11-29 20:01:58 -05:00
|
|
|
|
2008-12-02 14:24:45 -05:00
|
|
|
time_t started = time(0);
|
|
|
|
|
|
2008-11-29 20:01:58 -05:00
|
|
|
class DbWebServer : public MiniWebServer {
|
|
|
|
|
public:
|
2008-11-30 21:00:54 -05:00
|
|
|
void doLockedStuff(stringstream& ss) {
|
|
|
|
|
dblock lk;
|
2008-12-02 14:24:45 -05:00
|
|
|
ss << "# databases: " << databases.size() << '\n';
|
|
|
|
|
if( database ) {
|
|
|
|
|
ss << "curclient: " << database->name;
|
2008-11-30 21:00:54 -05:00
|
|
|
ss << '\n';
|
|
|
|
|
}
|
2008-12-01 14:55:36 -05:00
|
|
|
ss << "\n<b>replication</b>\n";
|
2008-11-30 21:00:54 -05:00
|
|
|
ss << "master: " << master << '\n';
|
|
|
|
|
ss << "slave: " << slave << '\n';
|
|
|
|
|
if( replPair ) {
|
|
|
|
|
ss << "replpair:\n";
|
|
|
|
|
ss << replPair->getInfo();
|
|
|
|
|
}
|
|
|
|
|
ss << replInfo << '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void doUnlockedStuff(stringstream& ss) {
|
|
|
|
|
ss << "port: " << port << '\n';
|
|
|
|
|
ss << "dblocked: " << dbLocked << " (initial)\n";
|
2008-12-02 14:24:45 -05:00
|
|
|
ss << "uptime: " << time(0)-started << " seconds\n";
|
2008-12-01 14:55:36 -05:00
|
|
|
if( allDead )
|
|
|
|
|
ss << "<b>replication allDead=" << allDead << "</b>\n";
|
2008-11-30 21:00:54 -05:00
|
|
|
}
|
2008-11-29 20:01:58 -05:00
|
|
|
|
|
|
|
|
virtual void doRequest(
|
|
|
|
|
const char *rq, // the full request
|
|
|
|
|
string url,
|
|
|
|
|
// set these and return them:
|
|
|
|
|
string& responseMsg,
|
|
|
|
|
int& responseCode,
|
|
|
|
|
vector<string>& headers // if completely empty, content-type: text/html will be added
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
responseCode = 200;
|
|
|
|
|
stringstream ss;
|
2008-12-01 14:55:36 -05:00
|
|
|
ss << "<html><head><title>db</title></head><body><h2>db</h2><p>\n<pre>";
|
2008-11-29 20:01:58 -05:00
|
|
|
|
2008-11-30 21:00:54 -05:00
|
|
|
doUnlockedStuff(ss);
|
2008-11-29 20:01:58 -05:00
|
|
|
|
|
|
|
|
int n = 2000;
|
|
|
|
|
while( 1 ) {
|
|
|
|
|
if( !dbLocked ) {
|
2008-11-30 21:00:54 -05:00
|
|
|
ss << '\n';
|
2008-11-29 20:01:58 -05:00
|
|
|
doLockedStuff(ss);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
sleepmillis(1);
|
|
|
|
|
if( --n < 0 ) {
|
|
|
|
|
ss << "\ntimed out getting dblock\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ss << "</pre></body></html>";
|
|
|
|
|
responseMsg = ss.str();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void webServerThread() {
|
|
|
|
|
DbWebServer mini;
|
|
|
|
|
if( mini.init(port+1000) )
|
|
|
|
|
mini.run();
|
|
|
|
|
}
|