Generalized Util::Config::is_restarting for rolling restarts, added rolling restart support to listening socket outputs
This commit is contained in:
parent
42da518d5f
commit
ea443945fe
10 changed files with 72 additions and 24 deletions
|
@ -78,7 +78,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();
|
||||
|
@ -371,7 +371,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)";}
|
||||
Controller::conf.is_active = false;
|
||||
Controller::Log("CONF", "Controller shutting down because of " + shutdown_reason);
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ int main_loop(int argc, char **argv){
|
|||
// give everything some time to print messages
|
||||
Util::wait(100);
|
||||
std::cout << "Killed all processes, wrote config to disk. Exiting." << std::endl;
|
||||
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;
|
||||
|
@ -396,7 +396,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
|
||||
}
|
||||
|
||||
|
@ -436,9 +436,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){
|
||||
|
|
|
@ -56,11 +56,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,10 +196,10 @@ void Controller::SharedMemStats(void * config){
|
|||
}
|
||||
statPointer = 0;
|
||||
HIGH_MSG("Stopping stats thread");
|
||||
if (Controller::restarting){
|
||||
if (Util::Config::is_restarting){
|
||||
statServer.abandon();
|
||||
}
|
||||
Controller::deinitState(Controller::restarting);
|
||||
Controller::deinitState(Util::Config::is_restarting);
|
||||
}
|
||||
|
||||
/// Gets a complete list of all streams currently in active state, with optional prefix matching
|
||||
|
|
|
@ -20,7 +20,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;
|
||||
|
|
|
@ -11,7 +11,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