mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2026-01-11 23:25:57 +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:
@@ -31,7 +31,8 @@ moc_%.cpp: %.h
|
||||
|
||||
sbin_PROGRAMS = rdservice
|
||||
|
||||
dist_rdservice_SOURCES = process.cpp process.h\
|
||||
dist_rdservice_SOURCES = maint_routines.cpp\
|
||||
process.cpp process.h\
|
||||
rdservice.cpp rdservice.h\
|
||||
shutdown.cpp\
|
||||
startup.cpp
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,21 @@ MainObject::MainObject(QObject *parent)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Maintenance Routine Timer
|
||||
//
|
||||
srandom(QTime::currentTime().msec());
|
||||
svc_maint_timer=new QTimer(this);
|
||||
svc_maint_timer->setSingleShot(true);
|
||||
connect(svc_maint_timer,SIGNAL(timeout()),this,SLOT(checkMaintData()));
|
||||
int interval=GetMaintInterval();
|
||||
if(!rda->config()->disableMaintChecks()) {
|
||||
svc_maint_timer->start(interval);
|
||||
}
|
||||
else {
|
||||
rda->log(RDConfig::LogInfo,"maintenance checks disabled on this host!");
|
||||
}
|
||||
|
||||
if(!RDWritePid(RD_PID_DIR,"rdservice.pid",getuid())) {
|
||||
fprintf(stderr,"rdservice: can't write pid file\n");
|
||||
}
|
||||
@@ -97,6 +112,8 @@ MainObject::MainObject(QObject *parent)
|
||||
|
||||
void MainObject::processFinishedData(int id)
|
||||
{
|
||||
svc_processes[id]->deleteLater();
|
||||
svc_processes.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,10 @@
|
||||
#define RDSERVICE_RDCATCHD_ID 2
|
||||
#define RDSERVICE_RDVAIRPLAYD_ID 3
|
||||
#define RDSERVICE_RDREPLD_ID 4
|
||||
#define RDSERVICE_LAST_ID 5
|
||||
#define RDSERVICE_LOCALMAINT_ID 5
|
||||
#define RDSERVICE_SYSTEMMAINT_ID 6
|
||||
#define RDSERVICE_PURGECASTS_ID 7
|
||||
#define RDSERVICE_LAST_ID 8
|
||||
#define RDSERVICE_FIRST_DROPBOX_ID 100
|
||||
|
||||
class MainObject : public QObject
|
||||
@@ -44,6 +47,7 @@ class MainObject : public QObject
|
||||
|
||||
private slots:
|
||||
void processFinishedData(int id);
|
||||
void checkMaintData();
|
||||
void exitData();
|
||||
|
||||
private:
|
||||
@@ -52,7 +56,13 @@ class MainObject : public QObject
|
||||
void KillProgram(const QString &program);
|
||||
void Shutdown();
|
||||
void ShutdownDropboxes();
|
||||
void RunSystemMaintRoutine();
|
||||
void RunLocalMaintRoutine();
|
||||
int GetMaintInterval() const;
|
||||
void RunEphemeralProcess(int id,const QString &program,
|
||||
const QStringList &args);
|
||||
QMap<int,Process *> svc_processes;
|
||||
QTimer *svc_maint_timer;
|
||||
QTimer *svc_exit_timer;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user