mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add a new setting to the update manager specifically for SysAdm:
"auto_update_reboot" = "0"-"23" (hour of the day) If this is set (to a valid number), then SysAdm will automatically reboot the system to finish performing updates at the specified hour. Any other setting (or the value not being set) disables this option.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "library/sysadm-general.h"
|
||||
#include "library/sysadm-zfs.h"
|
||||
#include "library/sysadm-update.h"
|
||||
#include "library/sysadm-systemmanager.h"
|
||||
|
||||
// === PUBLIC ===
|
||||
EventWatcher::EventWatcher(){
|
||||
@@ -370,8 +371,23 @@ void EventWatcher::CheckSystemState(){
|
||||
if(!updates.isEmpty()){
|
||||
if(updates.value("status").toString()!="noupdates"){
|
||||
int tmp = 2;
|
||||
if(updates.value("status").toString()=="rebootrequired"){ tmp = 9; } //user input required
|
||||
else if(updates.value("status").toString()!="updaterunning"){
|
||||
if(updates.value("status").toString()=="rebootrequired"){
|
||||
tmp = 9; //user input required
|
||||
//Check if the auto_update_reboot flag is set, and reboot as needed
|
||||
QJsonObject upset = sysadm::Update::readSettings();
|
||||
if(upset.contains("auto_update_reboot")){
|
||||
bool ok = false;
|
||||
int hour = upset.value("auto_update_reboot").toString().toInt(&ok);
|
||||
if(ok){ //got a valid number
|
||||
//Check if that time has recently happened
|
||||
QDateTime finished = sysadm::Update::rebootRequiredSince();
|
||||
QDateTime cdt = QDateTime::currentDateTime();
|
||||
if( (finished.addSecs(60*60*24)<cdt) || cdt.time().hour() == hour){ //more than 24 hours have passed, or time has come
|
||||
sysadm::SysMgmt::systemReboot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(updates.value("status").toString()!="updaterunning"){
|
||||
//updates are available - see if the auto-update flag is set, and start the updates as needed
|
||||
QJsonObject upset = sysadm::Update::readSettings();
|
||||
QDateTime last = sysadm::Update::lastFullCheck().addSecs(60); //wait one interval before starting auto-updates (15 min intervals usually)
|
||||
|
||||
@@ -25,6 +25,11 @@ QDateTime Update::lastFullCheck(){
|
||||
return QFileInfo(UP_UPFILE).lastModified();
|
||||
}
|
||||
|
||||
QDateTime Update::rebootRequiredSince(){
|
||||
if(!QFile::exists(UP_RBFILE)){ return QDateTime(); } //null time - no file exists
|
||||
return QFileInfo(UP_RBFILE).lastModified();
|
||||
}
|
||||
|
||||
// Return a list of updates available
|
||||
QJsonObject Update::checkUpdates(bool fast) {
|
||||
//NOTE: The "fast" option should only be used for automated/timed checks (to prevent doing this long check too frequently)
|
||||
@@ -243,7 +248,7 @@ QJsonObject Update::stopUpdate() {
|
||||
QJsonObject Update::readSettings(){
|
||||
QJsonObject ret;
|
||||
QStringList knownsettings;
|
||||
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE";// << "CDN_TYPE";
|
||||
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE" << "AUTO_UPDATE_REBOOT";// << "CDN_TYPE";
|
||||
|
||||
QStringList info = General::readTextFile(UP_CONFFILE);
|
||||
for(int i=0; i<info.length(); i++){
|
||||
@@ -261,7 +266,7 @@ QJsonObject Update::writeSettings(QJsonObject obj){
|
||||
QJsonObject ret;
|
||||
//Check inputs
|
||||
QStringList knownsettings;
|
||||
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE";// << "CDN_TYPE";
|
||||
knownsettings << "PACKAGE_SET" << "PACKAGE_URL" << "AUTO_UPDATE" << "MAXBE" << "AUTO_UPDATE_REBOOT";// << "CDN_TYPE";
|
||||
QStringList keys = obj.keys();
|
||||
QStringList vals;
|
||||
bool clearlastCheck = false;
|
||||
|
||||
@@ -14,7 +14,10 @@ namespace sysadm{
|
||||
|
||||
class Update{
|
||||
public:
|
||||
//Time stamps
|
||||
static QDateTime lastFullCheck();
|
||||
static QDateTime rebootRequiredSince();
|
||||
//Listing routines
|
||||
static QJsonObject checkUpdates(bool fast = false);
|
||||
static QJsonObject listBranches();
|
||||
//Start/stop update routine
|
||||
|
||||
Reference in New Issue
Block a user