2018-08-13 Fred Gleason <fredg@paravelsystems.com>

* Moved execution of maintenance routines from ripcd(8) to
	rdservice(8).
This commit is contained in:
Fred Gleason
2018-08-13 16:27:12 -04:00
parent ae9296352c
commit 16661cfb6d
9 changed files with 154 additions and 119 deletions

View File

@@ -57,7 +57,7 @@ dist_ripcd_SOURCES = acu1p.cpp acu1p.h\
livewire_mcastgpio.cpp livewire_mcastgpio.h\
local_audio.cpp local_audio.h\
local_gpio.cpp local_gpio.h\
local_macros.cpp maint_routines.cpp\
local_macros.cpp\
loaddrivers.cpp\
modbus.cpp modbus.h\
modemlines.cpp modemlines.h\

View File

@@ -1,54 +0,0 @@
// ripcd.cpp
//
// Rivendell Maintenance Routines
//
// (C) Copyright 2008,2016 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 <ripcd.h>
void MainObject::RunSystemMaintRoutine()
{
if(fork()==0) {
system("rdmaint --system");
system("rdpurgecasts");
exit(0);
}
LogLine(RDConfig::LogInfo,"ran system-wide maintenance routines");
}
void MainObject::RunLocalMaintRoutine()
{
if(fork()==0) {
system("rdmaint");
exit(0);
}
LogLine(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);
}

View File

@@ -180,20 +180,6 @@ MainObject::MainObject(QObject *parent)
connect(ripcd_backup_timer,SIGNAL(timeout()),this,SLOT(databaseBackup()));
ripcd_backup_timer->start(86400000);
//
// Maintenance Routine Timer
//
srandom(QTime::currentTime().msec());
ripcd_maint_timer=new QTimer(this);
connect(ripcd_maint_timer,SIGNAL(timeout()),this,SLOT(checkMaintData()));
int interval=GetMaintInterval();
if(!rda->config()->disableMaintChecks()) {
ripcd_maint_timer->start(interval);
}
else {
log(RDConfig::LogInfo,"maintenance checks disabled on this host!");
}
//
// Exit Timer
//
@@ -371,49 +357,6 @@ void MainObject::killData(int conn_id)
}
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::macroTimerData(int num)
{
ExecCart(ripc_macro_cart[num]);

View File

@@ -78,7 +78,6 @@ class MainObject : public QObject
void macroTimerData(int num);
void readyReadData(int conn_id);
void killData(int conn_id);
void checkMaintData();
void exitTimerData();
void garbageData();
@@ -100,9 +99,6 @@ class MainObject : public QObject
void SendGpoMask(int ch,int matrix);
void SendGpiCart(int ch,int matrix);
void SendGpoCart(int ch,int matrix);
void RunSystemMaintRoutine();
void RunLocalMaintRoutine();
int GetMaintInterval() const;
RDMacro ForwardConvert(const RDMacro &rml) const;
bool LoadSwitchDriver(int matrix_num);
QSqlDatabase *ripcd_db;
@@ -133,7 +129,6 @@ class MainObject : public QObject
bool ripc_onair_flag;
QTimer *ripc_macro_timer[RD_MAX_MACRO_TIMERS];
unsigned ripc_macro_cart[RD_MAX_MACRO_TIMERS];
QTimer *ripcd_maint_timer;
RDMulticaster *ripcd_notification_mcaster;
QTimer *ripcd_garbage_timer;
};