int run_backend(MythBackendCommandLineParser &cmdline) { gBackendContext = new BackendContext(); if (!DBUtil::CheckTimeZoneSupport()) { LOG(VB_GENERAL, LOG_ERR, "MySQL time zone support is missing. " "Please install it and try again. " "See 'mysql_tzinfo_to_sql' for assistance."); return GENERIC_EXIT_DB_NOTIMEZONE; } bool ismaster = gCoreContext->IsMasterHost(); if (!UpgradeTVDatabaseSchema(ismaster, ismaster)) { LOG(VB_GENERAL, LOG_ERR, "Couldn't upgrade database to new schema"); return GENERIC_EXIT_DB_OUTOFDATE; } MythTranslation::load("mythfrontend"); if (!ismaster) { int ret = connect_to_master(); if (ret != GENERIC_EXIT_OK) return ret; } int port = gCoreContext->GetBackendServerPort(); if (gCoreContext->GetBackendServerIP().isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); if (ismaster) { LOG(VB_GENERAL, LOG_NOTICE, LOC + "Starting up as the master server."); } else { LOG(VB_GENERAL, LOG_NOTICE, LOC + "Running as a slave backend."); } print_warnings(cmdline); bool fatal_error = false; bool runsched = setupTVs(ismaster, fatal_error); if (fatal_error) { delete sysEventHandler; return GENERIC_EXIT_SETUP_ERROR; } Scheduler *sched = NULL; if (ismaster) { if (runsched) { sched = new Scheduler(true, &tvList); int err = sched->GetError(); if (err) return err; if (cmdline.toBool("nosched")) sched->DisableScheduling(); } if (!cmdline.toBool("noautoexpire")) { expirer = new AutoExpire(&tvList); if (sched) sched->SetExpirer(expirer); } gCoreContext->SetScheduler(sched); } if (!cmdline.toBool("nohousekeeper")) { housekeeping = new HouseKeeper(); if (ismaster) { housekeeping->RegisterTask(new LogCleanerTask()); housekeeping->RegisterTask(new CleanupTask()); housekeeping->RegisterTask(new ThemeUpdateTask()); housekeeping->RegisterTask(new ArtworkTask()); housekeeping->RegisterTask(new MythFillDatabaseTask()); // only run this task if MythMusic is installed and we have a new enough schema if (gCoreContext->GetNumSetting("MusicDBSchemaVer", 0) >= 1024) housekeeping->RegisterTask(new RadioStreamUpdateTask()); } housekeeping->RegisterTask(new JobQueueRecoverTask()); #ifdef __linux__ #ifdef CONFIG_BINDINGS_PYTHON housekeeping->RegisterTask(new HardwareProfileTask()); #endif #endif housekeeping->Start(); } if (!cmdline.toBool("nojobqueue")) jobqueue = new JobQueue(ismaster); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- if (g_pUPnp == NULL) { g_pUPnp = new MediaServer(); g_pUPnp->Init(ismaster, cmdline.toBool("noupnp")); } // ---------------------------------------------------------------------- // Setup status server // ---------------------------------------------------------------------- HttpStatus *httpStatus = NULL; HttpServer *pHS = g_pUPnp->GetHttpServer(); if (pHS) { LOG(VB_GENERAL, LOG_INFO, "Main::Registering HttpStatus Extension"); httpStatus = new HttpStatus( &tvList, sched, expirer, ismaster ); pHS->RegisterExtension( httpStatus ); } mainServer = new MainServer( ismaster, port, &tvList, sched, expirer); int exitCode = mainServer->GetExitCode(); if (exitCode != GENERIC_EXIT_OK) { LOG(VB_GENERAL, LOG_CRIT, "Backend exiting, MainServer initialization error."); cleanup(); return exitCode; } if (httpStatus && mainServer) httpStatus->SetMainServer(mainServer); StorageGroup::CheckAllStorageGroupDirs(); if (gCoreContext->IsMasterBackend()) gCoreContext->SendSystemEvent("MASTER_STARTED"); #ifdef USING_SYSTEMD_NOTIFY // Provide systemd ready notification (for type=notify units) (void)sd_notify(0, "READY=1"); #endif /////////////////////////////// /////////////////////////////// exitCode = qApp->exec(); /////////////////////////////// /////////////////////////////// if (gCoreContext->IsMasterBackend()) { gCoreContext->SendSystemEvent("MASTER_SHUTDOWN"); qApp->processEvents(); } LOG(VB_GENERAL, LOG_NOTICE, "MythBackend exiting"); delete sysEventHandler; return exitCode; }
int run_backend(MythBackendCommandLineParser &cmdline) { if (!DBUtil::CheckTimeZoneSupport()) { LOG(VB_GENERAL, LOG_ERR, "MySQL time zone support is missing. " "Please install it and try again. " "See 'mysql_tzinfo_to_sql' for assistance."); return GENERIC_EXIT_DB_NOTIMEZONE; } bool ismaster = gCoreContext->IsMasterHost(); if (!UpgradeTVDatabaseSchema(ismaster, ismaster)) { LOG(VB_GENERAL, LOG_ERR, "Couldn't upgrade database to new schema"); return GENERIC_EXIT_DB_OUTOFDATE; } MythTranslation::load("mythfrontend"); if (!ismaster) { int ret = connect_to_master(); if (ret != GENERIC_EXIT_OK) return ret; } int port = gCoreContext->GetNumSetting("BackendServerPort", 6543); if (gCoreContext->GetSetting("BackendServerIP").isEmpty() && gCoreContext->GetSetting("BackendServerIP6").isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); if (ismaster) { LOG(VB_GENERAL, LOG_NOTICE, LOC + "Starting up as the master server."); } else { LOG(VB_GENERAL, LOG_NOTICE, LOC + "Running as a slave backend."); } print_warnings(cmdline); bool fatal_error = false; bool runsched = setupTVs(ismaster, fatal_error); if (fatal_error) { delete sysEventHandler; return GENERIC_EXIT_SETUP_ERROR; } Scheduler *sched = NULL; if (ismaster) { if (runsched) { sched = new Scheduler(true, &tvList); int err = sched->GetError(); if (err) return err; if (cmdline.toBool("nosched")) sched->DisableScheduling(); } if (!cmdline.toBool("nohousekeeper")) housekeeping = new HouseKeeper(true, ismaster, sched); if (!cmdline.toBool("noautoexpire")) { expirer = new AutoExpire(&tvList); if (sched) sched->SetExpirer(expirer); } gCoreContext->SetScheduler(sched); } else if (!cmdline.toBool("nohousekeeper")) { housekeeping = new HouseKeeper(true, ismaster, NULL); } if (!cmdline.toBool("nojobqueue")) jobqueue = new JobQueue(ismaster); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- if (g_pUPnp == NULL) { g_pUPnp = new MediaServer(); g_pUPnp->Init(ismaster, cmdline.toBool("noupnp")); } // ---------------------------------------------------------------------- // Setup status server // ---------------------------------------------------------------------- HttpStatus *httpStatus = NULL; HttpServer *pHS = g_pUPnp->GetHttpServer(); if (pHS) { LOG(VB_GENERAL, LOG_INFO, "Main::Registering HttpStatus Extension"); httpStatus = new HttpStatus( &tvList, sched, expirer, ismaster ); pHS->RegisterExtension( httpStatus ); } mainServer = new MainServer( ismaster, port, &tvList, sched, expirer); int exitCode = mainServer->GetExitCode(); if (exitCode != GENERIC_EXIT_OK) { LOG(VB_GENERAL, LOG_CRIT, "Backend exiting, MainServer initialization error."); cleanup(); return exitCode; } if (httpStatus && mainServer) httpStatus->SetMainServer(mainServer); StorageGroup::CheckAllStorageGroupDirs(); if (gCoreContext->IsMasterBackend()) gCoreContext->SendSystemEvent("MASTER_STARTED"); /////////////////////////////// /////////////////////////////// exitCode = qApp->exec(); /////////////////////////////// /////////////////////////////// if (gCoreContext->IsMasterBackend()) { gCoreContext->SendSystemEvent("MASTER_SHUTDOWN"); qApp->processEvents(); } LOG(VB_GENERAL, LOG_NOTICE, "MythBackend exiting"); delete sysEventHandler; return exitCode; }