Ticket #4184: 4184 mythtv-setup-autorestartbackend-29122007.2.patch

File 4184 mythtv-setup-autorestartbackend-29122007.2.patch, 10.7 KB (added by Matthew Wire <devel@…>, 16 years ago)

Apply cleanly and compile :)

  • libs/libmyth/mythcontext.cpp

     
    3434#include "util-x11.h"
    3535#include "mythsocket.h"
    3636#include "themeinfo.h"
     37#include "util.h"
    3738
    3839#include "libmythui/mythmainwindow.h"
    3940#include "libmythupnp/mythxmlclient.h"
     
    15181519                                       bool blockingClient)
    15191520{
    15201521    MythSocket *serverSock = NULL;
     1522    MythBusyDialog *busy = NULL;
    15211523    int cnt = 1;
     1524   
     1525    bool enableGUI=false;
     1526    if(GetMainWindow())
     1527        enableGUI=true;
     1528    else
     1529        enableGUI=false;
    15221530
    15231531    int sleepTime = GetNumSetting("WOLbackendReconnectWaitTime", 0);
    15241532    int maxConnTry = GetNumSetting("WOLbackendConnectRetry", 1);
     
    15571565                        manageLock = true;
    15581566                        d->serverSockLock.unlock();
    15591567                    }
    1560                     MythPopupBox::showOkPopup(d->mainWindow,
     1568                    if (GetMainWindow())
     1569                        MythPopupBox::showOkPopup(d->mainWindow, 
    15611570                                              "connection failure",
    15621571                                              tr("Could not connect to the "
    15631572                                                 "master backend server -- is "
     
    15731582            }
    15741583            else
    15751584            {
     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
    15761594                VERBOSE(VB_GENERAL, "Trying to wake up the MasterBackend "
    15771595                                    "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;                       
    15881633                ++cnt;
    1589             }
    1590             d->attemptingToConnect = false;
     1634                if (GetMainWindow())
     1635                {
     1636                    busy->Close();
     1637                    busy->deleteLater();
     1638                }
     1639           }
     1640           d->attemptingToConnect = false;
    15911641        }
    15921642        else
    15931643            break;
  • programs/mythtv-setup/main.cpp

     
    294294    gContext->UpdateImageCache();
    295295    MythThemeBase *themeBase = new MythThemeBase();
    296296    (void) themeBase;
     297    DialogBox *dia = NULL;
     298    QString stCmd;
     299    int val = 0;
    297300
    298301    LanguageSettings::prompt();
    299302    LanguageSettings::load("mythfrontend");
     
    302305        QObject::tr("WARNING") + ": " +
    303306        QObject::tr("MythTV has detected that the backend is running.")+"\n\n"+
    304307        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())
    310315    {
    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        }
    318338    }
    319339
    320340    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;
     
    356356static GlobalLineEdit *WOLbackendCommand()
    357357{
    358358    GlobalLineEdit *gc = new GlobalLineEdit("WOLbackendCommand");
    359     gc->setLabel(QObject::tr("Wake Command"));
     359    gc->setLabel(QObject::tr("WOL Wake Command"));
    360360    gc->setValue("");
    361361    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)."));
    363363    return gc;
    364364};
    365365
     
    369369    gc->setLabel(QObject::tr("Wake command"));
    370370    gc->setValue("");
    371371    gc->setHelpText(QObject::tr("The command used to wakeup your slave "
    372                     "backends. Leave empty to disable."));
     372                    "backends.\n (Leave blank to disable)."));
    373373    return gc;
    374374};
    375375
     376static 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
     386static 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
    376396static GlobalSpinBox *idleTimeoutSecs()
    377397{
    378398    GlobalSpinBox *gc = new GlobalSpinBox("idleTimeoutSecs", 0, 1200, 5);
     
    723743    backend->addChild(WOLbackendReconnectWaitTime());
    724744    backend->addChild(WOLbackendConnectRetry());
    725745    backend->addChild(WOLbackendCommand());
     746    backend->addChild(MythbackendStopCommand());
     747    backend->addChild(MythbackendStartCommand());
    726748    group4->addChild(backend);
    727749   
    728750    VerticalConfigurationGroup* slaveBackend = new VerticalConfigurationGroup();