From e5b6a7ec0a45db9513b35bb5fde6ae4bf42ab7bf Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Thu, 21 Mar 2019 17:13:46 -0400 Subject: [PATCH] 2019-03-21 Fred Gleason * Added a startup check for the 'rivendell' service. --- ChangeLog | 3 +- lib/librd_cs.ts | 19 +++++++++++ lib/librd_de.ts | 19 +++++++++++ lib/librd_es.ts | 19 +++++++++++ lib/librd_fr.ts | 19 +++++++++++ lib/librd_nb.ts | 19 +++++++++++ lib/librd_nn.ts | 19 +++++++++++ lib/librd_pt_BR.ts | 19 +++++++++++ lib/rdapplication.cpp | 60 +++++++++++++++++++++++++++++++++-- lib/rdapplication.h | 8 +++-- rdcatchd/rdcatchd.cpp | 3 +- rdpadd/rdpadd.cpp | 4 +-- rdpadengined/rdpadengined.cpp | 5 +-- rdrepld/rdrepld.cpp | 3 +- rdservice/startup.cpp | 2 +- rdvairplayd/rdvairplayd.cpp | 3 +- ripcd/ripcd.cpp | 5 +-- 17 files changed, 213 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index a27c3ec0..18ff91c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18551,4 +18551,5 @@ Guide. 2019-03-21 Fred Gleason * Cleaned up formatting typos in 'docs/opsguide/rml.xml'. - +2019-03-21 Fred Gleason + * Added a startup check for the 'rivendell' service. diff --git a/lib/librd_cs.ts b/lib/librd_cs.ts index 9080e2e2..7e659054 100644 --- a/lib/librd_cs.ts +++ b/lib/librd_cs.ts @@ -880,6 +880,25 @@ Služba je neplatná! + + RDApplication + + systemctl(1) returned exit code + + + + OK + OK + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_de.ts b/lib/librd_de.ts index 59d9c270..efcc9b6b 100644 --- a/lib/librd_de.ts +++ b/lib/librd_de.ts @@ -876,6 +876,25 @@ Der Service ist ungültig! + + RDApplication + + systemctl(1) returned exit code + + + + OK + OK + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_es.ts b/lib/librd_es.ts index 59a8182c..d713eab3 100644 --- a/lib/librd_es.ts +++ b/lib/librd_es.ts @@ -876,6 +876,25 @@ ¡El servicio es inválido! + + RDApplication + + systemctl(1) returned exit code + + + + OK + + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_fr.ts b/lib/librd_fr.ts index 9aa8dd3c..61fbf55f 100644 --- a/lib/librd_fr.ts +++ b/lib/librd_fr.ts @@ -842,6 +842,25 @@ + + RDApplication + + systemctl(1) returned exit code + + + + OK + + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_nb.ts b/lib/librd_nb.ts index d426a26b..3ca46584 100644 --- a/lib/librd_nb.ts +++ b/lib/librd_nb.ts @@ -876,6 +876,25 @@ + + RDApplication + + systemctl(1) returned exit code + + + + OK + OK + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_nn.ts b/lib/librd_nn.ts index d426a26b..3ca46584 100644 --- a/lib/librd_nn.ts +++ b/lib/librd_nn.ts @@ -876,6 +876,25 @@ + + RDApplication + + systemctl(1) returned exit code + + + + OK + OK + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/librd_pt_BR.ts b/lib/librd_pt_BR.ts index 13d95060..9e64ab27 100644 --- a/lib/librd_pt_BR.ts +++ b/lib/librd_pt_BR.ts @@ -876,6 +876,25 @@ O Serviço é Inválido! + + RDApplication + + systemctl(1) returned exit code + + + + OK + OK + + + systemctl(1) crashed. + + + + Rivendell service is not active. + + + RDAudioSettingsDialog diff --git a/lib/rdapplication.cpp b/lib/rdapplication.cpp index 5a056d06..1ee7ed12 100644 --- a/lib/rdapplication.cpp +++ b/lib/rdapplication.cpp @@ -2,7 +2,7 @@ // // Base Application Class // -// (C) Copyright 2018 Fred Gleason +// (C) Copyright 2018-2019 Fred Gleason // // 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 @@ -22,6 +22,7 @@ #include #include +#include #include "dbversion.h" #include "rdapplication.h" @@ -104,7 +105,8 @@ RDApplication::~RDApplication() } -bool RDApplication::open(QString *err_msg,RDApplication::ErrorType *err_type) +bool RDApplication::open(QString *err_msg,RDApplication::ErrorType *err_type, + bool check_svc) { int schema=0; QString db_err; @@ -133,6 +135,18 @@ bool RDApplication::open(QString *err_msg,RDApplication::ErrorType *err_type) app_config->load(); app_config->setModuleName(app_module_name); + // + // Check Rivendell Service Status + // + if(check_svc) { + if(!CheckService(err_msg)) { + if(err_type!=NULL) { + *err_type=RDApplication::ErrorNoService; + } + return false; + } + } + // // Open Database // @@ -282,3 +296,45 @@ void RDApplication::userChangedData() app_user->setName(app_ripc->user()); emit userChanged(); } + + + bool RDApplication::CheckService(QString *err_msg) +{ + bool ret=false; + QStringList args; + QProcess *proc=new QProcess(this); + + args.push_back("--property"); + args.push_back("ActiveState"); + args.push_back("show"); + args.push_back("rivendell"); + proc->start("systemctl",args); + proc->waitForFinished(); + if(proc->exitStatus()!=QProcess::NormalExit) { + *err_msg=tr("systemctl(1) crashed."); + } + else { + if(proc->exitCode()!=0) { + *err_msg=tr("systemctl(1) returned exit code")+ + QString().sprintf(" %d:\n",proc->exitCode())+ + proc->readAllStandardError(); + } + else { + *err_msg=tr("Rivendell service is not active."); + QStringList f0=QString(proc->readAllStandardOutput()). + split("\n",QString::SkipEmptyParts); + for(int i=0;i +// (C) Copyright 2018-2019 Fred Gleason // // 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 @@ -41,11 +41,12 @@ class RDApplication : public QObject { Q_OBJECT; public: - enum ErrorType {ErrorOk=0,ErrorDbVersionSkew=1,ErrorNoHostEntry=2}; + enum ErrorType {ErrorOk=0,ErrorDbVersionSkew=1,ErrorNoHostEntry=2, + ErrorNoService=3}; RDApplication(const QString &module_name,const QString &cmdname, const QString &usage,QObject *parent=0); ~RDApplication(); - bool open(QString *err_msg,ErrorType *err_type=NULL); + bool open(QString *err_msg,ErrorType *err_type=NULL,bool check_svc=true); RDAirPlayConf *airplayConf(); RDCae *cae(); RDCmdSwitch *cmdSwitch(); @@ -68,6 +69,7 @@ class RDApplication : public QObject void userChanged(); private: + bool CheckService(QString *err_msg); RDAirPlayConf *app_airplay_conf; RDAirPlayConf *app_panel_conf; RDCae *app_cae; diff --git a/rdcatchd/rdcatchd.cpp b/rdcatchd/rdcatchd.cpp index 77e170af..f515159b 100644 --- a/rdcatchd/rdcatchd.cpp +++ b/rdcatchd/rdcatchd.cpp @@ -185,13 +185,14 @@ MainObject::MainObject(QObject *parent) QString sql; RDSqlQuery *q; QString err_msg; + RDApplication::ErrorType err_type=RDApplication::ErrorOk; debug=false; // // Open the Database // rda=new RDApplication("rdcatchd","rdcatchd",RDCATCHD_USAGE,this); - if(!rda->open(&err_msg)) { + if(!rda->open(&err_msg,&err_type,false)) { fprintf(stderr,"rdcatchd: %s\n",(const char *)err_msg); exit(1); } diff --git a/rdpadd/rdpadd.cpp b/rdpadd/rdpadd.cpp index aeeaceed..637a66a0 100644 --- a/rdpadd/rdpadd.cpp +++ b/rdpadd/rdpadd.cpp @@ -2,7 +2,7 @@ // // Rivendell PAD Consolidation Server // -// (C) Copyright 2018 Fred Gleason +// (C) Copyright 2018-2019 Fred Gleason // // 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 @@ -44,7 +44,7 @@ QByteArray MetadataSource::buffer() const bool MetadataSource::appendBuffer(const QByteArray &data) { - printf("data: %s\n",(const char *)data); + // printf("data: %s\n",(const char *)data); if(meta_committed) { meta_buffer.clear(); diff --git a/rdpadengined/rdpadengined.cpp b/rdpadengined/rdpadengined.cpp index 02f86eb3..0b0fdb84 100644 --- a/rdpadengined/rdpadengined.cpp +++ b/rdpadengined/rdpadengined.cpp @@ -2,7 +2,7 @@ // // Rivendell PAD Consolidation Server // -// (C) Copyright 2018 Fred Gleason +// (C) Copyright 2018-2019 Fred Gleason // // 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 @@ -49,12 +49,13 @@ MainObject::MainObject(QObject *parent) : QObject(parent) { QString err_msg; + RDApplication::ErrorType err_type=RDApplication::ErrorOk; // // Open the Database // rda=new RDApplication("rdpadengined","rdpadengined",RDPADENGINED_USAGE,this); - if(!rda->open(&err_msg)) { + if(!rda->open(&err_msg,&err_type,false)) { fprintf(stderr,"rdpadengined: %s\n",(const char *)err_msg); exit(1); } diff --git a/rdrepld/rdrepld.cpp b/rdrepld/rdrepld.cpp index f6d5ee28..04d6392b 100644 --- a/rdrepld/rdrepld.cpp +++ b/rdrepld/rdrepld.cpp @@ -62,6 +62,7 @@ MainObject::MainObject(QObject *parent) :QObject(parent) { QString err_msg; + RDApplication::ErrorType err_type=RDApplication::ErrorOk; debug=false; @@ -69,7 +70,7 @@ MainObject::MainObject(QObject *parent) // Open the Database // rda=new RDApplication("rdrepld","rdrepld",RDREPLD_USAGE,this); - if(!rda->open(&err_msg)) { + if(!rda->open(&err_msg,&err_type,false)) { fprintf(stderr,"rdrepld: %s\n",(const char *)err_msg); exit(1); } diff --git a/rdservice/startup.cpp b/rdservice/startup.cpp index eee9d2ae..3384ce9d 100644 --- a/rdservice/startup.cpp +++ b/rdservice/startup.cpp @@ -2,7 +2,7 @@ // // Startup routines for the Rivendell Services Manager // -// (C) Copyright 2018 Fred Gleason +// (C) Copyright 2018-2019 Fred Gleason // // 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 diff --git a/rdvairplayd/rdvairplayd.cpp b/rdvairplayd/rdvairplayd.cpp index c178ff0f..bfefba1e 100644 --- a/rdvairplayd/rdvairplayd.cpp +++ b/rdvairplayd/rdvairplayd.cpp @@ -53,6 +53,7 @@ MainObject::MainObject(QObject *parent) :QObject(parent) { QString err_msg; + RDApplication::ErrorType err_type=RDApplication::ErrorOk; // // Startup DateTime @@ -63,7 +64,7 @@ MainObject::MainObject(QObject *parent) // Open the Database // rda=new RDApplication("rdvairplayd","rdvairplayd",RDVAIRPLAYD_USAGE,this); - if(!rda->open(&err_msg)) { + if(!rda->open(&err_msg,&err_type,false)) { fprintf(stderr,"rdvairplayd: %s\n",(const char *)err_msg); exit(1); } diff --git a/ripcd/ripcd.cpp b/ripcd/ripcd.cpp index 64193c9e..722a77e6 100644 --- a/ripcd/ripcd.cpp +++ b/ripcd/ripcd.cpp @@ -2,7 +2,7 @@ // // Rivendell Interprocess Communication Daemon // -// (C) Copyright 2002-2018 Fred Gleason +// (C) Copyright 2002-2019 Fred Gleason // // 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 @@ -75,9 +75,10 @@ MainObject::MainObject(QObject *parent) :QObject(parent) { QString err_msg; + RDApplication::ErrorType err_type=RDApplication::ErrorOk; rda=new RDApplication("ripcd","ripcd",RIPCD_USAGE,this); - if(!rda->open(&err_msg)) { + if(!rda->open(&err_msg,&err_type,false)) { fprintf(stderr,"ripcd: %s\n",(const char *)err_msg.utf8()); exit(1); }