Ticket #4184: 4184 mythtv-setup-autorestartbackend-29122007.2.patch
File 4184 mythtv-setup-autorestartbackend-29122007.2.patch, 10.7 KB (added by , 16 years ago) |
---|
-
libs/libmyth/mythcontext.cpp
34 34 #include "util-x11.h" 35 35 #include "mythsocket.h" 36 36 #include "themeinfo.h" 37 #include "util.h" 37 38 38 39 #include "libmythui/mythmainwindow.h" 39 40 #include "libmythupnp/mythxmlclient.h" … … 1518 1519 bool blockingClient) 1519 1520 { 1520 1521 MythSocket *serverSock = NULL; 1522 MythBusyDialog *busy = NULL; 1521 1523 int cnt = 1; 1524 1525 bool enableGUI=false; 1526 if(GetMainWindow()) 1527 enableGUI=true; 1528 else 1529 enableGUI=false; 1522 1530 1523 1531 int sleepTime = GetNumSetting("WOLbackendReconnectWaitTime", 0); 1524 1532 int maxConnTry = GetNumSetting("WOLbackendConnectRetry", 1); … … 1557 1565 manageLock = true; 1558 1566 d->serverSockLock.unlock(); 1559 1567 } 1560 MythPopupBox::showOkPopup(d->mainWindow, 1568 if (GetMainWindow()) 1569 MythPopupBox::showOkPopup(d->mainWindow, 1561 1570 "connection failure", 1562 1571 tr("Could not connect to the " 1563 1572 "master backend server -- is " … … 1573 1582 } 1574 1583 else 1575 1584 { 1585 QString wol_cmd; 1586 QString waitString=QObject::tr("Waiting for Server..."); 1587 1588 if (GetMainWindow()) 1589 { 1590 busy = new MythBusyDialog(waitString); 1591 busy->start(1); 1592 } 1593 1576 1594 VERBOSE(VB_GENERAL, "Trying to wake up the MasterBackend " 1577 1595 "now."); 1578 QString wol_cmd = GetSetting("WOLbackendCommand", 1579 "echo \'would run the " 1580 "WakeServerCommand now, if " 1581 "set!\'"); 1582 myth_system(wol_cmd); 1583 1584 VERBOSE(VB_GENERAL, QString("Waiting for %1 seconds until I " 1585 "try to reconnect again.") 1586 .arg(sleepTime)); 1587 sleep(sleepTime); 1596 1597 /* If this is run from the master backend, use local command 1598 * to start backend (eg. /etc/init.d/mythtv-backend start). 1599 * Otherwise use WakeOnLan command to start backend remotely. 1600 */ 1601 if (gContext->IsMasterHost()) 1602 wol_cmd = GetSetting("MythbackendStartCommand", 1603 "mythbackend"); 1604 else 1605 wol_cmd = GetSetting("WOLbackendCommand", 1606 "echo \'would run the WakeServerCommand now, " 1607 "if set!\'"); 1608 1609 // Don't restart the backend if setup is running 1610 if ( ! isRunning("mythtv-setup") ) 1611 { 1612 //busy->setLabel(waitString); 1613 system(wol_cmd.ascii()); 1614 cout << wol_cmd.ascii(); 1615 } 1616 //else 1617 // busy->setLabel(QObject::tr("Setup is Running. Not restarting backend until setup is finished!")); 1618 1619 VERBOSE(VB_GENERAL, QString("Waiting for %1 seconds before I send wake command again.") 1620 .arg(sleepTime)); 1621 1622 int sleepCount = 0; 1623 serverSock = new MythSocket(); 1624 while (!serverSock->connect(hostname, port)) 1625 { 1626 sleep(1); 1627 sleepCount++; 1628 if (sleepCount > sleepTime) 1629 break; 1630 } 1631 serverSock->DownRef(); 1632 serverSock = NULL; 1588 1633 ++cnt; 1589 } 1590 d->attemptingToConnect = false; 1634 if (GetMainWindow()) 1635 { 1636 busy->Close(); 1637 busy->deleteLater(); 1638 } 1639 } 1640 d->attemptingToConnect = false; 1591 1641 } 1592 1642 else 1593 1643 break; -
programs/mythtv-setup/main.cpp
294 294 gContext->UpdateImageCache(); 295 295 MythThemeBase *themeBase = new MythThemeBase(); 296 296 (void) themeBase; 297 DialogBox *dia = NULL; 298 QString stCmd; 299 int val = 0; 297 300 298 301 LanguageSettings::prompt(); 299 302 LanguageSettings::load("mythfrontend"); … … 302 305 QObject::tr("WARNING") + ": " + 303 306 QObject::tr("MythTV has detected that the backend is running.")+"\n\n"+ 304 307 QObject::tr("Changing existing card inputs, deleting anything, " 305 "or scanning for channels may not work."); 306 307 bool backendIsRunning = gContext->BackendIsRunning(); 308 309 if (backendIsRunning) 308 "or scanning for channels may not work.")+"\n\n"+ 309 QObject::tr("It is strongly advised that you stop the backend whilst running setup!"); 310 311 bool restartBackend=false; 312 313 // Offer to stop the backend if sensible 314 if (gContext->BackendIsRunning() && gContext->IsMasterHost()) 310 315 { 311 DialogCode val = MythPopupBox::Show2ButtonPopup( 312 mainWindow, QObject::tr("WARNING"), warn, 313 QObject::tr("Continue"), 314 QObject::tr("Exit"), kDialogCodeButton0); 315 316 if (kDialogCodeButton1 == val) 317 return 0; 316 dia = new DialogBox(mainWindow, warn); 317 dia->AddButton(QObject::tr("Stop backend and continue")); 318 dia->AddButton(QObject::tr("Continue anyway")); 319 dia->AddButton(QObject::tr("Exit")); 320 val = dia->exec(); 321 dia->deleteLater(); 322 323 if (val == kDialogCodeButton0) // Stop Backend 324 { 325 stCmd = gContext->GetSetting("MythbackendStopCommand", "killall mythbackend"); 326 if (!stCmd.isEmpty()) 327 myth_system(stCmd); 328 restartBackend=true; 329 } 330 else if (val == kDialogCodeButton1) // Continue anyway 331 { 332 restartBackend=false; 333 } 334 else // Exit 335 { 336 return 1; 337 } 318 338 } 319 339 320 340 REG_KEY("qt", "DELETE", "Delete", "D"); -
programs/mythtv-setup/backendsettings.cpp
REG_KEY("qt", "EDIT", "Edit", "E"); - DialogBox *dia = NULL; bool haveProblems = false; do { @@ -355,19 +374,34 @@ } while (haveProblems); + // Start backend + if (restartBackend) + { + stCmd = gContext->GetSetting("MythbackendStartCommand", "mythbackend"); + if (!stCmd.isEmpty()) + myth_system(stCmd); + } + if (gContext->IsMasterHost()) { dia = new DialogBox(mainWindow, - QObject::tr("If this is the master backend server, " - "please run 'mythfilldatabase' " - "to populate the database " - "with channel information.")); - dia->AddButton(QObject::tr("OK")); - dia->exec(); + QObject::tr("Run 'mythfilldatabase' to populate the database " + "with channel information?")+"\n\n"+ + QObject::tr("(Not required if you are using off-air information only, " + "such as on DVB).")); + dia->AddButton(QObject::tr("No, just exit")); + dia->AddButton(QObject::tr("Yes, run mythfilldatabase")); + val = dia->exec(); dia->deleteLater(); + if (val == 1) + { + stCmd = gContext->GetSetting("MythFillDatabasePath", "mythfilldatabase"); + if (!stCmd.isEmpty()) + myth_system(stCmd); + } } - if (backendIsRunning) + if (gContext->BackendIsRunning()) RemoteSendMessage("CLEAR_SETTINGS_CACHE"); return 0;
356 356 static GlobalLineEdit *WOLbackendCommand() 357 357 { 358 358 GlobalLineEdit *gc = new GlobalLineEdit("WOLbackendCommand"); 359 gc->setLabel(QObject::tr("W ake Command"));359 gc->setLabel(QObject::tr("WOL Wake Command")); 360 360 gc->setValue(""); 361 361 gc->setHelpText(QObject::tr("The command used to wake up your master " 362 "backend server \n(eg. sudo /etc/init.d/mythtv-backend restart)."));362 "backend server from another machine.\n (Leave blank to disable).")); 363 363 return gc; 364 364 }; 365 365 … … 369 369 gc->setLabel(QObject::tr("Wake command")); 370 370 gc->setValue(""); 371 371 gc->setHelpText(QObject::tr("The command used to wakeup your slave " 372 "backends. Leave empty to disable."));372 "backends.\n (Leave blank to disable).")); 373 373 return gc; 374 374 }; 375 375 376 static GlobalLineEdit *MythbackendStopCommand() 377 { 378 GlobalLineEdit *gc = new GlobalLineEdit("MythbackendStopCommand"); 379 gc->setLabel(QObject::tr("Backend Stop Command")); 380 gc->setValue("killall mythbackend"); 381 gc->setHelpText(QObject::tr("The command used to stop the backend when running on " 382 "the master backend server\n(eg. sudo /etc/init.d/mythtv-backend stop).")); 383 return gc; 384 }; 385 386 static GlobalLineEdit *MythbackendStartCommand() 387 { 388 GlobalLineEdit *gc = new GlobalLineEdit("MythbackendStartCommand"); 389 gc->setLabel(QObject::tr("Backend Start Command")); 390 gc->setValue("mythbackend"); 391 gc->setHelpText(QObject::tr("The command used to start the backend when running on " 392 "the master backend server\n(eg. sudo /etc/init.d/mythtv-backend start).")); 393 return gc; 394 }; 395 376 396 static GlobalSpinBox *idleTimeoutSecs() 377 397 { 378 398 GlobalSpinBox *gc = new GlobalSpinBox("idleTimeoutSecs", 0, 1200, 5); … … 723 743 backend->addChild(WOLbackendReconnectWaitTime()); 724 744 backend->addChild(WOLbackendConnectRetry()); 725 745 backend->addChild(WOLbackendCommand()); 746 backend->addChild(MythbackendStopCommand()); 747 backend->addChild(MythbackendStartCommand()); 726 748 group4->addChild(backend); 727 749 728 750 VerticalConfigurationGroup* slaveBackend = new VerticalConfigurationGroup();