mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:37:49 +02:00
have AssignmentClientMonitor catch SIGTERM and cleanup
This commit is contained in:
parent
3a8e89f754
commit
dac980d433
2 changed files with 43 additions and 0 deletions
|
@ -9,6 +9,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <LogHandler.h>
|
#include <LogHandler.h>
|
||||||
|
|
||||||
#include "AssignmentClientMonitor.h"
|
#include "AssignmentClientMonitor.h"
|
||||||
|
@ -17,9 +19,21 @@ const char* NUM_FORKS_PARAMETER = "-n";
|
||||||
|
|
||||||
const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor";
|
const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor";
|
||||||
|
|
||||||
|
void signalHandler(int param){
|
||||||
|
// get the qApp and cast it to an AssignmentClientMonitor
|
||||||
|
AssignmentClientMonitor* app = qobject_cast<AssignmentClientMonitor*>(qApp);
|
||||||
|
|
||||||
|
// tell it to stop the child processes and then go down
|
||||||
|
app->stopChildProcesses();
|
||||||
|
app->quit();
|
||||||
|
}
|
||||||
|
|
||||||
AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks) :
|
AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks) :
|
||||||
QCoreApplication(argc, argv)
|
QCoreApplication(argc, argv)
|
||||||
{
|
{
|
||||||
|
// be a signal handler for SIGTERM so we can stop our children when we get it
|
||||||
|
signal(SIGTERM, signalHandler);
|
||||||
|
|
||||||
// start the Logging class with the parent's target name
|
// start the Logging class with the parent's target name
|
||||||
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME);
|
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME);
|
||||||
|
|
||||||
|
@ -38,9 +52,29 @@ AssignmentClientMonitor::AssignmentClientMonitor(int &argc, char **argv, int num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssignmentClientMonitor::stopChildProcesses() {
|
||||||
|
|
||||||
|
QList<QPointer<QProcess> >::Iterator it = _childProcesses.begin();
|
||||||
|
while (it != _childProcesses.end()) {
|
||||||
|
if (!it->isNull()) {
|
||||||
|
qDebug() << "Monitor is terminating child process" << it->data();
|
||||||
|
|
||||||
|
// don't re-spawn this child when it goes down
|
||||||
|
disconnect(it->data(), 0, this, 0);
|
||||||
|
|
||||||
|
it->data()->terminate();
|
||||||
|
it->data()->waitForFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
it = _childProcesses.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AssignmentClientMonitor::spawnChildClient() {
|
void AssignmentClientMonitor::spawnChildClient() {
|
||||||
QProcess *assignmentClient = new QProcess(this);
|
QProcess *assignmentClient = new QProcess(this);
|
||||||
|
|
||||||
|
_childProcesses.append(QPointer<QProcess>(assignmentClient));
|
||||||
|
|
||||||
// make sure that the output from the child process appears in our output
|
// make sure that the output from the child process appears in our output
|
||||||
assignmentClient->setProcessChannelMode(QProcess::ForwardedChannels);
|
assignmentClient->setProcessChannelMode(QProcess::ForwardedChannels);
|
||||||
|
|
||||||
|
@ -55,5 +89,10 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
|
|
||||||
void AssignmentClientMonitor::childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) {
|
void AssignmentClientMonitor::childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
qDebug("Replacing dead child assignment client with a new one");
|
qDebug("Replacing dead child assignment client with a new one");
|
||||||
|
|
||||||
|
// remove the old process from our list of child processes
|
||||||
|
qDebug() << "need to remove" << QPointer<QProcess>(qobject_cast<QProcess*>(sender()));
|
||||||
|
_childProcesses.removeOne(QPointer<QProcess>(qobject_cast<QProcess*>(sender())));
|
||||||
|
|
||||||
spawnChildClient();
|
spawnChildClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define hifi_AssignmentClientMonitor_h
|
#define hifi_AssignmentClientMonitor_h
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtCore/qpointer.h>
|
||||||
#include <QtCore/QProcess>
|
#include <QtCore/QProcess>
|
||||||
|
|
||||||
#include <Assignment.h>
|
#include <Assignment.h>
|
||||||
|
@ -23,10 +24,13 @@ class AssignmentClientMonitor : public QCoreApplication {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks);
|
AssignmentClientMonitor(int &argc, char **argv, int numAssignmentClientForks);
|
||||||
|
|
||||||
|
void stopChildProcesses();
|
||||||
private slots:
|
private slots:
|
||||||
void childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void childProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
private:
|
private:
|
||||||
void spawnChildClient();
|
void spawnChildClient();
|
||||||
|
QList<QPointer<QProcess> > _childProcesses;
|
||||||
|
|
||||||
QStringList _childArguments;
|
QStringList _childArguments;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue