From 06c71afa4a9cd275900e0ae6c4ce4de14bd74d9d Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 9 Aug 2016 11:27:08 -0400 Subject: [PATCH] API CHANGE: Add a new "stopupdate" action for the sysadm/update class. (no additional inputs required). This will look for any currently-running pc-updatemanager processes and kill/stop them as needed. Example: { "id":"dummy", "namespace":"sysadm", "name":"update", "args": { "action":"stopupdate" } } Output arguments: "args":{ "stopupdate":{ "result":"success" or "error:" } } --- src/server/WebBackend.cpp | 4 ++++ src/server/library/sysadm-update.cpp | 24 ++++++++++++++++++++++++ src/server/library/sysadm-update.h | 3 +++ 3 files changed, 31 insertions(+) diff --git a/src/server/WebBackend.cpp b/src/server/WebBackend.cpp index 0280174..46ff23a 100644 --- a/src/server/WebBackend.cpp +++ b/src/server/WebBackend.cpp @@ -581,6 +581,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmUpdateRequest(const QJsonVal }else if(act=="startupdate"){ ok = true; out->insert("startupdate", sysadm::Update::startUpdate(in_args.toObject()) ); + + }else if(act=="stopupdate"){ + ok = true; + out->insert("stopupdate", sysadm::Update::stopUpdate() ); } } //end of "action" key usage diff --git a/src/server/library/sysadm-update.cpp b/src/server/library/sysadm-update.cpp index cdde30a..482284a 100644 --- a/src/server/library/sysadm-update.cpp +++ b/src/server/library/sysadm-update.cpp @@ -190,3 +190,27 @@ QJsonObject Update::startUpdate(QJsonObject jsin) { retObject.insert("queueid", ID); return retObject; } + +// Stop an update process +QJsonObject Update::stopUpdate() { + //See if the update is running in the dispatcher + QJsonObject ret; + QJsonObject cup = DISPATCHER->listJobs(); + QStringList ids = cup.keys().filter("sysadm_update_runupdates::"); + if(!ids.isEmpty()){ + //Found a dispatcher process - go ahead and request that it stop + DISPATCHER->killJobs(ids); + ret.insert("result","success"); + }else if( QFile::exists(UP_PIDFILE) ){ + //See if the process is actually running + if( General::RunQuickCommand(QString("pgrep -F ")+UP_PIDFILE) ){ + //Success if return code == 0 + int rtc = General::RunQuickCommand( QString("pkill -F ")+UP_PIDFILE ); + if(rtc==0){ ret.insert("result","success"); } + else{ ret.insert("result","error: could not kill update process"); } + } + }else{ + ret.insert("result","error: no update processes found"); + } + return ret; +} diff --git a/src/server/library/sysadm-update.h b/src/server/library/sysadm-update.h index 8f6ddb3..0dfbdee 100644 --- a/src/server/library/sysadm-update.h +++ b/src/server/library/sysadm-update.h @@ -16,7 +16,10 @@ class Update{ public: static QJsonObject checkUpdates(bool fast = false); static QJsonObject listBranches(); + //Start/stop update routine static QJsonObject startUpdate(QJsonObject); + static QJsonObject stopUpdate(); + }; } //end of pcbsd namespace