Added ability for controller to restart without restarting connectors simultaneously
This commit is contained in:
parent
707c055ba5
commit
0ece6d8f26
3 changed files with 81 additions and 1 deletions
|
@ -94,6 +94,7 @@ void createAccount (std::string account){
|
|||
/// Will check outputs, inputs and converters every five seconds
|
||||
void statusMonitor(void * np){
|
||||
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
Controller::loadActiveConnectors();
|
||||
while (Controller::conf.is_active){
|
||||
//this scope prevents the configMutex from being locked constantly
|
||||
{
|
||||
|
@ -116,7 +117,12 @@ void statusMonitor(void * np){
|
|||
Controller::configChanged = false;
|
||||
}
|
||||
}
|
||||
Util::wait(5000);//wait at least 5 seconds
|
||||
Util::sleep(5000);//wait at least 5 seconds
|
||||
}
|
||||
if (Controller::restarting){
|
||||
Controller::prepareActiveConnectorsForReload();
|
||||
}else{
|
||||
Controller::prepareActiveConnectorsForShutdown();
|
||||
}
|
||||
configLock.unlink();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <mist/defines.h>
|
||||
#include "controller_storage.h"
|
||||
#include "controller_connectors.h"
|
||||
#include <mist/shared_memory.h>
|
||||
#include <mist/util.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
@ -20,6 +22,61 @@ namespace Controller {
|
|||
|
||||
static std::map<std::string, pid_t> currentConnectors; ///<The currently running connectors.
|
||||
|
||||
/// Updates the shared memory page with active connectors
|
||||
void saveActiveConnectors(){
|
||||
IPC::sharedPage f("MstCnns", 4096, true, false);
|
||||
if (!f.mapped){
|
||||
FAIL_MSG("Could not store connector data!");
|
||||
return;
|
||||
}
|
||||
memset(f.mapped, 0, 32);
|
||||
Util::RelAccX A(f.mapped, false);
|
||||
A.addField("cmd", RAX_128STRING);
|
||||
A.addField("pid", RAX_64UINT);
|
||||
A.setReady();
|
||||
uint32_t count = 0;
|
||||
std::map<std::string, pid_t>::iterator it;
|
||||
for (it = currentConnectors.begin(); it != currentConnectors.end(); ++it){
|
||||
A.setString("cmd", it->first, count);
|
||||
A.setInt("pid", it->second, count);
|
||||
++count;
|
||||
}
|
||||
A.setRCount(count);
|
||||
f.master = false;//Keep the shm page around, don't kill it
|
||||
}
|
||||
|
||||
/// Reads active connectors from the shared memory pages
|
||||
void loadActiveConnectors(){
|
||||
IPC::sharedPage f("MstCnns", 4096, false, false);
|
||||
const Util::RelAccX A(f.mapped, false);
|
||||
if (A.isReady()){
|
||||
for (uint32_t i = 0; i < A.getRCount(); ++i){
|
||||
char * p = A.getPointer("cmd", i);
|
||||
if (p != 0 && p[0] != 0){
|
||||
currentConnectors[p] = A.getInt("pid", i);
|
||||
Util::Procs::remember(A.getInt("pid", i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes the shared memory page with connector information
|
||||
/// in preparation of shutdown.
|
||||
void prepareActiveConnectorsForShutdown(){
|
||||
IPC::sharedPage f("MstCnns", 4096, true, false);
|
||||
}
|
||||
|
||||
/// Forgets all active connectors, preventing them from being killed,
|
||||
/// in preparation of reload.
|
||||
void prepareActiveConnectorsForReload(){
|
||||
saveActiveConnectors();
|
||||
std::map<std::string, pid_t>::iterator it;
|
||||
for (it = currentConnectors.begin(); it != currentConnectors.end(); ++it){
|
||||
Util::Procs::forget(it->second);
|
||||
}
|
||||
currentConnectors.clear();
|
||||
}
|
||||
|
||||
///\brief Checks if the binary mentioned in the protocol argument is currently active, if so, restarts it.
|
||||
///\param protocol The protocol to check.
|
||||
void UpdateProtocol(std::string protocol){
|
||||
|
@ -171,6 +228,7 @@ namespace Controller {
|
|||
}
|
||||
runningConns.erase(runningConns.begin());
|
||||
}
|
||||
if (action){saveActiveConnectors();}
|
||||
return action;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,4 +8,20 @@ namespace Controller {
|
|||
/// Checks current protocol configuration, updates state of enabled connectors if neccesary.
|
||||
bool CheckProtocols(JSON::Value & p, const JSON::Value & capabilities);
|
||||
|
||||
/// Updates the shared memory page with active connectors
|
||||
void saveActiveConnectors();
|
||||
|
||||
/// Reads active connectors from the shared memory pages
|
||||
void loadActiveConnectors();
|
||||
|
||||
|
||||
/// Deletes the shared memory page with connector information
|
||||
/// in preparation of shutdown.
|
||||
void prepareActiveConnectorsForShutdown();
|
||||
|
||||
/// Forgets all active connectors, preventing them from being killed,
|
||||
/// in preparation of reload.
|
||||
void prepareActiveConnectorsForReload();
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue