Index: src/MythTV_PlugIn/MythTvInitialFillDB.sh
===================================================================
--- src/MythTV_PlugIn/MythTvInitialFillDB.sh (revision 20536)
+++ src/MythTV_PlugIn/MythTvInitialFillDB.sh (working copy)
@@ -1,13 +1,21 @@
#!/bin/bash
+echo $0 start `date`
+
. /usr/pluto/bin/Config_Ops.sh
. /usr/pluto/bin/MythTvCommon.sh
+# This sets a timestamp which prevents MythTvDailyFillDB.sh from taking the lock..
+# We do this a few times in case this takes a while..
+SetMythTvInitialFillDBRun
+
# Lock the MythFillDatabase lock to another script from running mythfilldatabase
-echo "MythTvInitialFillDB.sh waiting for MythFillDatabase lock"
+echo "$0 waiting for MythFillDatabase lock"
WaitLock "MythFillDatabase" "MythTvInitialFillDB.sh" nolog
-echo "MythTvInitialFillDB.sh got MythFillDatabase lock"
+echo "$0 got MythFillDatabase lock"
+SetMythTvInitialFillDBRun
+
# lock schema, this makes sure that we don't run this while the DB schema is
# being upgraded by another mythtv process.
echo "LOCK TABLE schemalock WRITE; UNLOCK TABLES;" | $MYSQLPIPE
@@ -15,12 +23,18 @@
# Make sure mythfilldatabase log is owned by mythtv user
touch $FILLDB_LOG ; chown mythtv:mythtv $FILLDB_LOG
+SetMythTvInitialFillDBRun
+
# Download today's scheduling data, so that we can tune LiveTV immediately
$FILLDB --refresh-today --max-days 1 >> $FILLDB_LOG
+SetMythTvInitialFillDBRun
+
# Download the channel icons
DownloadChannelIcons >> $FILLDB_LOG
+SetMythTvInitialFillDBRun
+
# Send a sync command to fix up the directories
/usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 824
@@ -31,15 +45,17 @@
/usr/pluto/bin/Restart_Backend_With_SchemaLock.sh
# Tell the user it's now safe to use MythTV
-R=$(echo "SELECT * FROM videosource LIMIT 1" | $MYSQL_WITH_COL)
+R=$(echo "SELECT * FROM videosource LIMIT 1" | $MYSQLPIPE_WITH_COL)
if [[ -n "$R" ]]; then
- # Notify all the orbiters that myth is ready to be used
+ echo Notify all the orbiters that myth is ready to be used
/usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 12 1 406 9 \
"MythTV is ready. However it may take several more minutes before the guide data is fully populated." 102 300
/usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 910 9 \
"Finished retrieving channels"
fi
+SetMythTvInitialFillDBRun
+
# Unlock the MythFillDatabase lock
Unlock "MythFillDatabase" "MythTvInitialFillDB.sh" nolog
@@ -47,3 +63,5 @@
if test x"" != x"$HAS_IGNORE_BACKEND" ; then
$BACKEND --resched > /dev/null &
fi
+
+echo $0 end `date`
Index: src/MythTV_PlugIn/MythTvDailyFillDB.sh
===================================================================
--- src/MythTV_PlugIn/MythTvDailyFillDB.sh (revision 20536)
+++ src/MythTV_PlugIn/MythTvDailyFillDB.sh (working copy)
@@ -1,15 +1,24 @@
#!/bin/bash
+echo $0 start `date`
+
. /usr/pluto/bin/Config_Ops.sh
. /usr/pluto/bin/MythTvCommon.sh
# Append all params..
FILLDB=$FILLDB" $@"
+# Before we lock, make sure MythTVInitialFillDB.sh was not run recently.
+# This is so that we don't start this until the user has finished
+# configuring MythTV in the configuration Wizard. By checking this
+# before we lock we make sure we're not running this script when
+# MythTVInitialFillDB.sh needs to be rerun.
+WaitUntilMythTvInitialRunXMinutesOld 10
+
# Lock the MythFillDatabase lock to another script from running mythfilldatabase
-echo "MythTvDailyFillDB.sh waiting for MythFillDatabase lock"
+echo "$0 waiting for MythFillDatabase lock"
WaitLock "MythFillDatabase" "MythTvDailyFillDB.sh" nolog
-echo "MythTvDailyFillDB.sh got MythFillDatabase lock"
+echo "$0 got MythFillDatabase lock"
# lock schema, this makes sure that we don't run this while the DB schema is
# being upgraded by another mythtv process.
@@ -43,4 +52,6 @@
# if channels were added we need to redownload channel icons
if [ x"$CHAN_COUNT_BFR" != x"$CHAN_COUNT_AFT" ] ; then
DownloadChannelIcons
-fi
\ No newline at end of file
+fi
+
+echo $0 end `date`
Index: src/MythTV_PlugIn/MythTvCommon.sh
===================================================================
--- src/MythTV_PlugIn/MythTvCommon.sh (revision 20536)
+++ src/MythTV_PlugIn/MythTvCommon.sh (working copy)
@@ -11,6 +11,7 @@
FILLDB=/usr/bin/mythfilldatabase
FILLDB_LOG=/var/log/mythtv/mythfilldatabase.log
+FILLDBINITRUN=/tmp/MythTvInitialFillDBRun
# If the user installed a their own mythfilldatabase, adjust..
if test -f /usr/local/bin/mythfilldatabase ; then
@@ -138,4 +139,46 @@
# Tell MythTV that the channel icons have been moved.
echo "UPDATE channel SET icon=REPLACE(icon,'$DIR','/home/mythtv')" | $MYSQLPIPE
-}
\ No newline at end of file
+}
+
+function SetMythTvInitialFillDBRun {
+ touch $FILLDBINITRUN ; chown mythtv:mythtv $FILLDBINITRUN
+ date +%s > $FILLDBINITRUN
+}
+
+function WaitUntilMythTvInitialRunXMinutesOld {
+ STARTTIME=`date +%s`
+ if [ -r $FILLDBINITRUN -a -s $FILLDBINITRUN ] ; then
+ STARTTIME=$(cat $FILLDBINITRUN)
+ fi
+
+ MINS="$1"
+ if [ x"$MINS" = x"" ] ; then
+ MINS=10
+ fi
+ SECS=$(echo $MINS \* 60 | bc)
+
+ ENDTIME=$(echo $STARTTIME + $SECS | bc)
+
+ NOW=`date +%s`
+ if [ $ENDTIME -gt $NOW ] ; then
+ TIMETOWAIT=$(echo $ENDTIME - $NOW | bc)
+ if [ $TIMETOWAIT -gt 60 ] ; then
+ echo Waiting $TIMETOWAIT seconds before starting..
+ echo We do not want to start until it has been
+ echo $MINS minutes since the MythTV channel download.
+ fi
+ while [ $ENDTIME -gt `date +%s` ] ; do
+ sleep 1
+ done
+
+ # in case end time changed, redo if we waited more
+ # than a few seconds
+ if $TIMETOWAIT -gt 5 ; then
+ WaitUntilMythTvInitialRunXMinutesOld $MINS
+ fi
+ fi
+
+ echo WaitUntilMythTvInitialRunXMinutesOld done
+}
+