p2pool: Restart monerod only when needed and with proper args

This commit is contained in:
devhyper 2023-01-31 18:23:20 -08:00
parent b7ba9437d8
commit 757bc7d7b9
No known key found for this signature in database
GPG key ID: D5F749908AE9DA70
4 changed files with 127 additions and 8 deletions

View file

@ -748,6 +748,12 @@ ApplicationWindow {
currentWallet.startRefresh();
informationPopup.title = qsTr("Daemon failed to start") + translationManager.emptyString;
informationPopup.text = error + ".\n\n" + qsTr("Please check your wallet and daemon log for errors. You can also try to start %1 manually.").arg((isWindows)? "monerod.exe" : "monerod")
if (middlePanel.advancedView.miningView.stopMiningEnabled == true) {
walletManager.stopMining()
p2poolManager.exit()
middlePanel.advancedView.miningView.update()
informationPopup.text += qsTr("\n\nExiting p2pool. Please check that port 18083 is available.") + translationManager.emptyString;
}
informationPopup.icon = StandardIcon.Critical
informationPopup.onCloseCallback = null
informationPopup.open();

View file

@ -41,7 +41,8 @@ Rectangle {
property alias miningHeight: mainLayout.height
property double currentHashRate: 0
property int threads: idealThreadCount / 2
property alias stopMiningEnabled: stopSoloMinerButton.enabled
property string args: ""
ColumnLayout {
id: mainLayout
Layout.fillWidth: true
@ -293,13 +294,20 @@ Rectangle {
var success;
if (persistentSettings.allow_p2pool_mining) {
if (p2poolManager.isInstalled()) {
if (persistentSettings.allowRemoteNodeMining) {
args = daemonManager.getArgs(persistentSettings.blockchainDataDir) //updates arguments
if (persistentSettings.allowRemoteNodeMining || (args.includes("--zmq-pub tcp://127.0.0.1:18083") || args.includes("--zmq-pub=tcp://127.0.0.1:18083")) && !args.includes("--no-zmq")) {
startP2Pool()
}
else {
var underSystemd = daemonManager.checkUnderSystemd();
if (underSystemd) {
miningError(qsTr("Monerod is managed by Systemd. Manually add --zmq-pub tcp://127.0.0.1:18083 to the unit file <br>") + translationManager.emptyString)
}
else {
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, startP2PoolLocal)
}
}
}
else {
confirmationDialog.title = qsTr("P2Pool installation") + translationManager.emptyString;
confirmationDialog.text = qsTr("P2Pool will be installed at %1. Proceed?").arg(applicationDirectory) + translationManager.emptyString;
@ -585,12 +593,35 @@ Rectangle {
function startP2PoolLocal() {
var noSync = false;
var customDaemonArgs = persistentSettings.daemonFlags.toLowerCase();
var daemonArgs = "--zmq-pub " + "tcp://127.0.0.1:18083 " + "--disable-dns-checkpoints "
if (!customDaemonArgs.includes("--zmq-pub") && !customDaemonArgs.includes("--disable-dns-checkpoints") && !customDaemonArgs.includes("--no-zmq")) {
daemonArgs = daemonArgs + customDaemonArgs;
//these args will be deleted because DaemonManager::start will re-add them later.
//--no-zmq must be deleted. removing '--zmq-pub=tcp...' lets us blindly add '--zmq-pub tcp...' later without risking duplication.
var defaultArgs = ["--detach","--data-dir","--bootstrap-daemon-address","--prune-blockchain","--no-sync","--check-updates","--non-interactive","--max-concurrency","--no-zmq","--zmq-pub=tcp://127.0.0.1:18083"]
var customDaemonArgsArray = args.split(' ');
var flag = "";
var allArgs = [];
var p2poolArgs = ["--zmq-pub tcp://127.0.0.1:18083"];
//create an array (allArgs) of ['--arg value','--arg2','--arg3']
for (let i = 0; i < customDaemonArgsArray.length; i++) {
if(!customDaemonArgsArray[i].startsWith("--")) {
flag += " " + customDaemonArgsArray[i]
} else {
if(flag){
allArgs.push(flag)
}
var success = daemonManager.start(daemonArgs, persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain)
flag = customDaemonArgsArray[i]
}
}
allArgs.push(flag)
//pop from allArgs if value is inside the deleteme array (defaultArgs)
allArgs = allArgs.filter( ( el ) => !defaultArgs.includes( el.split(" ")[0] ) )
//append required p2pool flags
for (let i = 0; i < p2poolArgs.length; i++) {
if(!allArgs.includes(p2poolArgs[i])) {
allArgs.push(p2poolArgs[i])
continue
}
}
var success = daemonManager.start(allArgs.join(" "), persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain)
if (success) {
startP2Pool()
}

View file

@ -342,6 +342,85 @@ bool DaemonManager::checkLmdbExists(QString datadir) {
return validateDataDir(datadir).value("lmdbExists").value<bool>();
}
bool DaemonManager::checkUnderSystemd() {
#ifdef Q_OS_LINUX
QProcess p;
QStringList args;
args << "monerod";
p.setProgram("pgrep");
p.setArguments(args);
p.start();
p.waitForFinished();
QString pid = p.readAllStandardOutput().trimmed();
if (pid.isEmpty()) {
return false;
}
args.clear();
args << "-c";
args << "ps -eo pid,cgroup | grep " + pid + " | grep -q .service$";
p.setProgram("sh");
p.setArguments(args);
p.start();
p.waitForFinished();
if (p.exitCode() == 0) {
return true;
}
#endif
return false;
}
QString DaemonManager::getArgs(const QString &dataDir) {
if (!running(NetworkType::MAINNET, dataDir)) {
return args;
}
QProcess p;
QStringList tempArgs;
#ifdef Q_OS_WIN
//powershell
tempArgs << "Get-CimInstance Win32_Process -Filter \"name = 'monerod.exe'\" | select -ExpandProperty CommandLine ";
p.setProgram("powershell");
p.setArguments(tempArgs);
p.start();
p.waitForFinished();
args = p.readAllStandardOutput().simplified().trimmed();
#elif defined(Q_OS_UNIX)
//pgrep
tempArgs << "monerod";
p.setProgram("pgrep");
p.setArguments(tempArgs);
p.start();
p.waitForFinished();
QString pid = p.readAllStandardOutput().trimmed();
if (pid.isEmpty()) {
return args;
}
tempArgs.clear();
//ps
tempArgs << "-o";
tempArgs << "args=";
tempArgs << "-fp";
tempArgs << pid;
p.setProgram("ps");
p.setArguments(tempArgs);
p.start();
p.waitForFinished();
args = p.readAllStandardOutput().trimmed();
#endif
if (args.contains("--")) {
int index = args.indexOf("--");
args.remove(0, index);
}
else {
args = "";
}
return args;
}
DaemonManager::DaemonManager(QObject *parent)
: QObject(parent)
, m_scheduler(this)

View file

@ -58,6 +58,8 @@ public:
Q_INVOKABLE void exit();
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
Q_INVOKABLE bool checkLmdbExists(QString datadir);
Q_INVOKABLE QString getArgs(const QString &dataDir);
Q_INVOKABLE bool checkUnderSystemd();
private:
@ -82,6 +84,7 @@ private:
QString m_monerod;
bool m_app_exit = false;
bool m_noSync = false;
QString args = "";
mutable FutureScheduler m_scheduler;
};