Generalized Util::Config::is_restarting for rolling restarts, added rolling restart support to listening socket outputs
This commit is contained in:
parent
26c9f964be
commit
5418c1fefc
11 changed files with 74 additions and 26 deletions
|
@ -86,7 +86,7 @@ void statusMonitor(void *np){
|
|||
}
|
||||
Util::sleep(3000); // wait at least 3 seconds
|
||||
}
|
||||
if (Controller::restarting){
|
||||
if (Util::Config::is_restarting){
|
||||
Controller::prepareActiveConnectorsForReload();
|
||||
}else{
|
||||
Controller::prepareActiveConnectorsForShutdown();
|
||||
|
@ -457,7 +457,7 @@ int main_loop(int argc, char **argv){
|
|||
}else{
|
||||
shutdown_reason = "socket problem (API port closed)";
|
||||
}
|
||||
if (Controller::restarting){shutdown_reason = "restart (on request)";}
|
||||
if (Util::Config::is_restarting){shutdown_reason = "restart (on request)";}
|
||||
/*LTS-START*/
|
||||
#ifdef LICENSING
|
||||
if (!Controller::isLicensed()){shutdown_reason = "no valid license";}
|
||||
|
@ -465,7 +465,7 @@ int main_loop(int argc, char **argv){
|
|||
if (Triggers::shouldTrigger("SYSTEM_STOP")){
|
||||
if (!Triggers::doTrigger("SYSTEM_STOP", shutdown_reason)){
|
||||
Controller::conf.is_active = true;
|
||||
Controller::restarting = false;
|
||||
Util::Config::is_restarting = false;
|
||||
Util::sleep(1000);
|
||||
}else{
|
||||
Controller::conf.is_active = false;
|
||||
|
@ -513,7 +513,7 @@ int main_loop(int argc, char **argv){
|
|||
<< " seconds, on license server request..." << std::endl;
|
||||
while (Controller::exitDelay--){Util::wait(1000);}
|
||||
}
|
||||
if (Controller::restarting){return 42;}
|
||||
if (Util::Config::is_restarting){return 42;}
|
||||
// close stderr to make the stderr reading thread exit
|
||||
close(STDERR_FILENO);
|
||||
return 0;
|
||||
|
@ -521,7 +521,7 @@ int main_loop(int argc, char **argv){
|
|||
|
||||
void handleUSR1(int signum, siginfo_t *sigInfo, void *ignore){
|
||||
Controller::Log("CONF", "USR1 received - restarting controller");
|
||||
Controller::restarting = true;
|
||||
Util::Config::is_restarting = true;
|
||||
raise(SIGINT); // trigger restart
|
||||
}
|
||||
|
||||
|
@ -561,9 +561,9 @@ int main(int argc, char **argv){
|
|||
// wait for the process to exit
|
||||
int status;
|
||||
while (waitpid(pid, &status, 0) != pid && errno == EINTR){
|
||||
if (Controller::restarting){
|
||||
if (Util::Config::is_restarting){
|
||||
Controller::conf.is_active = true;
|
||||
Controller::restarting = false;
|
||||
Util::Config::is_restarting = false;
|
||||
kill(pid, SIGUSR1);
|
||||
}
|
||||
if (!Controller::conf.is_active){
|
||||
|
|
|
@ -51,11 +51,13 @@ namespace Controller {
|
|||
IPC::sharedPage f("MstCnns", 4096, false, false);
|
||||
const Util::RelAccX A(f.mapped, false);
|
||||
if (A.isReady()){
|
||||
INFO_MSG("Reloading existing connectors to complete rolling restart");
|
||||
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));
|
||||
kill(A.getInt("pid", i), SIGUSR1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ namespace Controller{
|
|||
Util::wait(1000); // wait at least a second
|
||||
}
|
||||
//keep the pushPage if we are restarting, so we can restore state from it
|
||||
if (Controller::restarting){
|
||||
if (Util::Config::is_restarting){
|
||||
pushPage.master = false;
|
||||
//forget about all pushes, so they keep running
|
||||
for (std::map<pid_t, JSON::Value>::iterator it = activePushes.begin(); it != activePushes.end(); ++it){
|
||||
|
|
|
@ -433,7 +433,7 @@ void Controller::SharedMemStats(void * config){
|
|||
}
|
||||
statPointer = 0;
|
||||
HIGH_MSG("Stopping stats thread");
|
||||
if (Controller::restarting){
|
||||
if (Util::Config::is_restarting){
|
||||
statServer.abandon();
|
||||
shmSessions->master = false;
|
||||
}else{/*LTS-START*/
|
||||
|
@ -443,7 +443,7 @@ void Controller::SharedMemStats(void * config){
|
|||
}
|
||||
/*LTS-END*/
|
||||
}
|
||||
Controller::deinitState(Controller::restarting);
|
||||
Controller::deinitState(Util::Config::is_restarting);
|
||||
delete shmSessions;
|
||||
shmSessions = 0;
|
||||
delete cacheLock;
|
||||
|
|
|
@ -21,7 +21,6 @@ namespace Controller{
|
|||
tthread::mutex logMutex;
|
||||
uint64_t logCounter = 0;
|
||||
bool configChanged = false;
|
||||
bool restarting = false;
|
||||
bool isTerminal = false;
|
||||
bool isColorized = false;
|
||||
uint32_t maxLogsRecs = 0;
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace Controller {
|
|||
extern tthread::mutex logMutex;///< Mutex for log thread.
|
||||
extern tthread::mutex configMutex;///< Mutex for server config access.
|
||||
extern bool configChanged; ///< Bool that indicates config must be written to SHM.
|
||||
extern bool restarting;///< Signals if the controller is shutting down (false) or restarting (true).
|
||||
extern bool isTerminal;///< True if connected to a terminal and not a log file.
|
||||
extern bool isColorized;///< True if we colorize the output
|
||||
extern uint64_t logCounter; ///<Count of logged messages since boot
|
||||
|
|
|
@ -9,6 +9,12 @@ int spawnForked(Socket::Connection & S){
|
|||
return tmp.run();
|
||||
}
|
||||
|
||||
void handleUSR1(int signum, siginfo_t *sigInfo, void *ignore){
|
||||
HIGH_MSG("USR1 received - triggering rolling restart");
|
||||
Util::Config::is_restarting = true;
|
||||
Util::Config::is_active = false;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
Util::redirectLogsIfNeeded();
|
||||
Util::Config conf(argv[0]);
|
||||
|
@ -21,7 +27,19 @@ int main(int argc, char * argv[]) {
|
|||
}
|
||||
conf.activate();
|
||||
if (mistOut::listenMode()){
|
||||
{
|
||||
struct sigaction new_action;
|
||||
new_action.sa_sigaction = handleUSR1;
|
||||
sigemptyset(&new_action.sa_mask);
|
||||
new_action.sa_flags = 0;
|
||||
sigaction(SIGUSR1, &new_action, NULL);
|
||||
}
|
||||
mistOut::listener(conf, spawnForked);
|
||||
if (conf.is_restarting && Socket::checkTrueSocket(0)){
|
||||
INFO_MSG("Reloading input while re-using server socket");
|
||||
execvp(argv[0], argv);
|
||||
FAIL_MSG("Error reloading: %s", strerror(errno));
|
||||
}
|
||||
}else{
|
||||
Socket::Connection S(fileno(stdout),fileno(stdin) );
|
||||
mistOut tmp(S);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue