summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth_mtc.py
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2013-12-26 20:13:40 (GMT)
committerBritney Fransen <brfransen@gmail.com>2013-12-26 20:13:40 (GMT)
commitaf515b99f692bcf1f0af57aabe8f7c1a950b32c5 (patch)
treed2cbd0bd7a159adac8ebc749e6c76d005ad4a42e /abs/core/LinHES-system/myth_mtc.py
parent45f667c9512475b4cb5c5290557dea854d056634 (diff)
parent816f6f419c662354f4224f8d82387fc27693b0fb (diff)
downloadlinhes_pkgbuild-af515b99f692bcf1f0af57aabe8f7c1a950b32c5.zip
linhes_pkgbuild-af515b99f692bcf1f0af57aabe8f7c1a950b32c5.tar.gz
linhes_pkgbuild-af515b99f692bcf1f0af57aabe8f7c1a950b32c5.tar.bz2
Merge branch 'testing'
Diffstat (limited to 'abs/core/LinHES-system/myth_mtc.py')
-rwxr-xr-xabs/core/LinHES-system/myth_mtc.py64
1 files changed, 46 insertions, 18 deletions
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py
index a5f02a0..7847313 100755
--- a/abs/core/LinHES-system/myth_mtc.py
+++ b/abs/core/LinHES-system/myth_mtc.py
@@ -5,6 +5,7 @@ import re
import socket
import os
import datetime,time
+import shlex
try:
from MythTV import MythBE
@@ -14,24 +15,33 @@ except:
#print mythtv.db.getSetting( 'Theme', socket.gethostname())
+def get_timestamp():
+ now = datetime.datetime.now()
+#date = "%s-%s-%s" %(now.year, now.month, now.day)
+ date = (now.strftime('%Y-%m-%d %H:%M'))
+ return date
+
+
def optimize():
+
try:
cursor = mythtv.db.cursor()
cursor.execute("SHOW tables")
result = cursor.fetchall()
except:
- print "Problem getting tables from database"
+ print " Problem getting tables from database"
return
ops=["REPAIR","OPTIMIZE","ANALYZE"]
for row in result:
ctable=row[0]
for op in ops:
- print op,ctable
+ print " %s %s" %(op,ctable)
cmd= "%s table %s" %(op,ctable)
cursor.execute(cmd)
def upcoming_check():
+ print " Checking for upcoming shows"
try:
upcoming = mythtv.getUpcomingRecordings()
except:
@@ -50,11 +60,12 @@ def upcoming_check():
if ( time_diff > 30) :
return True
else:
- print show , "is upcoming in " , time_diff
+ print " %s is upcoming in %s" %(show,time_diff)
return False
def schemalock_check():
+ print " Checking if schema is locked"
try:
c = mythtv.db.cursor()
c.execute("select count(*) from schemalock")
@@ -66,10 +77,11 @@ def schemalock_check():
if schemalock == 0:
return True
else:
- print "schema is locked"
+ print " schema is locked"
return False
def job_check():
+ print " Checking jobqueue"
try:
c = mythtv.db.cursor()
c.execute("select count(*) from jobqueue where status = 4")
@@ -80,11 +92,12 @@ def job_check():
if jobs == 0 :
return True
else:
- print " jobs are running"
+ print " jobs are running"
return False
def in_use():
+ print " Checking if programs are in use"
try:
c = mythtv.db.cursor()
c.execute("select count(*) from inuseprograms")
@@ -95,10 +108,11 @@ def in_use():
if prginuse == 0 :
return True
else:
- print "programs in use"
+ print " Programs in use"
return False
def mfd_check():
+ print " Checking is mythfilldatabase is running"
ps = subprocess.Popen("ps ax -o pid= -o args= ", shell=True, stdout=subprocess.PIPE)
ps_pid = ps.pid
output = ps.stdout.read()
@@ -110,50 +124,64 @@ def mfd_check():
if res:
pid = int(res[0][0])
if proc_name in res[0][1] and pid != os.getpid() and pid != ps_pid:
- print "mythfilldatabase is running"
+ print " mythfilldatabase is running"
return False
return True
+def bail_if_another_is_running():
+ cmd = shlex.split("pgrep -u {} -f {}".format(os.getuid(), __file__))
+ pids = subprocess.check_output(cmd).strip().split('\n')
+ if len(pids) > 1:
+ pids.remove("{}".format(os.getpid()))
+ print "Exiting! Found {} is already running (pids): {}".format(
+ __file__, " ".join(pids))
+ raise SystemExit(1)
def idle_check():
+ print "\n%s Checking Idle" %(get_timestamp())
if ( upcoming_check() and schemalock_check() and job_check() and in_use() and mfd_check() ):
idle=True
- print "Myth is idle"
+ print "\n%s Myth is idle" %(get_timestamp())
else:
idle=False
- print "Myth is NOT idle"
+ print "\n%s Myth is NOT idle" %(get_timestamp())
return idle
def run_stuff():
if idle_check():
- print "Running optimize"
+ print "\n#######################################"
+ print "\n%s Running Optimize" %(get_timestamp())
optimize()
- print "Running backup"
+ print "\n#######################################"
+ print "\n%s Running Backup" %(get_timestamp())
os.system('/usr/LH/bin/lh_system_backup_job')
- print "Running system_update"
- os.system('/usr/LH/bin/lh_system_host_update')
+ print "\n#######################################"
+ print "\n%s Running System Update" %(get_timestamp())
+ os.system('/usr/LH/bin/lh_system_host_update')
+
+ print "\n#######################################"
continue_loop=False
else:
continue_loop=True
return continue_loop
#---------------------------------
+bail_if_another_is_running()
starttime=time.time()
ctin=True
while ctin:
ctin=run_stuff()
if ctin:
+ print "\n%s Waiting 10 minutes before trying again." %(get_timestamp())
time.sleep(600)
+
current_time=time.time()
- if (current_time - starttime) > 10800 :
+ if (current_time - starttime) > 3000 :
ctin = False
- print "time exceeded (3 hours)"
+ print "\n%s Time Exceeded 50 minutes. Quitting.)" %(get_timestamp())
exit(1)
-
-
-