mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-22 19:49:34 +00:00
DaemonManager: take dataDir into account when sending cmd
This commit is contained in:
parent
aef4a982dc
commit
80ade41905
6 changed files with 37 additions and 31 deletions
|
@ -201,6 +201,7 @@ Rectangle {
|
||||||
daemonManager.sendCommandAsync(
|
daemonManager.sendCommandAsync(
|
||||||
["set_bootstrap_daemon", "auto"],
|
["set_bootstrap_daemon", "auto"],
|
||||||
appWindow.currentWallet.nettype,
|
appWindow.currentWallet.nettype,
|
||||||
|
persistentSettings.blockchainDataDir,
|
||||||
callback);
|
callback);
|
||||||
|
|
||||||
refreshMouseArea.visible = false;
|
refreshMouseArea.visible = false;
|
||||||
|
|
6
main.qml
6
main.qml
|
@ -469,7 +469,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
// If wallet isnt connected, advanced wallet mode and no daemon is running - Ask
|
// If wallet isnt connected, advanced wallet mode and no daemon is running - Ask
|
||||||
if (appWindow.walletMode >= 2 && !persistentSettings.useRemoteNode && !walletInitialized && disconnected) {
|
if (appWindow.walletMode >= 2 && !persistentSettings.useRemoteNode && !walletInitialized && disconnected) {
|
||||||
daemonManager.runningAsync(persistentSettings.nettype, function(running) {
|
daemonManager.runningAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, function(running) {
|
||||||
if (!running) {
|
if (!running) {
|
||||||
daemonManagerDialog.open();
|
daemonManagerDialog.open();
|
||||||
}
|
}
|
||||||
|
@ -714,7 +714,7 @@ ApplicationWindow {
|
||||||
appWindow.showProcessingSplash(qsTr("Waiting for daemon to stop..."));
|
appWindow.showProcessingSplash(qsTr("Waiting for daemon to stop..."));
|
||||||
}
|
}
|
||||||
p2poolManager.exit()
|
p2poolManager.exit()
|
||||||
daemonManager.stopAsync(persistentSettings.nettype, function(result) {
|
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, function(result) {
|
||||||
daemonStartStopInProgress = 0;
|
daemonStartStopInProgress = 0;
|
||||||
if (splash) {
|
if (splash) {
|
||||||
hideProcessingSplash();
|
hideProcessingSplash();
|
||||||
|
@ -2141,7 +2141,7 @@ ApplicationWindow {
|
||||||
if (currentWallet) {
|
if (currentWallet) {
|
||||||
handler(!currentWallet.disconnected);
|
handler(!currentWallet.disconnected);
|
||||||
} else {
|
} else {
|
||||||
daemonManager.runningAsync(persistentSettings.nettype, handler);
|
daemonManager.runningAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ Rectangle {
|
||||||
startP2Pool()
|
startP2Pool()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
daemonManager.stopAsync(persistentSettings.nettype, startP2PoolLocal)
|
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, startP2PoolLocal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -254,7 +254,7 @@ Rectangle {
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
if(text.length > 0) {
|
if(text.length > 0) {
|
||||||
consoleArea.logCommand(">>> " + text)
|
consoleArea.logCommand(">>> " + text)
|
||||||
daemonManager.sendCommandAsync(text.split(" "), currentWallet.nettype, function(result) {
|
daemonManager.sendCommandAsync(text.split(" "), currentWallet.nettype, persistentSettings.blockchainDataDir, function(result) {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
appWindow.showStatusMessage(qsTr("Failed to send command"), 3);
|
appWindow.showStatusMessage(qsTr("Failed to send command"), 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start start watcher
|
// Start start watcher
|
||||||
m_scheduler.run([this, nettype, noSync] {
|
m_scheduler.run([this, nettype, dataDir, noSync] {
|
||||||
if (startWatcher(nettype)) {
|
if (startWatcher(nettype, dataDir)) {
|
||||||
emit daemonStarted();
|
emit daemonStarted();
|
||||||
m_noSync = noSync;
|
m_noSync = noSync;
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,13 +142,13 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonManager::stopAsync(NetworkType::Type nettype, const QJSValue& callback)
|
void DaemonManager::stopAsync(NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback)
|
||||||
{
|
{
|
||||||
const auto feature = m_scheduler.run([this, nettype] {
|
const auto feature = m_scheduler.run([this, nettype, dataDir] {
|
||||||
QString message;
|
QString message;
|
||||||
sendCommand({"exit"}, nettype, message);
|
sendCommand({"exit"}, nettype, dataDir, message);
|
||||||
|
|
||||||
return QJSValueList({stopWatcher(nettype)});
|
return QJSValueList({stopWatcher(nettype, dataDir)});
|
||||||
}, callback);
|
}, callback);
|
||||||
|
|
||||||
if (!feature.first)
|
if (!feature.first)
|
||||||
|
@ -157,14 +157,14 @@ void DaemonManager::stopAsync(NetworkType::Type nettype, const QJSValue& callbac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonManager::startWatcher(NetworkType::Type nettype) const
|
bool DaemonManager::startWatcher(NetworkType::Type nettype, const QString &dataDir) const
|
||||||
{
|
{
|
||||||
// Check if daemon is started every 2 seconds
|
// Check if daemon is started every 2 seconds
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) {
|
while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) {
|
||||||
QThread::sleep(2);
|
QThread::sleep(2);
|
||||||
if(!running(nettype)) {
|
if(!running(nettype, dataDir)) {
|
||||||
qDebug() << "daemon not running. checking again in 2 seconds.";
|
qDebug() << "daemon not running. checking again in 2 seconds.";
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "daemon is started. Waiting 5 seconds to let daemon catch up";
|
qDebug() << "daemon is started. Waiting 5 seconds to let daemon catch up";
|
||||||
|
@ -175,14 +175,14 @@ bool DaemonManager::startWatcher(NetworkType::Type nettype) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonManager::stopWatcher(NetworkType::Type nettype) const
|
bool DaemonManager::stopWatcher(NetworkType::Type nettype, const QString &dataDir) const
|
||||||
{
|
{
|
||||||
// Check if daemon is running every 2 seconds. Kill if still running after 10 seconds
|
// Check if daemon is running every 2 seconds. Kill if still running after 10 seconds
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while(true && !m_app_exit) {
|
while(true && !m_app_exit) {
|
||||||
QThread::sleep(2);
|
QThread::sleep(2);
|
||||||
counter++;
|
counter++;
|
||||||
if(running(nettype)) {
|
if(running(nettype, dataDir)) {
|
||||||
qDebug() << "Daemon still running. " << counter;
|
qDebug() << "Daemon still running. " << counter;
|
||||||
if(counter >= 5) {
|
if(counter >= 5) {
|
||||||
qDebug() << "Killing it! ";
|
qDebug() << "Killing it! ";
|
||||||
|
@ -236,10 +236,10 @@ void DaemonManager::printError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonManager::running(NetworkType::Type nettype) const
|
bool DaemonManager::running(NetworkType::Type nettype, const QString &dataDir) const
|
||||||
{
|
{
|
||||||
QString status;
|
QString status;
|
||||||
sendCommand({"sync_info"}, nettype, status);
|
sendCommand({"sync_info"}, nettype, dataDir, status);
|
||||||
qDebug() << status;
|
qDebug() << status;
|
||||||
return status.contains("Height:");
|
return status.contains("Height:");
|
||||||
}
|
}
|
||||||
|
@ -249,14 +249,14 @@ bool DaemonManager::noSync() const noexcept
|
||||||
return m_noSync;
|
return m_noSync;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonManager::runningAsync(NetworkType::Type nettype, const QJSValue& callback) const
|
void DaemonManager::runningAsync(NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback) const
|
||||||
{
|
{
|
||||||
m_scheduler.run([this, nettype] {
|
m_scheduler.run([this, nettype, dataDir] {
|
||||||
return QJSValueList({running(nettype)});
|
return QJSValueList({running(nettype, dataDir)});
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const
|
bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettype, const QString &dataDir, QString &message) const
|
||||||
{
|
{
|
||||||
QProcess p;
|
QProcess p;
|
||||||
QStringList external_cmd(cmd);
|
QStringList external_cmd(cmd);
|
||||||
|
@ -267,6 +267,11 @@ bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettyp
|
||||||
else if (nettype == NetworkType::STAGENET)
|
else if (nettype == NetworkType::STAGENET)
|
||||||
external_cmd << "--stagenet";
|
external_cmd << "--stagenet";
|
||||||
|
|
||||||
|
// Custom data-dir
|
||||||
|
if (!dataDir.isEmpty()) {
|
||||||
|
external_cmd << "--data-dir" << dataDir;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "sending external cmd: " << external_cmd;
|
qDebug() << "sending external cmd: " << external_cmd;
|
||||||
|
|
||||||
|
|
||||||
|
@ -278,11 +283,11 @@ bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettyp
|
||||||
return started;
|
return started;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonManager::sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const
|
void DaemonManager::sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback) const
|
||||||
{
|
{
|
||||||
m_scheduler.run([this, cmd, nettype] {
|
m_scheduler.run([this, cmd, nettype, dataDir] {
|
||||||
QString message;
|
QString message;
|
||||||
return QJSValueList({sendCommand(cmd, nettype, message)});
|
return QJSValueList({sendCommand(cmd, nettype, dataDir, message)});
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,23 +48,23 @@ public:
|
||||||
~DaemonManager();
|
~DaemonManager();
|
||||||
|
|
||||||
Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = "", bool noSync = false, bool pruneBlockchain = false);
|
Q_INVOKABLE bool start(const QString &flags, NetworkType::Type nettype, const QString &dataDir = "", const QString &bootstrapNodeAddress = "", bool noSync = false, bool pruneBlockchain = false);
|
||||||
Q_INVOKABLE void stopAsync(NetworkType::Type nettype, const QJSValue& callback);
|
Q_INVOKABLE void stopAsync(NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback);
|
||||||
|
|
||||||
Q_INVOKABLE bool noSync() const noexcept;
|
Q_INVOKABLE bool noSync() const noexcept;
|
||||||
// return true if daemon process is started
|
// return true if daemon process is started
|
||||||
Q_INVOKABLE void runningAsync(NetworkType::Type nettype, const QJSValue& callback) const;
|
Q_INVOKABLE void runningAsync(NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback) const;
|
||||||
// Send daemon command from qml and prints output in console window.
|
// Send daemon command from qml and prints output in console window.
|
||||||
Q_INVOKABLE void sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const;
|
Q_INVOKABLE void sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QString &dataDir, const QJSValue& callback) const;
|
||||||
Q_INVOKABLE void exit();
|
Q_INVOKABLE void exit();
|
||||||
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
|
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
|
||||||
Q_INVOKABLE bool checkLmdbExists(QString datadir);
|
Q_INVOKABLE bool checkLmdbExists(QString datadir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool running(NetworkType::Type nettype) const;
|
bool running(NetworkType::Type nettype, const QString &dataDir) const;
|
||||||
bool sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const;
|
bool sendCommand(const QStringList &cmd, NetworkType::Type nettype, const QString &dataDir, QString &message) const;
|
||||||
bool startWatcher(NetworkType::Type nettype) const;
|
bool startWatcher(NetworkType::Type nettype, const QString &dataDir) const;
|
||||||
bool stopWatcher(NetworkType::Type nettype) const;
|
bool stopWatcher(NetworkType::Type nettype, const QString &dataDir) const;
|
||||||
signals:
|
signals:
|
||||||
void daemonStarted() const;
|
void daemonStarted() const;
|
||||||
void daemonStopped() const;
|
void daemonStopped() const;
|
||||||
|
|
Loading…
Reference in a new issue