Merge pull request #10637 from highfidelity/RC-42-Hotfix

Build 42.1 Hotfix Update server-console to watch interface via pid rather than marker
This commit is contained in:
Stephen Birarda 2017-06-07 19:05:40 -07:00 committed by GitHub
commit f884de87ad
6 changed files with 31 additions and 80 deletions

View file

@ -190,7 +190,7 @@ int main(int argc, const char* argv[]) {
int exitCode; int exitCode;
{ {
RunningMarker runningMarker(nullptr, RUNNING_MARKER_FILENAME); RunningMarker runningMarker(RUNNING_MARKER_FILENAME);
bool runningMarkerExisted = runningMarker.fileExists(); bool runningMarkerExisted = runningMarker.fileExists();
runningMarker.writeRunningMarkerFile(); runningMarker.writeRunningMarkerFile();
@ -199,14 +199,11 @@ int main(int argc, const char* argv[]) {
bool serverContentPathOptionIsSet = parser.isSet(serverContentPathOption); bool serverContentPathOptionIsSet = parser.isSet(serverContentPathOption);
QString serverContentPath = serverContentPathOptionIsSet ? parser.value(serverContentPathOption) : QString(); QString serverContentPath = serverContentPathOptionIsSet ? parser.value(serverContentPathOption) : QString();
if (runServer) { if (runServer) {
SandboxUtils::runLocalSandbox(serverContentPath, true, RUNNING_MARKER_FILENAME, noUpdater); SandboxUtils::runLocalSandbox(serverContentPath, true, noUpdater);
} }
Application app(argc, const_cast<char**>(argv), startupTime, runningMarkerExisted); Application app(argc, const_cast<char**>(argv), startupTime, runningMarkerExisted);
// Now that the main event loop is setup, launch running marker thread
runningMarker.startRunningMarker();
// If we failed the OpenGLVersion check, log it. // If we failed the OpenGLVersion check, log it.
if (override) { if (override) {
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();

View file

@ -52,9 +52,8 @@ bool readStatus(QByteArray statusData) {
return false; return false;
} }
void runLocalSandbox(QString contentPath, bool autoShutdown, QString runningMarkerName, bool noUpdater) { void runLocalSandbox(QString contentPath, bool autoShutdown, bool noUpdater) {
QString serverPath = "./server-console/server-console.exe"; QString serverPath = "./server-console/server-console.exe";
qCDebug(networking) << "Running marker path is: " << runningMarkerName;
qCDebug(networking) << "Server path is: " << serverPath; qCDebug(networking) << "Server path is: " << serverPath;
qCDebug(networking) << "autoShutdown: " << autoShutdown; qCDebug(networking) << "autoShutdown: " << autoShutdown;
qCDebug(networking) << "noUpdater: " << noUpdater; qCDebug(networking) << "noUpdater: " << noUpdater;
@ -74,8 +73,8 @@ void runLocalSandbox(QString contentPath, bool autoShutdown, QString runningMark
} }
if (autoShutdown) { if (autoShutdown) {
QString interfaceRunningStateFile = RunningMarker::getMarkerFilePath(runningMarkerName); auto pid = QCoreApplication::applicationPid();
args << "--shutdownWatcher" << interfaceRunningStateFile; args << "--shutdownWith" << QString::number(pid);
} }
if (noUpdater) { if (noUpdater) {

View file

@ -21,7 +21,7 @@ namespace SandboxUtils {
QNetworkReply* getStatus(); QNetworkReply* getStatus();
bool readStatus(QByteArray statusData); bool readStatus(QByteArray statusData);
void runLocalSandbox(QString contentPath, bool autoShutdown, QString runningMarkerName, bool noUpdater); void runLocalSandbox(QString contentPath, bool autoShutdown, bool noUpdater);
}; };
#endif // hifi_SandboxUtils_h #endif // hifi_SandboxUtils_h

View file

@ -13,44 +13,16 @@
#include <QFile> #include <QFile>
#include <QStandardPaths> #include <QStandardPaths>
#include <QThread>
#include <QTimer>
#include "NumericalConstants.h"
#include "PathUtils.h" #include "PathUtils.h"
RunningMarker::RunningMarker(QObject* parent, QString name) : RunningMarker::RunningMarker(QString name) :
_parent(parent),
_name(name) _name(name)
{ {
} }
void RunningMarker::startRunningMarker() {
static const int RUNNING_STATE_CHECK_IN_MSECS = MSECS_PER_SECOND;
// start the nodeThread so its event loop is running
_runningMarkerThread = new QThread(_parent);
_runningMarkerThread->setObjectName("Running Marker Thread");
_runningMarkerThread->start();
writeRunningMarkerFile(); // write the first file, even before timer
_runningMarkerTimer = new QTimer();
QObject::connect(_runningMarkerTimer, &QTimer::timeout, [=](){
writeRunningMarkerFile();
});
_runningMarkerTimer->start(RUNNING_STATE_CHECK_IN_MSECS);
// put the time on the thread
_runningMarkerTimer->moveToThread(_runningMarkerThread);
}
RunningMarker::~RunningMarker() { RunningMarker::~RunningMarker() {
deleteRunningMarkerFile(); deleteRunningMarkerFile();
QMetaObject::invokeMethod(_runningMarkerTimer, "stop", Qt::BlockingQueuedConnection);
_runningMarkerThread->quit();
_runningMarkerTimer->deleteLater();
_runningMarkerThread->deleteLater();
} }
bool RunningMarker::fileExists() const { bool RunningMarker::fileExists() const {
@ -77,8 +49,3 @@ void RunningMarker::deleteRunningMarkerFile() {
QString RunningMarker::getFilePath() const { QString RunningMarker::getFilePath() const {
return QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + _name; return QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + _name;
} }
QString RunningMarker::getMarkerFilePath(QString name) {
return QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + name;
}

View file

@ -12,21 +12,14 @@
#ifndef hifi_RunningMarker_h #ifndef hifi_RunningMarker_h
#define hifi_RunningMarker_h #define hifi_RunningMarker_h
#include <QObject>
#include <QString> #include <QString>
class QThread;
class QTimer;
class RunningMarker { class RunningMarker {
public: public:
RunningMarker(QObject* parent, QString name); RunningMarker(QString name);
~RunningMarker(); ~RunningMarker();
void startRunningMarker();
QString getFilePath() const; QString getFilePath() const;
static QString getMarkerFilePath(QString name);
bool fileExists() const; bool fileExists() const;
@ -34,10 +27,7 @@ public:
void deleteRunningMarkerFile(); void deleteRunningMarkerFile();
private: private:
QObject* _parent { nullptr };
QString _name; QString _name;
QThread* _runningMarkerThread { nullptr };
QTimer* _runningMarkerTimer { nullptr };
}; };
#endif // hifi_RunningMarker_h #endif // hifi_RunningMarker_h

View file

@ -821,6 +821,17 @@ for (var key in trayIcons) {
const notificationIcon = path.join(__dirname, '../resources/console-notification.png'); const notificationIcon = path.join(__dirname, '../resources/console-notification.png');
function isProcessRunning(pid) {
try {
// Sending a signal of 0 is effectively a NOOP.
// If sending the signal is successful, kill will return true.
// If the process is not running, an exception will be thrown.
return process.kill(pid, 0);
} catch (e) {
}
return false;
}
function onContentLoaded() { function onContentLoaded() {
// Disable splash window for now. // Disable splash window for now.
// maybeShowSplash(); // maybeShowSplash();
@ -882,31 +893,18 @@ function onContentLoaded() {
startInterface(); startInterface();
} }
// If we were launched with the shutdownWatcher option, then we need to watch for the interface app // If we were launched with the shutdownWith option, then we need to shutdown when that process (pid)
// shutting down. The interface app will regularly update a running state file which we will check. // is no longer running.
// If the file doesn't exist or stops updating for a significant amount of time, we will shut down. if (argv.shutdownWith) {
if (argv.shutdownWatcher) { let pid = argv.shutdownWith;
log.debug("Shutdown watcher requested... argv.shutdownWatcher:", argv.shutdownWatcher); console.log("Shutting down with process: ", pid);
var MAX_TIME_SINCE_EDIT = 5000; // 5 seconds between updates let checkProcessInterval = setInterval(function() {
var firstAttemptToCheck = new Date().getTime(); let isRunning = isProcessRunning(pid);
var shutdownWatchInterval = setInterval(function(){ if (!isRunning) {
var stats = fs.stat(argv.shutdownWatcher, function(err, stats) { log.debug("Watched process is no longer running, shutting down");
if (err) { clearTimeout(checkProcessInterval);
var sinceFirstCheck = new Date().getTime() - firstAttemptToCheck; forcedShutdown();
if (sinceFirstCheck > MAX_TIME_SINCE_EDIT) { }
log.debug("Running state file is missing, assume interface has shutdown... shutting down snadbox.");
forcedShutdown();
clearTimeout(shutdownWatchInterval);
}
} else {
var sinceEdit = new Date().getTime() - stats.mtime.getTime();
if (sinceEdit > MAX_TIME_SINCE_EDIT) {
log.debug("Running state of interface hasn't updated in MAX time... shutting down.");
forcedShutdown();
clearTimeout(shutdownWatchInterval);
}
}
});
}, 1000); }, 1000);
} }
} }