mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
add option to disable AC child file logging
This commit is contained in:
parent
5b2c3b4b26
commit
efa46b8c7b
4 changed files with 71 additions and 44 deletions
|
@ -96,6 +96,9 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
const QCommandLineOption logDirectoryOption(ASSIGNMENT_LOG_DIRECTORY, "directory to store logs", "log-directory");
|
const QCommandLineOption logDirectoryOption(ASSIGNMENT_LOG_DIRECTORY, "directory to store logs", "log-directory");
|
||||||
parser.addOption(logDirectoryOption);
|
parser.addOption(logDirectoryOption);
|
||||||
|
|
||||||
|
const QCommandLineOption noLogFileOption(ASSIGNMENT_NO_CHILD_LOG_FILE_OPTION, "disable writing of child assignment-client output to file");
|
||||||
|
parser.addOption(noLogFileOption);
|
||||||
|
|
||||||
if (!parser.parse(QCoreApplication::arguments())) {
|
if (!parser.parse(QCoreApplication::arguments())) {
|
||||||
qCritical() << parser.errorText() << endl;
|
qCritical() << parser.errorText() << endl;
|
||||||
parser.showHelp();
|
parser.showHelp();
|
||||||
|
@ -139,12 +142,19 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
httpStatusPort = parser.value(httpStatusPortOption).toUShort();
|
httpStatusPort = parser.value(httpStatusPortOption).toUShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wantsChildFileLogging = false;
|
||||||
QDir logDirectory { "." };
|
QDir logDirectory { "." };
|
||||||
|
|
||||||
|
if (!parser.isSet(noLogFileOption)) {
|
||||||
|
wantsChildFileLogging = true;
|
||||||
|
|
||||||
if (parser.isSet(logDirectoryOption)) {
|
if (parser.isSet(logDirectoryOption)) {
|
||||||
logDirectory = parser.value(logDirectoryOption);
|
logDirectory = parser.value(logDirectoryOption);
|
||||||
} else {
|
} else {
|
||||||
logDirectory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
logDirectory = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Assignment::Type requestAssignmentType = Assignment::AllTypes;
|
Assignment::Type requestAssignmentType = Assignment::AllTypes;
|
||||||
if (argumentVariantMap.contains(ASSIGNMENT_TYPE_OVERRIDE_OPTION)) {
|
if (argumentVariantMap.contains(ASSIGNMENT_TYPE_OVERRIDE_OPTION)) {
|
||||||
|
@ -216,7 +226,8 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
AssignmentClientMonitor* monitor = new AssignmentClientMonitor(numForks, minForks, maxForks,
|
AssignmentClientMonitor* monitor = new AssignmentClientMonitor(numForks, minForks, maxForks,
|
||||||
requestAssignmentType, assignmentPool,
|
requestAssignmentType, assignmentPool,
|
||||||
listenPort, walletUUID, assignmentServerHostname,
|
listenPort, walletUUID, assignmentServerHostname,
|
||||||
assignmentServerPort, httpStatusPort, logDirectory);
|
assignmentServerPort, httpStatusPort, logDirectory,
|
||||||
|
wantsChildFileLogging);
|
||||||
monitor->setParent(this);
|
monitor->setParent(this);
|
||||||
connect(this, &QCoreApplication::aboutToQuit, monitor, &AssignmentClientMonitor::aboutToQuit);
|
connect(this, &QCoreApplication::aboutToQuit, monitor, &AssignmentClientMonitor::aboutToQuit);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,6 +27,7 @@ const QString ASSIGNMENT_MAX_FORKS_OPTION = "max";
|
||||||
const QString ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION = "monitor-port";
|
const QString ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION = "monitor-port";
|
||||||
const QString ASSIGNMENT_HTTP_STATUS_PORT = "http-status-port";
|
const QString ASSIGNMENT_HTTP_STATUS_PORT = "http-status-port";
|
||||||
const QString ASSIGNMENT_LOG_DIRECTORY = "log-directory";
|
const QString ASSIGNMENT_LOG_DIRECTORY = "log-directory";
|
||||||
|
const QString ASSIGNMENT_NO_CHILD_LOG_FILE_OPTION = "no-child-log-files";
|
||||||
|
|
||||||
class AssignmentClientApp : public QCoreApplication {
|
class AssignmentClientApp : public QCoreApplication {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -33,7 +33,8 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
||||||
const unsigned int maxAssignmentClientForks,
|
const unsigned int maxAssignmentClientForks,
|
||||||
Assignment::Type requestAssignmentType, QString assignmentPool,
|
Assignment::Type requestAssignmentType, QString assignmentPool,
|
||||||
quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
||||||
quint16 assignmentServerPort, quint16 httpStatusServerPort, QDir logDirectory) :
|
quint16 assignmentServerPort, quint16 httpStatusServerPort, QDir logDirectory,
|
||||||
|
bool wantsChildFileLogging) :
|
||||||
_logDirectory(logDirectory),
|
_logDirectory(logDirectory),
|
||||||
_httpManager(QHostAddress::LocalHost, httpStatusServerPort, "", this),
|
_httpManager(QHostAddress::LocalHost, httpStatusServerPort, "", this),
|
||||||
_numAssignmentClientForks(numAssignmentClientForks),
|
_numAssignmentClientForks(numAssignmentClientForks),
|
||||||
|
@ -43,7 +44,8 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
||||||
_assignmentPool(assignmentPool),
|
_assignmentPool(assignmentPool),
|
||||||
_walletUUID(walletUUID),
|
_walletUUID(walletUUID),
|
||||||
_assignmentServerHostname(assignmentServerHostname),
|
_assignmentServerHostname(assignmentServerHostname),
|
||||||
_assignmentServerPort(assignmentServerPort)
|
_assignmentServerPort(assignmentServerPort),
|
||||||
|
_wantsChildFileLogging(wantsChildFileLogging)
|
||||||
|
|
||||||
{
|
{
|
||||||
qDebug() << "_requestAssignmentType =" << _requestAssignmentType;
|
qDebug() << "_requestAssignmentType =" << _requestAssignmentType;
|
||||||
|
@ -159,6 +161,10 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
_childArguments.append("--" + ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION);
|
_childArguments.append("--" + ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION);
|
||||||
_childArguments.append(QString::number(DependencyManager::get<NodeList>()->getLocalSockAddr().getPort()));
|
_childArguments.append(QString::number(DependencyManager::get<NodeList>()->getLocalSockAddr().getPort()));
|
||||||
|
|
||||||
|
QString nowString, stdoutFilenameTemp, stderrFilenameTemp, stdoutPathTemp, stderrPathTemp;
|
||||||
|
|
||||||
|
|
||||||
|
if (_wantsChildFileLogging) {
|
||||||
// Setup log files
|
// Setup log files
|
||||||
const QString DATETIME_FORMAT = "yyyyMMdd.hh.mm.ss.zzz";
|
const QString DATETIME_FORMAT = "yyyyMMdd.hh.mm.ss.zzz";
|
||||||
|
|
||||||
|
@ -167,26 +173,30 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
_logDirectory.mkpath(_logDirectory.absolutePath());
|
_logDirectory.mkpath(_logDirectory.absolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nowString = QDateTime::currentDateTime().toString(DATETIME_FORMAT);
|
nowString = QDateTime::currentDateTime().toString(DATETIME_FORMAT);
|
||||||
auto stdoutFilenameTemp = QString("ac-%1-stdout.txt").arg(nowString);
|
stdoutFilenameTemp = QString("ac-%1-stdout.txt").arg(nowString);
|
||||||
auto stderrFilenameTemp = QString("ac-%1-stderr.txt").arg(nowString);
|
stderrFilenameTemp = QString("ac-%1-stderr.txt").arg(nowString);
|
||||||
QString stdoutPathTemp = _logDirectory.absoluteFilePath(stdoutFilenameTemp);
|
stdoutPathTemp = _logDirectory.absoluteFilePath(stdoutFilenameTemp);
|
||||||
QString stderrPathTemp = _logDirectory.absoluteFilePath(stderrFilenameTemp);
|
stderrPathTemp = _logDirectory.absoluteFilePath(stderrFilenameTemp);
|
||||||
|
|
||||||
// reset our output and error files
|
// reset our output and error files
|
||||||
assignmentClient->setStandardOutputFile(stdoutPathTemp);
|
assignmentClient->setStandardOutputFile(stdoutPathTemp);
|
||||||
assignmentClient->setStandardErrorFile(stderrPathTemp);
|
assignmentClient->setStandardErrorFile(stderrPathTemp);
|
||||||
|
}
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
|
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
|
||||||
|
|
||||||
|
QString stdoutPath, stderrPath;
|
||||||
|
|
||||||
|
if (_wantsChildFileLogging) {
|
||||||
|
|
||||||
// Update log path to use PID in filename
|
// Update log path to use PID in filename
|
||||||
auto stdoutFilename = QString("ac-%1_%2-stdout.txt").arg(nowString).arg(assignmentClient->processId());
|
auto stdoutFilename = QString("ac-%1_%2-stdout.txt").arg(nowString).arg(assignmentClient->processId());
|
||||||
auto stderrFilename = QString("ac-%1_%2-stderr.txt").arg(nowString).arg(assignmentClient->processId());
|
auto stderrFilename = QString("ac-%1_%2-stderr.txt").arg(nowString).arg(assignmentClient->processId());
|
||||||
QString stdoutPath = _logDirectory.absoluteFilePath(stdoutFilename);
|
stdoutPath = _logDirectory.absoluteFilePath(stdoutFilename);
|
||||||
QString stderrPath = _logDirectory.absoluteFilePath(stderrFilename);
|
stderrPath = _logDirectory.absoluteFilePath(stderrFilename);
|
||||||
|
|
||||||
qDebug() << "Renaming " << stdoutPathTemp << " to " << stdoutPath;
|
qDebug() << "Renaming " << stdoutPathTemp << " to " << stdoutPath;
|
||||||
if (!_logDirectory.rename(stdoutFilenameTemp, stdoutFilename)) {
|
if (!_logDirectory.rename(stdoutFilenameTemp, stdoutFilename)) {
|
||||||
|
@ -204,6 +214,7 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
|
|
||||||
qDebug() << "Child stdout being written to: " << stdoutFilename;
|
qDebug() << "Child stdout being written to: " << stdoutFilename;
|
||||||
qDebug() << "Child stderr being written to: " << stderrFilename;
|
qDebug() << "Child stderr being written to: " << stderrFilename;
|
||||||
|
}
|
||||||
|
|
||||||
if (assignmentClient->processId() > 0) {
|
if (assignmentClient->processId() > 0) {
|
||||||
auto pid = assignmentClient->processId();
|
auto pid = assignmentClient->processId();
|
||||||
|
@ -212,6 +223,7 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
this, [this, pid]() { childProcessFinished(pid); });
|
this, [this, pid]() { childProcessFinished(pid); });
|
||||||
|
|
||||||
qDebug() << "Spawned a child client with PID" << assignmentClient->processId();
|
qDebug() << "Spawned a child client with PID" << assignmentClient->processId();
|
||||||
|
|
||||||
_childProcesses.insert(assignmentClient->processId(), { assignmentClient, stdoutPath, stderrPath });
|
_childProcesses.insert(assignmentClient->processId(), { assignmentClient, stdoutPath, stderrPath });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,8 @@ public:
|
||||||
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
||||||
const unsigned int maxAssignmentClientForks, Assignment::Type requestAssignmentType,
|
const unsigned int maxAssignmentClientForks, Assignment::Type requestAssignmentType,
|
||||||
QString assignmentPool, quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
QString assignmentPool, quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
||||||
quint16 assignmentServerPort, quint16 httpStatusServerPort, QDir logDirectory);
|
quint16 assignmentServerPort, quint16 httpStatusServerPort, QDir logDirectory,
|
||||||
|
bool wantsChildFileLogging);
|
||||||
~AssignmentClientMonitor();
|
~AssignmentClientMonitor();
|
||||||
|
|
||||||
void stopChildProcesses();
|
void stopChildProcesses();
|
||||||
|
@ -73,6 +74,8 @@ private:
|
||||||
quint16 _assignmentServerPort;
|
quint16 _assignmentServerPort;
|
||||||
|
|
||||||
QMap<qint64, ACProcess> _childProcesses;
|
QMap<qint64, ACProcess> _childProcesses;
|
||||||
|
|
||||||
|
bool _wantsChildFileLogging;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AssignmentClientMonitor_h
|
#endif // hifi_AssignmentClientMonitor_h
|
||||||
|
|
Loading…
Reference in a new issue