summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-system/myth_mtc.py
diff options
context:
space:
mode:
authorBritney Fransen <brfransen@gmail.com>2013-12-12 20:26:55 (GMT)
committerBritney Fransen <brfransen@gmail.com>2013-12-12 20:26:55 (GMT)
commitb97e90ff739fa2f7d27ed5c62ae8436c6ce2bb8d (patch)
treebc9551882ded56ac8fdb0ea27025fbcc06b1790b /abs/core/LinHES-system/myth_mtc.py
parent5f58ea928f87bc20e8bb8102f8ce6272d3d6fc47 (diff)
downloadlinhes_pkgbuild-b97e90ff739fa2f7d27ed5c62ae8436c6ce2bb8d.zip
linhes_pkgbuild-b97e90ff739fa2f7d27ed5c62ae8436c6ce2bb8d.tar.gz
linhes_pkgbuild-b97e90ff739fa2f7d27ed5c62ae8436c6ce2bb8d.tar.bz2
LinHES-system: change myth_mtc.py to run in cron hourly to run more reliably after system is down or is busy.
Diffstat (limited to 'abs/core/LinHES-system/myth_mtc.py')
-rwxr-xr-xabs/core/LinHES-system/myth_mtc.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/abs/core/LinHES-system/myth_mtc.py b/abs/core/LinHES-system/myth_mtc.py
index 2c1fd14..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
@@ -34,7 +35,7 @@ def optimize():
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)
@@ -128,10 +129,18 @@ def mfd_check():
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 "%s Checking idle" %(get_timestamp())
+ 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 "\n%s Myth is idle" %(get_timestamp())
@@ -142,35 +151,37 @@ def idle_check():
def run_stuff():
if idle_check():
- print "\n%sRunning optimize" %(get_timestamp())
+ print "\n#######################################"
+ print "\n%s Running Optimize" %(get_timestamp())
optimize()
- print "\n%s Running backup" %(get_timestamp())
+ print "\n#######################################"
+ print "\n%s Running Backup" %(get_timestamp())
os.system('/usr/LH/bin/lh_system_backup_job')
- print "\n%s Running system update" %(get_timestamp())
- 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()
- print "\n"
if ctin:
- print "%s Waiting 10 minutes before trying again" %(get_timestamp())
+ 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)
-
-
-