MythTV master
mythbackend_main_helpers.cpp
Go to the documentation of this file.
1#include "libmythbase/mythconfig.h"
2#if CONFIG_SYSTEMD_NOTIFY
3#include <systemd/sd-daemon.h>
4static inline void be_sd_notify(const char *str) { sd_notify(0, str); };
5#else
6static inline void be_sd_notify(const char */*str*/) {};
7#endif
8
9// C++ headers
10#include <cerrno>
11#include <csignal>
12#include <cstdlib>
13#include <fcntl.h>
14#include <sys/stat.h>
15#include <sys/time.h> // for setpriority
16#include <sys/types.h>
17#include <unistd.h>
18
19// Qt
20#include <QtGlobal>
21#include <QCoreApplication>
22#include <QFileInfo>
23#include <QFile>
24#include <QDir>
25#include <QMap>
26
27// MythTV
28#include "libmythbase/compat.h"
29#include "libmythbase/dbutil.h"
33#include "libmythbase/mythdb.h"
37#include "libmythbase/mythversion.h"
39#include "libmythtv/dbcheck.h"
40#include "libmythtv/eitcache.h"
41#include "libmythtv/jobqueue.h"
46#include "libmythtv/tv_rec.h"
47#include "libmythupnp/ssdp.h"
49
50// MythBackend
51#include "autoexpire.h"
52#include "backendcontext.h"
53#include "backendhousekeeper.h"
54#include "encoderlink.h"
55#include "httpstatus.h"
56#include "mainserver.h"
57#include "mediaserver.h"
60#include "scheduler.h"
61
62// New webserver
66#include "servicesv2/v2myth.h"
67#include "servicesv2/v2video.h"
68#include "servicesv2/v2dvr.h"
70#include "servicesv2/v2guide.h"
72#include "servicesv2/v2status.h"
74#include "servicesv2/v2music.h"
75#include "servicesv2/v2config.h"
76
77#define LOC QString("MythBackend: ")
78#define LOC_WARN QString("MythBackend, Warning: ")
79#define LOC_ERR QString("MythBackend, Error: ")
80
81static HouseKeeper *gHousekeeping { nullptr };
82static JobQueue *gJobQueue { nullptr };
84static MediaServer *g_pUPnp { nullptr };
85static MainServer *mainServer { nullptr };
86
87bool setupTVs(bool ismaster, bool &error)
88{
89 error = false;
90 QString localhostname = gCoreContext->GetHostName();
91
93
94 if (ismaster)
95 {
96 // Hack to make sure recorded.basename gets set if the user
97 // downgrades to a prior version and creates new entries
98 // without it.
99 if (!query.exec("UPDATE recorded SET basename = CONCAT(chanid, '_', "
100 "DATE_FORMAT(starttime, '%Y%m%d%H%i00'), '_', "
101 "DATE_FORMAT(endtime, '%Y%m%d%H%i00'), '.nuv') "
102 "WHERE basename = '';"))
103 MythDB::DBError("Updating record basename", query);
104
105 // Hack to make sure record.station gets set if the user
106 // downgrades to a prior version and creates new entries
107 // without it.
108 if (!query.exec("UPDATE channel SET callsign=chanid "
109 "WHERE callsign IS NULL OR callsign='';"))
110 MythDB::DBError("Updating channel callsign", query);
111
112 if (query.exec("SELECT MIN(chanid) FROM channel;"))
113 {
114 query.first();
115 int min_chanid = query.value(0).toInt();
116 if (!query.exec(QString("UPDATE record SET chanid = %1 "
117 "WHERE chanid IS NULL;").arg(min_chanid)))
118 MythDB::DBError("Updating record chanid", query);
119 }
120 else
121 {
122 MythDB::DBError("Querying minimum chanid", query);
123 }
124
125 MSqlQuery records_without_station(MSqlQuery::InitCon());
126 records_without_station.prepare("SELECT record.chanid,"
127 " channel.callsign FROM record LEFT JOIN channel"
128 " ON record.chanid = channel.chanid WHERE record.station='';");
129 if (records_without_station.exec())
130 {
131 MSqlQuery update_record(MSqlQuery::InitCon());
132 update_record.prepare("UPDATE record SET station = :CALLSIGN"
133 " WHERE chanid = :CHANID;");
134 while (records_without_station.next())
135 {
136 update_record.bindValue(":CALLSIGN",
137 records_without_station.value(1));
138 update_record.bindValue(":CHANID",
139 records_without_station.value(0));
140 if (!update_record.exec())
141 {
142 MythDB::DBError("Updating record station", update_record);
143 }
144 }
145 }
146 }
147
148 if (!query.exec(
149 "SELECT cardid, parentid, videodevice, hostname, sourceid "
150 "FROM capturecard "
151 "ORDER BY cardid"))
152 {
153 MythDB::DBError("Querying Recorders", query);
154 return false;
155 }
156
157 std::vector<unsigned int> cardids;
158 std::vector<QString> hosts;
159 while (query.next())
160 {
161 uint cardid = query.value(0).toUInt();
162 uint parentid = query.value(1).toUInt();
163 QString videodevice = query.value(2).toString();
164 QString hostname = query.value(3).toString();
165 uint sourceid = query.value(4).toUInt();
166 QString cidmsg = QString("Card[%1](%2)").arg(cardid).arg(videodevice);
167
168 if (hostname.isEmpty())
169 {
170 LOG(VB_GENERAL, LOG_ERR, cidmsg +
171 " does not have a hostname defined.\n"
172 "Please run setup and confirm all of the capture cards.\n");
173 continue;
174 }
175
176 // Skip all cards that do not have a video source
177 if (sourceid == 0)
178 {
179 if (parentid == 0)
180 {
181 LOG(VB_GENERAL, LOG_WARNING, cidmsg +
182 " does not have a video source");
183 }
184 continue;
185 }
186
187 cardids.push_back(cardid);
188 hosts.push_back(hostname);
189 }
190
191 QWriteLocker tvlocker(&TVRec::s_inputsLock);
192
193 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
194 for (size_t i = 0; i < cardids.size(); i++)
195 {
196 if (hosts[i] == localhostname) {
197 // No memory leak. The constructor for TVRec adds the item
198 // to the static map TVRec::s_inputs.
199 new TVRec(cardids[i]);
200 }
201 }
202
203 for (size_t i = 0; i < cardids.size(); i++)
204 {
205 uint cardid = cardids[i];
206 const QString& host = hosts[i];
207 QString cidmsg = QString("Card %1").arg(cardid);
208
209 if (!ismaster)
210 {
211 if (host == localhostname)
212 {
213 TVRec *tv = TVRec::GetTVRec(cardid);
214 if (tv && tv->Init())
215 {
216 auto *enc = new EncoderLink(cardid, tv);
217 gTVList[cardid] = enc;
218 }
219 else
220 {
221 LOG(VB_GENERAL, LOG_ERR, "Problem with capture cards. " +
222 cidmsg + " failed init");
223 delete tv;
224 // No longer set an error here, because we need the
225 // slave backend to be able to start without a capture
226 // card, so that it can be setup through the web app
227 }
228 }
229 }
230 else
231 {
232 if (host == localhostname)
233 {
234 TVRec *tv = TVRec::GetTVRec(cardid);
235 if (tv && tv->Init())
236 {
237 auto *enc = new EncoderLink(cardid, tv);
238 gTVList[cardid] = enc;
239 }
240 else
241 {
242 LOG(VB_GENERAL, LOG_ERR, "Problem with capture cards. " +
243 cidmsg + " failed init");
244 delete tv;
245 }
246 }
247 else
248 {
249 auto *enc = new EncoderLink(cardid, nullptr, host);
250 gTVList[cardid] = enc;
251 }
252 }
253 }
254
255 if (gTVList.empty())
256 {
257 LOG(VB_GENERAL, LOG_WARNING, LOC +
258 "No valid capture cards are defined in the database.");
259 }
260
261 return true;
262}
263
264void cleanup(void)
265{
266 if (mainServer)
267 {
268 mainServer->Stop();
269 qApp->processEvents();
270 }
271
272 if (gCoreContext)
274
275 delete gSysEventHandler;
276 gSysEventHandler = nullptr;
277
278 delete gHousekeeping;
279 gHousekeeping = nullptr;
280
281 if (gCoreContext)
282 {
283 delete gCoreContext->GetScheduler();
284 gCoreContext->SetScheduler(nullptr);
285 }
286
287 delete gExpirer;
288 gExpirer = nullptr;
289
290 delete gJobQueue;
291 gJobQueue = nullptr;
292
293 delete g_pUPnp;
294 g_pUPnp = nullptr;
295
297 {
300 }
301
302 while (!TVRec::s_inputs.empty())
303 {
304 TVRec *rec = *TVRec::s_inputs.begin();
305 delete rec;
306 }
307
308 delete mainServer;
309 mainServer = nullptr;
310
311 delete gBackendContext;
312 gBackendContext = nullptr;
313}
314
316{
317 if (cmdline.toBool("setverbose"))
318 {
320 {
321 QString message = "SET_VERBOSE ";
322 message += cmdline.toString("setverbose");
323
324 gCoreContext->SendMessage(message);
325 LOG(VB_GENERAL, LOG_INFO,
326 QString("Sent '%1' message").arg(message));
327 return GENERIC_EXIT_OK;
328 }
329 LOG(VB_GENERAL, LOG_ERR,
330 "Unable to connect to backend, verbose mask unchanged ");
332 }
333
334 if (cmdline.toBool("setloglevel"))
335 {
337 {
338 QString message = "SET_LOG_LEVEL ";
339 message += cmdline.toString("setloglevel");
340
341 gCoreContext->SendMessage(message);
342 LOG(VB_GENERAL, LOG_INFO,
343 QString("Sent '%1' message").arg(message));
344 return GENERIC_EXIT_OK;
345 }
346 LOG(VB_GENERAL, LOG_ERR,
347 "Unable to connect to backend, log level unchanged ");
349 }
350
351 if (cmdline.toBool("printsched") ||
352 cmdline.toBool("testsched"))
353 {
354 auto *sched = new Scheduler(false, &gTVList);
355 if (cmdline.toBool("printsched"))
356 {
358 {
359 LOG(VB_GENERAL, LOG_ERR, "Cannot connect to master");
360 delete sched;
362 }
363 std::cout << "Retrieving Schedule from Master backend.\n";
365 }
366 else
367 {
368 std::cout << "Calculating Schedule from database.\n" <<
369 "Inputs, Card IDs, and Conflict info may be invalid "
370 "if you have multiple tuners.\n";
373 }
374
375 verboseMask |= VB_SCHEDULE;
376 LogLevel_t oldLogLevel = logLevel;
377 logLevel = LOG_DEBUG;
378 sched->PrintList(true);
379 logLevel = oldLogLevel;
380 delete sched;
381 return GENERIC_EXIT_OK;
382 }
383
384 if (cmdline.toBool("printexpire"))
385 {
386 gExpirer = new AutoExpire();
387 gExpirer->PrintExpireList(cmdline.toString("printexpire"));
388 return GENERIC_EXIT_OK;
389 }
390
391 // This should never actually be reached..
392 return GENERIC_EXIT_OK;
393}
394using namespace MythTZ;
395
397{
398 auto *tempMonitorConnection = new MythSocket();
399 if (tempMonitorConnection->ConnectToHost(
402 {
403 if (!gCoreContext->CheckProtoVersion(tempMonitorConnection))
404 {
405 LOG(VB_GENERAL, LOG_ERR, "Master backend is incompatible with "
406 "this backend.\nCannot become a slave.");
407 tempMonitorConnection->DecrRef();
409 }
410
411 QStringList tempMonitorDone("DONE");
412
413 QStringList tempMonitorAnnounce(QString("ANN Monitor %1 0")
414 .arg(gCoreContext->GetHostName()));
415 tempMonitorConnection->SendReceiveStringList(tempMonitorAnnounce);
416 if (tempMonitorAnnounce.empty() ||
417 tempMonitorAnnounce[0] == "ERROR")
418 {
419 tempMonitorConnection->DecrRef();
420 tempMonitorConnection = nullptr;
421 if (tempMonitorAnnounce.empty())
422 {
423 LOG(VB_GENERAL, LOG_ERR, LOC +
424 "Failed to open event socket, timeout");
425 }
426 else
427 {
428 LOG(VB_GENERAL, LOG_ERR, LOC +
429 "Failed to open event socket" +
430 ((tempMonitorAnnounce.size() >= 2) ?
431 QString(", error was %1").arg(tempMonitorAnnounce[1]) :
432 QString(", remote error")));
433 }
434 }
435
436 QStringList timeCheck;
437 if (tempMonitorConnection)
438 {
439 timeCheck.push_back("QUERY_TIME_ZONE");
440 tempMonitorConnection->SendReceiveStringList(timeCheck);
441 tempMonitorConnection->WriteStringList(tempMonitorDone);
442 }
443 if (timeCheck.size() < 3)
444 {
445 if (tempMonitorConnection)
446 tempMonitorConnection->DecrRef();
448 }
449
450 QDateTime our_time = MythDate::current();
451 QDateTime master_time = MythDate::fromString(timeCheck[2]);
452 int timediff = abs(our_time.secsTo(master_time));
453
454 if (timediff > 300)
455 {
456 LOG(VB_GENERAL, LOG_ERR,
457 QString("Current time on the master backend differs by "
458 "%1 seconds from time on this system. Exiting.")
459 .arg(timediff));
460 if (tempMonitorConnection)
461 tempMonitorConnection->DecrRef();
463 }
464
465 if (timediff > 20)
466 {
467 LOG(VB_GENERAL, LOG_WARNING,
468 QString("Time difference between the master "
469 "backend and this system is %1 seconds.")
470 .arg(timediff));
471 }
472 }
473 if (tempMonitorConnection)
474 tempMonitorConnection->DecrRef();
475
476 return GENERIC_EXIT_OK;
477}
478
479
481{
482 if (cmdline.toBool("nohousekeeper"))
483 {
484 LOG(VB_GENERAL, LOG_WARNING, LOC +
485 "****** The Housekeeper has been DISABLED with "
486 "the --nohousekeeper option ******");
487 }
488 if (cmdline.toBool("nosched"))
489 {
490 LOG(VB_GENERAL, LOG_WARNING, LOC +
491 "********** The Scheduler has been DISABLED with "
492 "the --nosched option **********");
493 }
494 if (cmdline.toBool("noautoexpire"))
495 {
496 LOG(VB_GENERAL, LOG_WARNING, LOC +
497 "********* Auto-Expire has been DISABLED with "
498 "the --noautoexpire option ********");
499 }
500 if (cmdline.toBool("nojobqueue"))
501 {
502 LOG(VB_GENERAL, LOG_WARNING, LOC +
503 "********* The JobQueue has been DISABLED with "
504 "the --nojobqueue option *********");
505 }
506}
507
509{
511
513 {
514 return run_setup_webserver();
515 }
517 {
518 LOG(VB_GENERAL, LOG_ERR,
519 "MySQL time zone support is missing. "
520 "Please install it and try again. "
521 "See 'mysql_tzinfo_to_sql' for assistance.");
522 gCoreContext->GetDB()->IgnoreDatabase(true);
524 return run_setup_webserver();
525 }
526 bool ismaster = gCoreContext->IsMasterHost();
527
528 if (!UpgradeTVDatabaseSchema(ismaster, ismaster, true))
529 {
530 LOG(VB_GENERAL, LOG_ERR,
531 QString("Couldn't upgrade database to new schema on %1 backend.")
532 .arg(ismaster ? "master" : "slave"));
534 return run_setup_webserver();
535 }
536#ifndef NDEBUG
537 if (cmdline.toBool("upgradedbonly"))
538 {
539 LOG(VB_GENERAL, LOG_ERR, "Exiting as requested.");
540 return GENERIC_EXIT_OK;
541 }
542#endif
543
544 be_sd_notify("STATUS=Loading translation");
545 MythTranslation::load("mythfrontend");
546
547 if (cmdline.toBool("webonly"))
548 {
550 return run_setup_webserver();
551 }
552 if (!ismaster)
553 {
554 be_sd_notify("STATUS=Connecting to master backend");
555 int ret = connect_to_master();
556 if (ret != GENERIC_EXIT_OK)
557 return ret;
558 }
559
560 be_sd_notify("STATUS=Get backend server port");
562 if (gCoreContext->GetBackendServerIP().isEmpty())
563 {
564 std::cerr << "No setting found for this machine's BackendServerAddr.\n"
565 << "MythBackend starting in Web App only mode for initial setup.\n"
566 << "Use http://<yourBackend>:6544 to perform setup.\n";
568 return run_setup_webserver();
569 }
570
572
573 if (ismaster)
574 {
575 LOG(VB_GENERAL, LOG_NOTICE, LOC + "Starting up as the master server.");
576 }
577 else
578 {
579 LOG(VB_GENERAL, LOG_NOTICE, LOC + "Running as a slave backend.");
580 }
581
582 if (ismaster)
583 {
585 }
586
588
589 bool fatal_error = false;
590 bool runsched = setupTVs(ismaster, fatal_error);
591 if (fatal_error)
593
594 Scheduler *sched = nullptr;
595 if (ismaster)
596 {
597 if (runsched)
598 {
599 be_sd_notify("STATUS=Creating scheduler");
600 sched = new Scheduler(true, &gTVList);
601 int err = sched->GetError();
602 if (err)
603 {
604 delete sched;
605 return err;
606 }
607
608 if (cmdline.toBool("nosched"))
610 }
611
612 if (!cmdline.toBool("noautoexpire"))
613 {
615 if (sched)
617 }
620 }
621
622 if (!cmdline.toBool("nohousekeeper"))
623 {
624 be_sd_notify("STATUS=Creating housekeeper");
626
627 if (ismaster)
628 {
633
634 // only run this task if MythMusic is installed and we have a new enough schema
635 if (gCoreContext->GetNumSetting("MusicDBSchemaVer", 0) >= 1024)
637 }
638
640#ifdef Q_OS_LINUX
641 #ifdef CONFIG_BINDINGS_PYTHON
643 #endif
644#endif
645
647 }
648
649 if (!cmdline.toBool("nojobqueue"))
650 gJobQueue = new JobQueue(ismaster);
651
652 // ----------------------------------------------------------------------
653 //
654 // ----------------------------------------------------------------------
655
656 if (g_pUPnp == nullptr)
657 {
658 be_sd_notify("STATUS=Creating UPnP media server");
659 g_pUPnp = new MediaServer();
660
661 g_pUPnp->Init(ismaster, cmdline.toBool("noupnp"));
662 }
663
664 if (cmdline.toBool("dvbv3"))
665 {
666 LOG(VB_GENERAL, LOG_INFO, LOC + "Use legacy DVBv3 API");
667 gCoreContext->SetDVBv3(true);
668 }
669
670 // ----------------------------------------------------------------------
671 // Setup status server
672 // ----------------------------------------------------------------------
673
674 HttpStatus *httpStatus = nullptr;
676
677 if (pHS)
678 {
679 LOG(VB_GENERAL, LOG_INFO, "Main::Registering HttpStatus Extension");
680 be_sd_notify("STATUS=Registering HttpStatus Extension");
681
682 httpStatus = new HttpStatus( &gTVList, sched, ismaster );
683 pHS->RegisterExtension( httpStatus );
684 }
685
686 be_sd_notify("STATUS=Creating main server");
688 ismaster, port, &gTVList, sched, gExpirer);
689
690 int exitCode = mainServer->GetExitCode();
691 if (exitCode != GENERIC_EXIT_OK)
692 {
693 LOG(VB_GENERAL, LOG_CRIT,
694 "Backend exiting, MainServer initialization error.");
695 cleanup();
696 return exitCode;
697 }
698
699 if (httpStatus && mainServer)
700 httpStatus->SetMainServer(mainServer);
701
702 be_sd_notify("STATUS=Check all storage groups");
704
705 be_sd_notify("STATUS=Sending \"master started\" message");
707 gCoreContext->SendSystemEvent("MASTER_STARTED");
708
709 // Provide systemd ready notification (for Type=notify)
710 be_sd_notify("READY=1");
711
712 const HTTPServices be_services = {
713 { VIDEO_SERVICE, &MythHTTPService::Create<V2Video> },
714 { MYTH_SERVICE, &MythHTTPService::Create<V2Myth> },
715 { DVR_SERVICE, &MythHTTPService::Create<V2Dvr> },
716 { CONTENT_SERVICE, &MythHTTPService::Create<V2Content> },
717 { GUIDE_SERVICE, &MythHTTPService::Create<V2Guide> },
718 { CHANNEL_SERVICE, &MythHTTPService::Create<V2Channel> },
719 { STATUS_SERVICE, &MythHTTPService::Create<V2Status> },
720 { CAPTURE_SERVICE, &MythHTTPService::Create<V2Capture> },
721 { MUSIC_SERVICE, &MythHTTPService::Create<V2Music> },
722 { CONFIG_SERVICE, &MythHTTPService::Create<V2Config> },
723 };
724
726
727 // Send all unknown requests into the web app. make bookmarks and direct access work.
728 auto spa_index = [](auto && PH1) { return MythHTTPRewrite::RewriteToSPA(std::forward<decltype(PH1)>(PH1), "apps/backend/index.html"); };
729 MythHTTPInstance::AddErrorPageHandler({ "=404", spa_index });
730
731 // Serve components of the backend web app as if they were hosted at '/'
732 auto main_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/main.js"); };
733 auto styles_css = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/styles.css"); };
734 auto polyfills_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/polyfills.js"); };
735 auto runtime_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/runtime.js"); };
736
737 // Default index page
738 auto root = [](auto && PH1) { return MythHTTPRoot::RedirectRoot(std::forward<decltype(PH1)>(PH1), "apps/backend/index.html"); };
739
740 const HTTPHandlers be_handlers = {
741 { "/main.js", main_js },
742 { "/styles.css", styles_css },
743 { "/polyfills.js", polyfills_js },
744 { "/runtime.js", runtime_js },
745 { "/", root }
746 };
747
748 MythHTTPScopedInstance webserver(be_handlers);
749
752 exitCode = qApp->exec();
755
757 {
758 gCoreContext->SendSystemEvent("MASTER_SHUTDOWN");
759 qApp->processEvents();
760 }
761
762 LOG(VB_GENERAL, LOG_NOTICE, "MythBackend exiting");
763 be_sd_notify("STOPPING=1\nSTATUS=Exiting");
764
765 return exitCode;
766}
767
768// This is a copy of the code from above, to start backend in a restricted mode, only running the web server
769// when the database is unusable, so thet the user can use the web app to fix the settings.
770
772{
773 LOG(VB_GENERAL, LOG_NOTICE, "***********************************************************************");
774 LOG(VB_GENERAL, LOG_NOTICE, "***** MythBackend starting in Web App only mode for initial setup *****");
775 LOG(VB_GENERAL, LOG_NOTICE, "***** Use http://<yourBackend>:6544 to perform setup *****");
776 LOG(VB_GENERAL, LOG_NOTICE, "***********************************************************************");
777
778 const HTTPServices be_services = {
779 { VIDEO_SERVICE, &MythHTTPService::Create<V2Video> },
780 { MYTH_SERVICE, &MythHTTPService::Create<V2Myth> },
781 { DVR_SERVICE, &MythHTTPService::Create<V2Dvr> },
782 { CONTENT_SERVICE, &MythHTTPService::Create<V2Content> },
783 { GUIDE_SERVICE, &MythHTTPService::Create<V2Guide> },
784 { CHANNEL_SERVICE, &MythHTTPService::Create<V2Channel> },
785 { STATUS_SERVICE, &MythHTTPService::Create<V2Status> },
786 { CAPTURE_SERVICE, &MythHTTPService::Create<V2Capture> },
787 { MUSIC_SERVICE, &MythHTTPService::Create<V2Music> },
788 { CONFIG_SERVICE, &MythHTTPService::Create<V2Config> },
789 };
790
792
793 // Send all unknown requests into the web app. make bookmarks and direct access work.
794 auto spa_index = [](auto && PH1) { return MythHTTPRewrite::RewriteToSPA(std::forward<decltype(PH1)>(PH1), "apps/backend/index.html"); };
795 MythHTTPInstance::AddErrorPageHandler({ "=404", spa_index });
796
797 // Serve components of the backend web app as if they were hosted at '/'
798 auto main_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/main.js"); };
799 auto styles_css = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/styles.css"); };
800 auto polyfills_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/polyfills.js"); };
801 auto runtime_js = [](auto && PH1) { return MythHTTPRewrite::RewriteFile(std::forward<decltype(PH1)>(PH1), "apps/backend/runtime.js"); };
802
803 // Default index page
804 auto root = [](auto && PH1) { return MythHTTPRoot::RedirectRoot(std::forward<decltype(PH1)>(PH1), "apps/backend/index.html"); };
805
806 const HTTPHandlers be_handlers = {
807 { "/main.js", main_js },
808 { "/styles.css", styles_css },
809 { "/polyfills.js", polyfills_js },
810 { "/runtime.js", runtime_js },
811 { "/", root }
812 };
813
814 MythHTTPScopedInstance webserver(be_handlers);
815
818 // Provide systemd ready notification (for Type=notify)
819 be_sd_notify("READY=1\nSTATUS=Started in 'Web App only mode'");
820 int exitCode = qApp->exec();
821
822 be_sd_notify("STOPPING=1\nSTATUS='Exiting Web App only mode'");
823 LOG(VB_GENERAL, LOG_NOTICE, "MythBackend Web App only mode exiting");
824 return exitCode;
825}
AutoExpire * gExpirer
QMap< int, EncoderLink * > gTVList
BackendContext * gBackendContext
Used to expire recordings to make space for new recordings.
Definition: autoexpire.h:60
void PrintExpireList(const QString &expHost="ALL")
Prints a summary of the files that can be deleted.
Definition: autoexpire.cpp:807
static void UpdateChannelGroups(void)
static bool CheckTimeZoneSupport(void)
Check if MySQL has working timz zone support.
Definition: dbutil.cpp:869
static MTV_PUBLIC void ClearChannelLocks(void)
Removes old channel locks, use it only at master backend start.
Definition: eitcache.cpp:462
Manages registered HouseKeeperTasks and queues tasks for operation.
Definition: housekeeper.h:150
void Start(void)
void RegisterTask(HouseKeeperTask *task)
void RegisterExtension(HttpServerExtension *pExtension)
Definition: httpserver.cpp:313
void SetMainServer(MainServer *mainServer)
Definition: httpstatus.h:87
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
bool first(void)
Wrap QSqlQuery::first() so we can display the query results.
Definition: mythdbcon.cpp:822
QVariant value(int i) const
Definition: mythdbcon.h:204
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
int GetExitCode() const
Definition: mainserver.h:153
void Stop(void)
Definition: mainserver.cpp:359
void Init(bool bIsMaster, bool bDisableUPnp=false)
Definition: mediaserver.cpp:54
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
MythDB * GetDB(void)
QString GetMasterServerIP(void)
Returns the Master Backend IP address If the address is an IPv6 address, the scope Id is removed.
bool IsDatabaseIgnored(void) const
/brief Returns true if database is being ignored.
QString GetHostName(void)
void SetExiting(bool exiting=true)
MythScheduler * GetScheduler(void)
void SendSystemEvent(const QString &msg)
static int GetMasterServerPort(void)
Returns the Master Backend control port If no master server port has been defined in the database,...
bool CheckProtoVersion(MythSocket *socket, std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
int GetBackendServerPort(void)
Returns the locally defined backend control port.
void SetDVBv3(bool dvbv3)
void SetScheduler(MythScheduler *sched)
bool ConnectToMasterServer(bool blockingClient=true, bool openEventSocket=true)
void SendMessage(const QString &message)
bool IsMasterHost(void)
is this the same host as the master
int GetNumSetting(const QString &key, int defaultval=0)
QString GetBackendServerIP(void)
Returns the IP address of the locally defined backend IP.
bool IsMasterBackend(void)
is this the actual MBE process
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
static void AddErrorPageHandler(const HTTPHandler &Handler)
static void Addservices(const HTTPServices &Services)
static HTTPResponse RewriteFile(const HTTPRequest2 &Request, const QString &File)
A convenience method to seemlessly redirect requests for files to a context specific file.
static HTTPResponse RewriteToSPA(const HTTPRequest2 &Request, const QString &File)
A convenience method to seemlessly redirect requests to a Single Page web app (SPA)
static HTTPResponse RedirectRoot(const HTTPRequest2 &Request, const QString &File)
A convenience method to seemlessly redirect requests for index.html to a context specific file.
Class for communcating between myth backends and frontends.
Definition: mythsocket.h:26
Handles incoming MythSystemEvent messages.
static void load(const QString &module_name)
Load a QTranslator for the user's preferred language.
static void CheckProgramIDAuthorities(void)
void FillRecordListFromDB(uint recordid=0)
Definition: scheduler.cpp:496
void PrintList(bool onlyFutureRecordings=false)
Definition: scheduler.h:98
int GetError(void) const
Definition: scheduler.h:119
void DisableScheduling(void)
Definition: scheduler.h:109
void SetExpirer(AutoExpire *autoExpirer)
Definition: scheduler.h:54
void FillRecordListFromMaster(void)
Definition: scheduler.cpp:579
static void CheckAllStorageGroupDirs(void)
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
bool Init(void)
Performs instance initialization, returns true on success.
Definition: tv_rec.cpp:156
static TVRec * GetTVRec(uint inputid)
Definition: tv_rec.cpp:4904
static QReadWriteLock s_inputsLock
Definition: tv_rec.h:434
static QMap< uint, TVRec * > s_inputs
Definition: tv_rec.h:435
void RequestTerminate()
Definition: taskqueue.cpp:98
static TaskQueue * Instance()
Definition: taskqueue.cpp:55
HttpServer * GetHttpServer()
Definition: upnp.h:126
static WebOnlyStartup s_WebOnlyStartup
Definition: v2myth.h:68
@ kWebOnlyIPAddress
Definition: v2myth.h:65
@ kWebOnlyDBTimezone
Definition: v2myth.h:63
@ kWebOnlyWebOnlyParm
Definition: v2myth.h:64
@ kWebOnlySchemaUpdate
Definition: v2myth.h:66
unsigned int uint
Definition: compat.h:68
bool UpgradeTVDatabaseSchema(const bool upgradeAllowed, const bool upgradeIfNoUI, const bool informSystemd)
Called from outside dbcheck.cpp to update the schema.
Definition: dbcheck.cpp:362
@ GENERIC_EXIT_CONNECT_ERROR
Can't connect to master backend.
Definition: exitcodes.h:23
@ GENERIC_EXIT_INVALID_TIME
Invalid time.
Definition: exitcodes.h:25
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_SETUP_ERROR
Incorrectly setup system.
Definition: exitcodes.h:24
@ GENERIC_EXIT_SOCKET_ERROR
Socket error.
Definition: exitcodes.h:21
uint64_t verboseMask
Definition: logging.cpp:100
LogLevel_t logLevel
Definition: logging.cpp:88
#define LOC
static HouseKeeper * gHousekeeping
int handle_command(const MythBackendCommandLineParser &cmdline)
int connect_to_master(void)
static MediaServer * g_pUPnp
static JobQueue * gJobQueue
static MainServer * mainServer
bool setupTVs(bool ismaster, bool &error)
void print_warnings(const MythBackendCommandLineParser &cmdline)
static void be_sd_notify(const char *)
int run_backend(MythBackendCommandLineParser &cmdline)
int run_setup_webserver()
void cleanup(void)
static MythSystemEventHandler * gSysEventHandler
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
std::vector< HTTPHandler > HTTPHandlers
Definition: mythhttptypes.h:48
std::vector< HTTPService > HTTPServices
Definition: mythhttptypes.h:55
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
QDateTime fromString(const QString &dtstr)
Converts kFilename && kISODate formats to QDateTime.
Definition: mythdate.cpp:39
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:15
MythCommFlagCommandLineParser cmdline
def error(message)
Definition: smolt.py:409
string hostname
Definition: caa.py:17
#define CAPTURE_SERVICE
Definition: v2capture.h:33
#define CHANNEL_SERVICE
Definition: v2channel.h:39
#define CONFIG_SERVICE
Definition: v2config.h:11
#define CONTENT_SERVICE
Definition: v2content.h:34
#define DVR_SERVICE
Definition: v2dvr.h:41
Scheduler * sched
#define GUIDE_SERVICE
Definition: v2guide.h:42
#define MUSIC_SERVICE
Definition: v2music.h:17
#define MYTH_SERVICE
Definition: v2myth.h:16
#define STATUS_SERVICE
Definition: v2status.h:34
#define VIDEO_SERVICE
Definition: v2video.h:13