From b1228a681e74db2c56d97e5489fa01c4f649ade4 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Thu, 20 Dec 2012 11:54:57 -0600
Subject: LinHES-system: add be_check.py and modify LinHES-session to use it.
 This will stop mythfrontend/mythwelcome from starting if be_check can't
 connect to the master backend. Mostly this was done to stop mythfronted from
 complaining about not being able to contact the MBE and in the worst case
 displaying  the DB connection configuration screen.

refs #886
---
 abs/core/LinHES-system/LinHES-session | 15 +++++++++++++--
 abs/core/LinHES-system/PKGBUILD       | 10 ++++++----
 abs/core/LinHES-system/be_check.py    | 29 +++++++++++++++++++++++++++++
 abs/core/LinHES-system/myth_status.py |  2 +-
 4 files changed, 49 insertions(+), 7 deletions(-)
 create mode 100644 abs/core/LinHES-system/be_check.py

diff --git a/abs/core/LinHES-system/LinHES-session b/abs/core/LinHES-system/LinHES-session
index a5632fd..d55b900 100755
--- a/abs/core/LinHES-system/LinHES-session
+++ b/abs/core/LinHES-system/LinHES-session
@@ -317,10 +317,21 @@ function start_myth() {
 
     echo "====================================================================="
     echo "Starting $STARTCMD"
-    #firstboot.sh &
+    if [ "x$bewait" = "x1" ]
+    then
+        #do init check
+        /usr/LH/bin/be_check.py
+        rc=$?
+        while [ $rc -ne 0 ]
+        do
+            msg "Waiting for connection to MythBackend"
+            /usr/LH/bin/be_check.py
+            rc=$?
+            sleep 6
+        done
+    fi
 
     #continue on with starting mythtv
-
     if [ x$STARTUP_STYLE = xenhanced ]
     then
         start_myth_mv
diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index 61ea2f2..e4e26d4 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-system
 pkgver=2
-pkgrel=129
+pkgrel=131
 arch=('i686' 'x86_64')
 MVDIR=$startdir/pkg/usr/LH
 BINDIR=$startdir/pkg/usr/bin
@@ -30,7 +30,8 @@ binfiles="LinHES-start optimize_mythdb.py
  misc_status_info.sh
  misc_upcoming_recordings.pl
  misc_which_recorder.pl
- change_channel.sh change_channel_wrapper.sh"
+ change_channel.sh change_channel_wrapper.sh
+ be_check.py"
 
 source=(LinHES-session
     LinHES-profile.sh $binfiles
@@ -79,7 +80,7 @@ build() {
 
 
 }
-md5sums=('d35912d6b6b267bc6616205fa4776833'
+md5sums=('d275db0a946087671e0c2014dac9ed22'
          '5881bdb43d578ec3a79d1f77ea58a3db'
          'a875ee97f86e46f34a741c2bc455f894'
          '76b2637cac0452b3acdbeeb4e8a5474b'
@@ -91,7 +92,7 @@ md5sums=('d35912d6b6b267bc6616205fa4776833'
          '542e670e78d117657f93141e9689f54d'
          '41951459ea9d2b0567be521b67e6285a'
          '659c0a55b0b375c48fcd751252dd2102'
-         '309638acf596ce3c790aa2bf5c7c9880'
+         '692563448cca1d49f45e7d1c8abcaa0c'
          '962a3e9eaba2d1466251b7ab0956705d'
          '1758aed160de64abfafb28a3a8f3390e'
          '2200f08381370f6ae553e13a9f376377'
@@ -117,6 +118,7 @@ md5sums=('d35912d6b6b267bc6616205fa4776833'
          '116b0f62ed4e8dd6e437930deeb6e49e'
          '17f678d37187be0f12d67f64e40429c6'
          'bacc813b48bafcc6fe906e5969930501'
+         'd6d11865317d13f3e2a313980108736b'
          'eb879fee9603a05d5420d4ce8ed9e450'
          '6782771960c495aeb597893f37d1e5ee'
          '84492954db16740f949d795b74383189'
diff --git a/abs/core/LinHES-system/be_check.py b/abs/core/LinHES-system/be_check.py
new file mode 100644
index 0000000..91c39dc
--- /dev/null
+++ b/abs/core/LinHES-system/be_check.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python2
+#simple program to check if mythbackend is up and running
+#exit code of 0 is success, anything else means it can't connect
+import sys
+class Logger(object):
+    def __init__(self, filename="/tmp/Default.log"):
+        #self.terminal = sys.stdout
+        self.log = open(filename, "a")
+
+    def write(self, message):
+        #self.terminal.write(message)
+        self.log.write(message)
+
+sys.stdout = Logger("/tmp/be_check.log")
+
+
+from MythTV import MythBE,MythDB
+#import datetime,time,sys,subprocess
+
+
+
+
+
+try:
+    be=MythBE()
+    db = MythDB()
+except:
+    sys.exit(1)
+sys.exit(0)
\ No newline at end of file
diff --git a/abs/core/LinHES-system/myth_status.py b/abs/core/LinHES-system/myth_status.py
index da43679..2e48024 100644
--- a/abs/core/LinHES-system/myth_status.py
+++ b/abs/core/LinHES-system/myth_status.py
@@ -5,7 +5,7 @@ try:
     be=MythBE()
     db = MythDB()
 except:
-    print "Couldn't connect to MythTV service for status"
+    print "\nCouldn't connect to MythTV service for status"
     sys.exit(1)
 
 cursor = db.cursor()
-- 
cgit v0.12

