Added stop_sessions API call
This commit is contained in:
parent
69bb08a10a
commit
d504324b8f
3 changed files with 59 additions and 1 deletions
|
@ -571,7 +571,7 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
|||
}
|
||||
|
||||
if (Request.isMember("invalidate_sessions")){
|
||||
if (Request["totals"].isArray()){
|
||||
if (Request["invalidate_sessions"].isArray()){
|
||||
for (unsigned int i = 0; i < Request["invalidate_sessions"].size(); ++i){
|
||||
Controller::sessions_invalidate(Request["invalidate_sessions"][i].asStringRef());
|
||||
}
|
||||
|
@ -580,6 +580,16 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
|||
}
|
||||
}
|
||||
|
||||
if (Request.isMember("stop_sessions")){
|
||||
if (Request["stop_sessions"].isArray() || Request["stop_sessions"].isObject()){
|
||||
jsonForEach(Request["stop_sessions"], it){
|
||||
Controller::sessions_shutdown(it);
|
||||
}
|
||||
}else{
|
||||
Controller::sessions_shutdown(Request["stop_sessions"].asStringRef());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Request.isMember("push_start")){
|
||||
std::string stream;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <mist/config.h>
|
||||
#include <mist/shared_memory.h>
|
||||
#include <mist/dtsc.h>
|
||||
#include <mist/procs.h>
|
||||
#include "controller_statistics.h"
|
||||
#include "controller_limits.h"
|
||||
#include "controller_push.h"
|
||||
|
@ -160,6 +161,51 @@ void Controller::sessions_invalidate(const std::string & streamname){
|
|||
INFO_MSG("Invalidated %u connections in %u sessions for stream %s", invalidated, sessCount, streamname.c_str());
|
||||
}
|
||||
|
||||
|
||||
///Shuts down all current sessions for the given streamname
|
||||
void Controller::sessions_shutdown(JSON::Iter & i){
|
||||
if (i->isArray() || i->isObject()){
|
||||
jsonForEach(*i, it){
|
||||
sessions_shutdown(it);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (i->isString()){
|
||||
sessions_shutdown(i.key(), i->asStringRef());
|
||||
return;
|
||||
}
|
||||
//not handled, ignore
|
||||
}
|
||||
|
||||
///Shuts down all current sessions for the given streamname
|
||||
void Controller::sessions_shutdown(const std::string & streamname, const std::string & protocol){
|
||||
if (!statPointer){
|
||||
FAIL_MSG("In controller shutdown procedure - cannot shutdown sessions.");
|
||||
return;
|
||||
}
|
||||
unsigned int murdered = 0;
|
||||
unsigned int sessCount = 0;
|
||||
tthread::lock_guard<tthread::mutex> guard(statsMutex);
|
||||
for (std::map<sessIndex, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){
|
||||
if ((!streamname.size() || it->first.streamName == streamname) && (!protocol.size() || it->first.connector == protocol) && it->second.curConns.size()){
|
||||
sessCount++;
|
||||
for (std::map<unsigned long, statStorage>::iterator jt = it->second.curConns.begin(); jt != it->second.curConns.end(); ++jt){
|
||||
char * data = statPointer->getIndex(jt->first);
|
||||
if (data){
|
||||
IPC::statExchange tmpEx(data);
|
||||
uint32_t pid = tmpEx.getPID();
|
||||
if (pid > 1){
|
||||
Util::Procs::Stop(pid);
|
||||
INFO_MSG("Killing PID %lu", pid);
|
||||
murdered++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
INFO_MSG("Shut down %u connections in %u sessions for stream %s/%s", murdered, sessCount, streamname.c_str(), protocol.c_str());
|
||||
}
|
||||
|
||||
/// This function runs as a thread and roughly once per second retrieves
|
||||
/// statistics from all connected clients, as well as wipes
|
||||
/// old statistics that have disconnected over 10 minutes ago.
|
||||
|
|
|
@ -117,6 +117,8 @@ namespace Controller {
|
|||
void fillTotals(JSON::Value & req, JSON::Value & rep);
|
||||
void SharedMemStats(void * config);
|
||||
void sessions_invalidate(const std::string & streamname);
|
||||
void sessions_shutdown(JSON::Iter & i);
|
||||
void sessions_shutdown(const std::string & streamname, const std::string & protocol = "");
|
||||
bool hasViewers(std::string streamName);
|
||||
|
||||
#define PROMETHEUS_TEXT 0
|
||||
|
|
Loading…
Add table
Reference in a new issue