mirror of
https://github.com/oxen-io/lokinet-control-panel.git
synced 2023-12-14 05:53:00 +01:00
Use systemd for stopping lokinet, also some DRY
This commit is contained in:
parent
5fe01a510d
commit
560a0478e3
|
@ -65,6 +65,22 @@ bool LokinetProcessManager::stopLokinetProcess()
|
|||
qDebug("warning, lokinet process is already stopping, we'll try to stop again anyway");
|
||||
}
|
||||
|
||||
bool success = doStopLokinetProcess();
|
||||
if (not success)
|
||||
{
|
||||
qDebug() << "doStopLokinetProcess() failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
// note that we don't touch m_didLaunchProcess here because we don't
|
||||
// know whether or not lokinet will gracefully exit
|
||||
|
||||
setLastKnownStatus(ProcessStatus::Stopping);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LokinetProcessManager::doStopLokinetProcess()
|
||||
{
|
||||
bool success = m_apiClient.llarpAdminDie([](QNetworkReply* reply) {
|
||||
qDebug() << "llarp.admin.die response: " << reply->readAll();
|
||||
});
|
||||
|
@ -74,11 +90,7 @@ bool LokinetProcessManager::stopLokinetProcess()
|
|||
return false;
|
||||
}
|
||||
|
||||
// note that we don't touch m_didLaunchProcess here because we don't
|
||||
// know whether or not lokinet will gracefully exit
|
||||
|
||||
setLastKnownStatus(ProcessStatus::Stopping);
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool LokinetProcessManager::forciblyStopLokinetProcess()
|
||||
|
|
|
@ -138,6 +138,16 @@ protected:
|
|||
*/
|
||||
virtual bool doStartLokinetProcess() = 0;
|
||||
|
||||
/**
|
||||
* Subclasses may provide platform-specific means of stopping the
|
||||
* lokinet process. Note, however, that this has an "intelligent default"
|
||||
* which will use the 'llarp.admin.die' API call, which should cause
|
||||
* lokinet to gracefully exit.
|
||||
*
|
||||
* @return true on successful request to stop, false otherwise
|
||||
*/
|
||||
virtual bool doStopLokinetProcess();
|
||||
|
||||
/**
|
||||
* Subclasses should provide platform-specific means of forcibly stopping
|
||||
* the lokinet process.
|
||||
|
|
|
@ -26,32 +26,36 @@ SystemdStatus fromString(const QString& str) {
|
|||
return SystemdStatus::unknown;
|
||||
}
|
||||
|
||||
bool SystemdLokinetProcessManager::doStartLokinetProcess()
|
||||
bool invoke(const QString& cmd, const QStringList& args)
|
||||
{
|
||||
QStringList args = { "--noblock", "start", "lokinet.service" };
|
||||
int result = QProcess::execute("systemctl", args);
|
||||
int result = QProcess::execute(cmd, args);
|
||||
if (result)
|
||||
{
|
||||
qDebug("Failed to 'systemctl start lokinet': %d", result);
|
||||
qDebug() << "Failed to invoke " << cmd;
|
||||
qDebug() << " Args:";
|
||||
for (const auto arg : args)
|
||||
{
|
||||
qDebug() << " " << arg;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemdLokinetProcessManager::doStopLokinetProcess()
|
||||
{
|
||||
return invoke("systemctl", { "--no-block", "stop", "lokinet.service" });
|
||||
}
|
||||
|
||||
bool SystemdLokinetProcessManager::doStartLokinetProcess()
|
||||
{
|
||||
return invoke("systemctl", { "--no-block", "start", "lokinet.service" });
|
||||
}
|
||||
|
||||
bool SystemdLokinetProcessManager::doForciblyStopLokinetProcess()
|
||||
{
|
||||
// note that this will do its own graceful attempt before doing a forceful kill.
|
||||
// "kill" instead of "stop" should perform an immediate, forceful kill
|
||||
QStringList args = { "stop", "lokinet.service" };
|
||||
int result = QProcess::execute("systemctl", args);
|
||||
if (result)
|
||||
{
|
||||
qDebug("Failed to 'systemctl stop lokinet': %d", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return invoke("systemctl", { "--noblock", "kill", "lokinet.service" });
|
||||
}
|
||||
|
||||
bool SystemdLokinetProcessManager::doGetProcessPid(int& pid)
|
||||
|
|
|
@ -15,6 +15,7 @@ class SystemdLokinetProcessManager : public LokinetProcessManager
|
|||
|
||||
protected:
|
||||
|
||||
bool doStopLokinetProcess() override;
|
||||
bool doStartLokinetProcess() override;
|
||||
bool doForciblyStopLokinetProcess() override;
|
||||
bool doGetProcessPid(int& pid) override;
|
||||
|
|
Loading…
Reference in a new issue