mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-11-26 07:10:11 +01:00
2018-08-13 Fred Gleason <fredg@paravelsystems.com>
* Moved execution of maintenance routines from ripcd(8) to rdservice(8).
This commit is contained in:
120
rdservice/maint_routines.cpp
Normal file
120
rdservice/maint_routines.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// main_routines.cpp
|
||||
//
|
||||
// Rivendell Maintenance Routines
|
||||
//
|
||||
// (C) Copyright 2008-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdapplication.h>
|
||||
#include <rdpaths.h>
|
||||
|
||||
#include "rdservice.h"
|
||||
|
||||
void MainObject::checkMaintData()
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
QDateTime current_datetime=
|
||||
QDateTime(QDate::currentDate(),QTime::currentTime());
|
||||
bool run=false;
|
||||
|
||||
RunLocalMaintRoutine();
|
||||
|
||||
//
|
||||
// Should we try to run system maintenance?
|
||||
//
|
||||
if(!rda->station()->systemMaint()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Get the system-wide maintenance timestamp
|
||||
//
|
||||
sql="lock tables VERSION write";
|
||||
q=new RDSqlQuery(sql);
|
||||
delete q;
|
||||
sql="select LAST_MAINT_DATETIME from VERSION";
|
||||
q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
run=1000*q->value(0).toDateTime().secsTo(current_datetime)>
|
||||
RD_MAINT_MAX_INTERVAL;
|
||||
}
|
||||
delete q;
|
||||
sql="unlock tables";
|
||||
q=new RDSqlQuery(sql);
|
||||
delete q;
|
||||
|
||||
//
|
||||
// Run the routines
|
||||
//
|
||||
if(run) {
|
||||
RunSystemMaintRoutine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainObject::RunSystemMaintRoutine()
|
||||
{
|
||||
QStringList args;
|
||||
|
||||
args.clear();
|
||||
args.push_back("--system");
|
||||
RunEphemeralProcess(RDSERVICE_SYSTEMMAINT_ID,
|
||||
QString(RD_PREFIX)+"/bin/rdmaint",args);
|
||||
|
||||
args.clear();
|
||||
RunEphemeralProcess(RDSERVICE_PURGECASTS_ID,
|
||||
QString(RD_PREFIX)+"/bin/rdpurgecasts",args);
|
||||
|
||||
rda->log(RDConfig::LogInfo,"ran system-wide maintenance routines");
|
||||
}
|
||||
|
||||
|
||||
void MainObject::RunLocalMaintRoutine()
|
||||
{
|
||||
RunEphemeralProcess(RDSERVICE_SYSTEMMAINT_ID,
|
||||
QString(RD_PREFIX)+"/bin/rdmaint",QStringList());
|
||||
|
||||
rda->log(RDConfig::LogInfo,"ran local maintenance routines");
|
||||
}
|
||||
|
||||
|
||||
int MainObject::GetMaintInterval() const
|
||||
{
|
||||
return (int)(RD_MAINT_MIN_INTERVAL+
|
||||
(RD_MAINT_MAX_INTERVAL-RD_MAINT_MIN_INTERVAL)*
|
||||
(double)random()/(double)RAND_MAX);
|
||||
}
|
||||
|
||||
|
||||
void MainObject::RunEphemeralProcess(int id,const QString &program,
|
||||
const QStringList &args)
|
||||
{
|
||||
svc_processes[id]=new Process(id,this);
|
||||
connect(svc_processes[id],SIGNAL(finished(int)),
|
||||
this,SLOT(processFinishedData(int)));
|
||||
svc_processes[id]->start(program,args);
|
||||
if(!svc_processes[id]->process()->waitForStarted()) {
|
||||
QString err_msg=tr("unable to start")+"\""+program+"\": "+
|
||||
svc_processes[id]->errorText();
|
||||
rda->log(RDConfig::LogWarning,err_msg);
|
||||
delete svc_processes[id];
|
||||
svc_processes.remove(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user