Update server-console to watch interface via pid rather than marker

This commit is contained in:
Ryan Huffman 2017-06-01 11:20:36 -07:00
parent efe72e1b85
commit aaf9b9ac7f
4 changed files with 28 additions and 6 deletions

View file

@ -200,7 +200,7 @@ int main(int argc, const char* argv[]) {
bool serverContentPathOptionIsSet = parser.isSet(serverContentPathOption);
QString serverContentPath = serverContentPathOptionIsSet ? parser.value(serverContentPathOption) : QString();
if (runServer) {
SandboxUtils::runLocalSandbox(serverContentPath, true, RUNNING_MARKER_FILENAME, noUpdater);
SandboxUtils::runLocalSandbox(serverContentPath, true, noUpdater);
}
Application app(argc, const_cast<char**>(argv), startupTime, runningMarkerExisted);

View file

@ -52,9 +52,8 @@ bool readStatus(QByteArray statusData) {
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";
qCDebug(networking) << "Running marker path is: " << runningMarkerName;
qCDebug(networking) << "Server path is: " << serverPath;
qCDebug(networking) << "autoShutdown: " << autoShutdown;
qCDebug(networking) << "noUpdater: " << noUpdater;
@ -74,8 +73,9 @@ void runLocalSandbox(QString contentPath, bool autoShutdown, QString runningMark
}
if (autoShutdown) {
QString interfaceRunningStateFile = RunningMarker::getMarkerFilePath(runningMarkerName);
args << "--shutdownWatcher" << interfaceRunningStateFile;
auto pid = qApp->applicationPid();
qCDebug(networking) << "autoShutdown pid is" << pid;
args << "--watchProcessShutdown" << QString::number(pid);
}
if (noUpdater) {

View file

@ -21,7 +21,7 @@ namespace SandboxUtils {
QNetworkReply* getStatus();
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

View file

@ -821,6 +821,15 @@ for (var key in trayIcons) {
const notificationIcon = path.join(__dirname, '../resources/console-notification.png');
function isProcessRunning(pid) {
try {
running = process.kill(pid, 0);
return true;
} catch (e) {
}
return false;
}
function onContentLoaded() {
// Disable splash window for now.
// maybeShowSplash();
@ -882,6 +891,19 @@ function onContentLoaded() {
startInterface();
}
if (argv.watchProcessShutdown) {
let pid = argv.watchProcessShutdown;
console.log("Watching process: ", pid);
let watchProcessInterval = setInterval(function() {
let isRunning = isProcessRunning(pid);
if (!isRunning) {
log.debug("Watched process is no longer running, shutting down");
clearTimeout(watchProcessInterval);
forcedShutdown();
}
}, 5000);
}
// If we were launched with the shutdownWatcher option, then we need to watch for the interface app
// shutting down. The interface app will regularly update a running state file which we will check.
// If the file doesn't exist or stops updating for a significant amount of time, we will shut down.