mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-10 16:43:35 +02:00
2018-08-10 Fred Gleason <fredg@paravelsystems.com>
* Changed installation location of caed(8), ripcd(8), rdcatchd(8) and rdrepld(8) from '@prefix@/bin' to '@prefix@/sbin'. * Removed code to detach from controlling terminal after startup from caed(8), ripcd(8), rdcatchd(8) and rdrepld(8). * Removed code to manage dropbox instances from rdcatchd(8). * Removed code to start service daemons automatically from user modules. * Added rdservice(8).
This commit is contained in:
48
rdservice/Makefile.am
Normal file
48
rdservice/Makefile.am
Normal file
@@ -0,0 +1,48 @@
|
||||
## Makefile.am
|
||||
##
|
||||
## Rivendell Services Manager
|
||||
##
|
||||
## (C) Copyright 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.
|
||||
##
|
||||
##
|
||||
## Use automake to process this into a Makefile.in
|
||||
|
||||
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -I$(top_srcdir)/lib @QT4_CFLAGS@ -I/usr/include/Qt3Support
|
||||
LIBS = -L$(top_srcdir)/lib
|
||||
MOC = @QT_MOC@
|
||||
|
||||
# The dependency for qt's Meta Object Compiler (moc)
|
||||
moc_%.cpp: %.h
|
||||
$(MOC) $< -o $@
|
||||
|
||||
|
||||
sbin_PROGRAMS = rdservice
|
||||
|
||||
dist_rdservice_SOURCES = process.cpp process.h\
|
||||
rdservice.cpp rdservice.h\
|
||||
shutdown.cpp\
|
||||
startup.cpp
|
||||
|
||||
nodist_rdservice_SOURCES = moc_process.cpp\
|
||||
moc_rdservice.cpp
|
||||
|
||||
rdservice_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT4_LIBS@ -lQt3Support
|
||||
|
||||
CLEANFILES = *~\
|
||||
moc_*
|
||||
|
||||
MAINTAINERCLEANFILES = *~\
|
||||
Makefile.in
|
102
rdservice/process.cpp
Normal file
102
rdservice/process.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
// process.cpp
|
||||
//
|
||||
// Process container for the Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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 <qfile.h>
|
||||
|
||||
#include "process.h"
|
||||
|
||||
Process::Process(int id,QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
p_id=id;
|
||||
p_process=new QProcess(this);
|
||||
connect(p_process,SIGNAL(started()),this,SLOT(startedData()));
|
||||
connect(p_process,SIGNAL(finished(int,QProcess::ExitStatus)),
|
||||
this,SLOT(finishedData(int,QProcess::ExitStatus)));
|
||||
}
|
||||
|
||||
|
||||
Process::~Process()
|
||||
{
|
||||
delete p_process;
|
||||
}
|
||||
|
||||
|
||||
QProcess *Process::process() const
|
||||
{
|
||||
return p_process;
|
||||
}
|
||||
|
||||
|
||||
QString Process::program() const
|
||||
{
|
||||
return p_program;
|
||||
}
|
||||
|
||||
|
||||
QStringList Process::arguments() const
|
||||
{
|
||||
return p_arguments;
|
||||
}
|
||||
|
||||
|
||||
void Process::start(const QString &program,const QStringList &args)
|
||||
{
|
||||
p_program=program;
|
||||
p_arguments=args;
|
||||
|
||||
QFile file(p_program);
|
||||
if(!file.exists()) {
|
||||
p_error_text=tr("no such program")+" \""+p_program+"\"";
|
||||
}
|
||||
|
||||
p_process->start(program,args);
|
||||
}
|
||||
|
||||
|
||||
QString Process::errorText() const
|
||||
{
|
||||
return p_error_text;
|
||||
}
|
||||
|
||||
|
||||
void Process::startedData()
|
||||
{
|
||||
emit started(p_id);
|
||||
}
|
||||
|
||||
|
||||
void Process::finishedData(int exit_code,QProcess::ExitStatus status)
|
||||
{
|
||||
p_error_text=tr("ok");
|
||||
|
||||
if(status==QProcess::CrashExit) {
|
||||
p_error_text=tr("process crashed");
|
||||
}
|
||||
else {
|
||||
if(exit_code!=0) {
|
||||
p_error_text=tr("process returned exit code")+
|
||||
QString().sprintf(" %d ",exit_code)+
|
||||
"["+p_process->readAllStandardError()+"]";
|
||||
}
|
||||
}
|
||||
|
||||
emit finished(p_id);
|
||||
}
|
56
rdservice/process.h
Normal file
56
rdservice/process.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// process.h
|
||||
//
|
||||
// Process container for the Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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.
|
||||
//
|
||||
|
||||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qprocess.h>
|
||||
|
||||
class Process : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
public:
|
||||
Process(int id,QObject *parent=0);
|
||||
~Process();
|
||||
QProcess *process() const;
|
||||
QString program() const;
|
||||
QStringList arguments() const;
|
||||
void start(const QString &program,const QStringList &args);
|
||||
QString errorText() const;
|
||||
|
||||
signals:
|
||||
void started(int id);
|
||||
void finished(int id);
|
||||
|
||||
private slots:
|
||||
void startedData();
|
||||
void finishedData(int exit_code,QProcess::ExitStatus status);
|
||||
|
||||
private:
|
||||
int p_id;
|
||||
QString p_program;
|
||||
QStringList p_arguments;
|
||||
QProcess *p_process;
|
||||
QString p_error_text;
|
||||
};
|
||||
|
||||
|
||||
#endif // PROCESS_H
|
127
rdservice/rdservice.cpp
Normal file
127
rdservice/rdservice.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
// rdservice.cpp
|
||||
//
|
||||
// Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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 <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <qcoreapplication.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdapplication.h>
|
||||
#include <rdcmd_switch.h>
|
||||
#include <rdconf.h>
|
||||
|
||||
#include "rdservice.h"
|
||||
|
||||
bool global_exiting=false;
|
||||
bool global_reload_dropboxes=false;
|
||||
|
||||
void SigHandler(int signo)
|
||||
{
|
||||
switch(signo) {
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
global_exiting=true;
|
||||
break;
|
||||
|
||||
case SIGUSR1:
|
||||
global_reload_dropboxes=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
QString err_msg;
|
||||
|
||||
//
|
||||
// Check for prior instance
|
||||
//
|
||||
if(RDGetPids("rdservice").size()>1) {
|
||||
fprintf(stderr,"rdservice: prior instance found\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Open the Database
|
||||
//
|
||||
rda=new RDApplication("rdservice","rdservice","\n\n",this);
|
||||
if(!rda->open(&err_msg)) {
|
||||
fprintf(stderr,"rdservice: %s\n",(const char *)err_msg.utf8());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Exit Timer
|
||||
//
|
||||
::signal(SIGINT,SigHandler);
|
||||
::signal(SIGTERM,SigHandler);
|
||||
::signal(SIGUSR1,SigHandler);
|
||||
svc_exit_timer=new QTimer(this);
|
||||
connect(svc_exit_timer,SIGNAL(timeout()),this,SLOT(exitData()));
|
||||
svc_exit_timer->start(100);
|
||||
|
||||
if(!Startup(&err_msg)) {
|
||||
Shutdown();
|
||||
fprintf(stderr,"rdservice: %s\n",(const char *)err_msg.toUtf8());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(!RDWritePid(RD_PID_DIR,"rdservice.pid",getuid())) {
|
||||
fprintf(stderr,"rdservice: can't write pid file\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainObject::processFinishedData(int id)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MainObject::exitData()
|
||||
{
|
||||
QString err_msg;
|
||||
|
||||
if(global_exiting) {
|
||||
Shutdown();
|
||||
RDDeletePid(RD_PID_DIR,"rdservice.pid");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(global_reload_dropboxes) {
|
||||
ShutdownDropboxes();
|
||||
StartDropboxes(&err_msg);
|
||||
::signal(SIGUSR1,SigHandler);
|
||||
global_reload_dropboxes=false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc,argv);
|
||||
new MainObject();
|
||||
return a.exec();
|
||||
}
|
60
rdservice/rdservice.h
Normal file
60
rdservice/rdservice.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// rdservice.h
|
||||
//
|
||||
// Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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.
|
||||
//
|
||||
|
||||
#ifndef RDSERVICE_H
|
||||
#define RDSERVICE_H
|
||||
|
||||
#include <qmap.h>
|
||||
#include <qobject.h>
|
||||
#include <qprocess.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
#include "process.h"
|
||||
|
||||
#define RDSERVICE_CAED_ID 0
|
||||
#define RDSERVICE_RIPCD_ID 1
|
||||
#define RDSERVICE_RDCATCHD_ID 2
|
||||
#define RDSERVICE_RDVAIRPLAYD_ID 3
|
||||
#define RDSERVICE_RDREPLD_ID 4
|
||||
#define RDSERVICE_LAST_ID 5
|
||||
#define RDSERVICE_FIRST_DROPBOX_ID 100
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
public:
|
||||
MainObject(QObject *parent=0);
|
||||
|
||||
private slots:
|
||||
void processFinishedData(int id);
|
||||
void exitData();
|
||||
|
||||
private:
|
||||
bool Startup(QString *err_msg);
|
||||
bool StartDropboxes(QString *err_msg);
|
||||
void KillProgram(const QString &program);
|
||||
void Shutdown();
|
||||
void ShutdownDropboxes();
|
||||
QMap<int,Process *> svc_processes;
|
||||
QTimer *svc_exit_timer;
|
||||
};
|
||||
|
||||
|
||||
#endif // RDSERVICE_H
|
54
rdservice/shutdown.cpp
Normal file
54
rdservice/shutdown.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// shutdown.cpp
|
||||
//
|
||||
// Shutdown routines for the Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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 "rdservice.h"
|
||||
|
||||
void MainObject::Shutdown()
|
||||
{
|
||||
ShutdownDropboxes();
|
||||
|
||||
//
|
||||
// Rivendell Daemons
|
||||
//
|
||||
for(int i=RDSERVICE_LAST_ID-1;i>=0;i--) {
|
||||
if(svc_processes[i]!=NULL) {
|
||||
svc_processes[i]->process()->terminate();
|
||||
if(!svc_processes[i]->process()->waitForFinished()) {
|
||||
svc_processes[i]->process()->kill();
|
||||
}
|
||||
}
|
||||
delete svc_processes[i];
|
||||
svc_processes.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainObject::ShutdownDropboxes()
|
||||
{
|
||||
for(QMap<int,Process *>::iterator it=svc_processes.begin();
|
||||
it!=svc_processes.end();it++) {
|
||||
if(it.key()>=RDSERVICE_FIRST_DROPBOX_ID) {
|
||||
it.value()->process()->kill();
|
||||
it.value()->process()->waitForFinished();
|
||||
delete it.value();
|
||||
svc_processes.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
333
rdservice/startup.cpp
Normal file
333
rdservice/startup.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
// startup.cpp
|
||||
//
|
||||
// Startup routines for the Rivendell Services Manager
|
||||
//
|
||||
// (C) Copyright 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 <stdio.h>
|
||||
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <rdapplication.h>
|
||||
#include <rdconf.h>
|
||||
#include <rdescape_string.h>
|
||||
#include <rdpaths.h>
|
||||
|
||||
#include "rdservice.h"
|
||||
|
||||
bool MainObject::Startup(QString *err_msg)
|
||||
{
|
||||
QStringList args;
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
|
||||
//
|
||||
// Kill Stale Programs
|
||||
//
|
||||
KillProgram("rdrepld");
|
||||
KillProgram("rdvairplayd");
|
||||
KillProgram("rdcatchd");
|
||||
KillProgram("ripcd");
|
||||
KillProgram("caed");
|
||||
|
||||
//
|
||||
// caed(8)
|
||||
//
|
||||
svc_processes[RDSERVICE_CAED_ID]=new Process(RDSERVICE_CAED_ID,this);
|
||||
args.clear();
|
||||
svc_processes[RDSERVICE_CAED_ID]->start(QString(RD_PREFIX)+"/sbin/caed",args);
|
||||
if(!svc_processes[RDSERVICE_CAED_ID]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start caed(8)")+": "+
|
||||
svc_processes[RDSERVICE_CAED_ID]->errorText();
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// ripcd(8)
|
||||
//
|
||||
svc_processes[RDSERVICE_RIPCD_ID]=new Process(RDSERVICE_RIPCD_ID,this);
|
||||
args.clear();
|
||||
svc_processes[RDSERVICE_RIPCD_ID]->
|
||||
start(QString(RD_PREFIX)+"/sbin/ripcd",args);
|
||||
if(!svc_processes[RDSERVICE_RIPCD_ID]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start ripcd(8)")+": "+
|
||||
svc_processes[RDSERVICE_RIPCD_ID]->errorText();
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// rdcatchd(8)
|
||||
//
|
||||
svc_processes[RDSERVICE_RDCATCHD_ID]=new Process(RDSERVICE_RDCATCHD_ID,this);
|
||||
args.clear();
|
||||
svc_processes[RDSERVICE_RDCATCHD_ID]->
|
||||
start(QString(RD_PREFIX)+"/sbin/rdcatchd",args);
|
||||
if(!svc_processes[RDSERVICE_RDCATCHD_ID]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start rdcatchd(8)")+": "+
|
||||
svc_processes[RDSERVICE_RDCATCHD_ID]->errorText();
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// rdvairplayd(8)
|
||||
//
|
||||
svc_processes[RDSERVICE_RDVAIRPLAYD_ID]=new Process(RDSERVICE_RDVAIRPLAYD_ID,this);
|
||||
args.clear();
|
||||
svc_processes[RDSERVICE_RDVAIRPLAYD_ID]->
|
||||
start(QString(RD_PREFIX)+"/sbin/rdvairplayd",args);
|
||||
if(!svc_processes[RDSERVICE_RDVAIRPLAYD_ID]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start rdvairplayd(8)")+": "+
|
||||
svc_processes[RDSERVICE_RDVAIRPLAYD_ID]->errorText();
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// rdrepld(8)
|
||||
//
|
||||
sql=QString("select NAME from REPLICATORS where ")+
|
||||
"STATION_NAME=\""+RDEscapeString(rda->station()->name())+"\"";
|
||||
q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
svc_processes[RDSERVICE_RDREPLD_ID]=new Process(RDSERVICE_RDREPLD_ID,this);
|
||||
args.clear();
|
||||
svc_processes[RDSERVICE_RDREPLD_ID]->
|
||||
start(QString(RD_PREFIX)+"/sbin/rdrepld",args);
|
||||
if(!svc_processes[RDSERVICE_RDREPLD_ID]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start rdrepld(8)")+": "+
|
||||
svc_processes[RDSERVICE_RDREPLD_ID]->errorText();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
delete q;
|
||||
|
||||
if(!StartDropboxes(err_msg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MainObject::StartDropboxes(QString *err_msg)
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
RDSqlQuery *q1;
|
||||
int id=RDSERVICE_FIRST_DROPBOX_ID;
|
||||
|
||||
//
|
||||
// Launch Dropbox Configurations
|
||||
//
|
||||
sql=QString("select ")+
|
||||
"ID,"+ // 00
|
||||
"GROUP_NAME,"+ // 01
|
||||
"PATH,"+ // 02
|
||||
"NORMALIZATION_LEVEL,"+ // 03
|
||||
"AUTOTRIM_LEVEL,"+ // 04
|
||||
"TO_CART,"+ // 05
|
||||
"USE_CARTCHUNK_ID,"+ // 06
|
||||
"TITLE_FROM_CARTCHUNK_ID,"+ // 07
|
||||
"DELETE_CUTS,"+ // 08
|
||||
"METADATA_PATTERN,"+ // 09
|
||||
"FIX_BROKEN_FORMATS,"+ // 10
|
||||
"LOG_PATH,"+ // 11
|
||||
"DELETE_SOURCE,"+ // 12
|
||||
"STARTDATE_OFFSET,"+ // 13
|
||||
"ENDDATE_OFFSET,"+ // 14
|
||||
"ID,"+ // 15
|
||||
"IMPORT_CREATE_DATES,"+ // 16
|
||||
"CREATE_STARTDATE_OFFSET,"+ // 17
|
||||
"CREATE_ENDDATE_OFFSET,"+ // 18
|
||||
"SET_USER_DEFINED,"+ // 19
|
||||
"FORCE_TO_MONO,"+ // 20
|
||||
"SEGUE_LEVEL,"+ // 21
|
||||
"SEGUE_LENGTH "+ // 22
|
||||
"from DROPBOXES where "+
|
||||
"STATION_NAME=\""+RDEscapeString(rda->config()->stationName())+"\"";
|
||||
q=new RDSqlQuery(sql);
|
||||
while(q->next()) {
|
||||
QStringList args;
|
||||
|
||||
args.push_back(QString().sprintf("--persistent-dropbox-id=%d",
|
||||
q->value(15).toInt()));
|
||||
args.push_back("--drop-box");
|
||||
args.push_back("--log-mode");
|
||||
sql=QString("select SCHED_CODE from DROPBOX_SCHED_CODES where ")+
|
||||
QString().sprintf("DROPBOX_ID=%d",q->value(0).toInt());
|
||||
q1=new RDSqlQuery(sql);
|
||||
while(q1->next()) {
|
||||
args.push_back(QString().sprintf("--add-scheduler-code=\"")+
|
||||
q1->value(0).toString()+"\"");
|
||||
}
|
||||
delete q1;
|
||||
args.push_back(QString().sprintf("--normalization-level=%d",
|
||||
q->value(3).toInt()/100));
|
||||
args.push_back(QString().sprintf("--autotrim-level=%d",
|
||||
q->value(4).toInt()/100));
|
||||
if(q->value(5).toUInt()>0) {
|
||||
args.push_back(QString().sprintf("--to-cart=%u",q->value(5).toUInt()));
|
||||
}
|
||||
if(q->value(6).toString()=="Y") {
|
||||
args.push_back("--use-cartchunk-cutid");
|
||||
}
|
||||
if(q->value(21).toInt()<1) {
|
||||
args.push_back(QString().sprintf("--segue-level=%d",
|
||||
q->value(21).toInt()));
|
||||
args.push_back(QString().sprintf("--segue-length=%u",
|
||||
q->value(22).toUInt()));
|
||||
}
|
||||
if(q->value(7).toString()=="Y") {
|
||||
args.push_back("--title-from-cartchunk-cutid");
|
||||
}
|
||||
if(q->value(8).toString()=="Y") {
|
||||
args.push_back("--delete-cuts");
|
||||
}
|
||||
if(q->value(20).toString()=="Y") {
|
||||
args.push_back("--to-mono");
|
||||
}
|
||||
if(!q->value(9).toString().isEmpty()) {
|
||||
args.push_back(QString("--metadata-pattern=")+q->value(9).toString());
|
||||
}
|
||||
if(q->value(10).toString()=="Y") {
|
||||
args.push_back("--fix-broken-formats");
|
||||
}
|
||||
if(q->value(12).toString()=="Y") {
|
||||
args.push_back("--delete-source");
|
||||
}
|
||||
if(q->value(16).toString()=="Y") {
|
||||
args.push_back(QString().sprintf("--create-startdate-offset=%d",
|
||||
q->value(17).toInt()));
|
||||
args.push_back(QString().sprintf("--create-enddate-offset=%d",
|
||||
q->value(18).toInt()));
|
||||
}
|
||||
if(!q->value(19).toString().isEmpty()) {
|
||||
args.push_back(QString("--set-user-defined=")+q->value(19).toString());
|
||||
}
|
||||
args.push_back(QString().sprintf("--startdate-offset=%d",
|
||||
q->value(13).toInt()));
|
||||
args.push_back(QString().sprintf("--enddate-offset=%d",
|
||||
q->value(14).toInt()));
|
||||
args.push_back(q->value(1).toString());
|
||||
args.push_back(q->value(2).toString());
|
||||
|
||||
svc_processes[id]=new Process(id,this);
|
||||
svc_processes[id]->start(QString(RD_PREFIX)+"/bin/rdimport",args);
|
||||
if(!svc_processes[id]->process()->waitForStarted(-1)) {
|
||||
*err_msg=tr("unable to start dropbox")+": "+
|
||||
svc_processes[id]->errorText();
|
||||
return false;
|
||||
}
|
||||
id++;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
QString cmd=QString().
|
||||
sprintf("nice rdimport --persistent-dropbox-id=%d --drop-box --log-mode",
|
||||
q->value(15).toInt());
|
||||
sql=QString("select SCHED_CODE from DROPBOX_SCHED_CODES where ")+
|
||||
QString().sprintf("DROPBOX_ID=%d",q->value(0).toInt());
|
||||
q1=new RDSqlQuery(sql);
|
||||
while(q1->next()) {
|
||||
cmd+=QString(" --add-scheduler-code=\"")+q1->value(0).toString()+"\"";
|
||||
}
|
||||
delete q1;
|
||||
cmd+=
|
||||
QString().sprintf(" --normalization-level=%d",q->value(3).toInt()/100);
|
||||
cmd+=
|
||||
QString().sprintf(" --autotrim-level=%d",q->value(4).toInt()/100);
|
||||
if(q->value(5).toUInt()>0) {
|
||||
cmd+=QString().sprintf(" --to-cart=%u",q->value(5).toUInt());
|
||||
}
|
||||
if(q->value(6).toString()=="Y") {
|
||||
cmd+=" --use-cartchunk-cutid";
|
||||
}
|
||||
if(q->value(21).toInt()<1) {
|
||||
cmd+=
|
||||
QString().sprintf(" --segue-level=%d",q->value(21).toInt());
|
||||
cmd+=
|
||||
QString().sprintf(" --segue-length=%u",q->value(22).toUInt());
|
||||
}
|
||||
if(q->value(7).toString()=="Y") {
|
||||
cmd+=" --title-from-cartchunk-cutid";
|
||||
}
|
||||
if(q->value(8).toString()=="Y") {
|
||||
cmd+=" --delete-cuts";
|
||||
}
|
||||
if(q->value(20).toString()=="Y") {
|
||||
cmd+=" --to-mono";
|
||||
}
|
||||
if(!q->value(9).toString().isEmpty()) {
|
||||
cmd+=QString().sprintf(" \"--metadata-pattern=%s\"",
|
||||
(const char *)q->value(9).toString());
|
||||
}
|
||||
if(q->value(10).toString()=="Y") {
|
||||
cmd+=" --fix-broken-formats";
|
||||
}
|
||||
if(q->value(12).toString()=="Y") {
|
||||
cmd+=" --delete-source";
|
||||
}
|
||||
if(q->value(16).toString()=="Y") {
|
||||
cmd+=QString().sprintf(" --create-startdate-offset=%d",
|
||||
q->value(17).toInt());
|
||||
cmd+=QString().sprintf(" --create-enddate-offset=%d",
|
||||
q->value(18).toInt());
|
||||
}
|
||||
if(!q->value(19).toString().isEmpty()) {
|
||||
cmd+=" --set-user-defined="+RDEscapeString(q->value(19).toString());
|
||||
}
|
||||
cmd+=QString().sprintf(" --startdate-offset=%d",q->value(13).toInt());
|
||||
cmd+=QString().sprintf(" --enddate-offset=%d",q->value(14).toInt());
|
||||
cmd+=QString().sprintf(" %s \"%s\"",(const char *)q->value(1).toString(),
|
||||
(const char *)q->value(2).toString());
|
||||
if(!q->value(11).toString().isEmpty()) {
|
||||
cmd+=QString().sprintf(" >> %s 2>> %s",
|
||||
(const char *)q->value(11).toString(),
|
||||
(const char *)q->value(11).toString());
|
||||
}
|
||||
else {
|
||||
cmd+=" > /dev/null 2> /dev/null";
|
||||
}
|
||||
cmd+=" &";
|
||||
LogLine(RDConfig::LogInfo,QString().
|
||||
sprintf("launching dropbox configuration: \"%s\"",
|
||||
(const char *)cmd));
|
||||
if(fork()==0) {
|
||||
system(cmd);
|
||||
exit(0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
delete q;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void MainObject::KillProgram(const QString &program)
|
||||
{
|
||||
QList<pid_t> pids=RDGetPids(program);
|
||||
|
||||
while(pids.size()>0) {
|
||||
for(int i=0;i<pids.size();i++) {
|
||||
kill(pids.at(i),SIGKILL);
|
||||
fprintf(stderr,"rdservice: killing stale program \"%s\" [%d]\n",
|
||||
(const char *)program.toUtf8(),pids.at(i));
|
||||
}
|
||||
sleep(1);
|
||||
pids=RDGetPids(program);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user