Changeset 4866


Ignore:
Timestamp:
May 23, 2017, 10:19:41 AM (2 years ago)
Author:
mabarracus
Message:

Fix race condition that stops sending messages when time changes
Optimize subprocessing calls
Better flavour detection

Location:
lliurex-statistics/trunk/fuentes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lliurex-statistics/trunk/fuentes/debian/changelog

    r3623 r4866  
     1lliurex-statistics (0.4-7) xenial; urgency=medium
     2
     3  * Fix race condition that stops sending messages when time changes
     4  * Optimize subprocessing calls
     5  * Better flavour detection
     6
     7 -- M.Angel Juan <m.angel.juan@gmail.com>  Tue, 23 May 2017 10:17:58 +0200
     8
    19lliurex-statistics (0.4-6) xenial; urgency=medium
    210
  • lliurex-statistics/trunk/fuentes/lliurex-statistics.install/usr/sbin/analytics

    r3456 r4866  
    1717import lockfile
    1818import xmlrpclib
     19import time
    1920
    2021######### END CONFIG ###########
     
    4647#
    4748def sig_handler(sig,frame):
    48     global t,LIST
     49    global t,LIST,RUNNER
    4950    debug("Aborting...")
     51    RUNNER=0
    5052    try:
    5153        # Cancel threads
     
    108110
    109111def allow_send():
    110     answer = check_server_acknowledge()
    111     if answer == '1':
    112         debug("allow_send stats by check server acknowledge")
    113         return True
    114     if answer == '0':
    115         debug("deny allow_send stats by check server acknowledge")
    116         return False
    117    
     112    global SABOR
     113
     114    if SABOR.lower() != 'server':
     115        answer = check_server_acknowledge()
     116        if answer == '1':
     117            debug("allow_send stats by check server acknowledge")
     118            return True
     119        if answer == '0':
     120            debug("deny allow_send stats by check server acknowledge")
     121            return False
     122
    118123    answer = check_local_acknowledge()
    119124    if answer == "yes":
     
    172177        global TIMEOUT
    173178        global BDTIMEOUT
    174 
    175         # Flush in-memory data to file db when expires timeout
    176         if ctimeout > TIMEOUT:
     179        global RUNNER
     180       
     181        while RUNNER == 1:
     182            # Flush in-memory data to file db when expires timeout
     183            if ctimeout > TIMEOUT:
    177184                update_db()
    178185                ctimeout=0
    179         else:
     186            else:
    180187                ctimeout+=1
    181188
    182         # Call send-data to server when expires dbtimeout
    183         if btimeout > BDTIMEOUT:
     189            # Call send-data to server when expires dbtimeout
     190            if btimeout > BDTIMEOUT:
    184191                clean_and_send();
    185192                btimeout=0
    186         else:
     193            else:
    187194                btimeout+=1
    188         debug('.',2)
    189 
    190         # Reload 1 sec timeout
    191         t=threading.Timer(1.0,runner)
    192 #        De-comment to allow stop threads inmediately
    193 #        t.daemon = True
    194         t.start()
     195            debug('.',2)
     196            time.sleep(1.0)
     197            # Reload 1 sec timeout
     198            #t=threading.Timer(1.0,runner)
     199#           De-comment to allow stop threads inmediately
     200#           t.daemon = True
     201            #t.start()
    195202#END def runner():
    196203
     
    263270#
    264271def send_data():
     272    global SABOR
     273    global RELEASE
     274
    265275    # Calculates mac address
    266276    f = open('/sys/class/net/eth0/address','r');
     
    280290    except:
    281291        return;
     292   
    282293    # Get version and flavour
    283     p=subprocess.Popen(['lliurex-version','-n'],stdout=subprocess.PIPE)
    284     out,err=p.communicate()
    285     version=out.strip();
    286 
    287     p=subprocess.Popen(['lliurex-version','-v'],stdout=subprocess.PIPE)
    288     out,err=p.communicate()
    289     sabor=out.strip();
     294    #p=subprocess.Popen(['lliurex-version','-n'],stdout=subprocess.PIPE)
     295    #out,err=p.communicate()
     296    #version=out.strip();
     297    version=RELEASE
     298
     299    #p=subprocess.Popen(['lliurex-version','-f'],stdout=subprocess.PIPE)
     300    #out,err=p.communicate()
     301    #sabor=out.strip();
     302    sabor=SABOR
    290303
    291304    # Send json encoded data to server
     
    474487ctimeout=0
    475488btimeout=0
     489RUNNER=1
    476490
    477491# Get configuration parameters
     
    507521
    508522debug("filename="+filename+' next='+next_filename)
     523
     524p=subprocess.Popen(['lliurex-version','-n'],stdout=subprocess.PIPE)
     525RELEASE,err=p.communicate()
     526RELEASE=RELEASE.strip()
     527if RELEASE[0:2] == '15':
     528    VERSION_GETTER='lliurex-detect'
     529else:
     530    VERSION_GETTER='lliurex-version'
     531
     532
     533p=subprocess.Popen([VERSION_GETTER,'-f'],stdout=subprocess.PIPE)
     534SABOR,err=p.communicate()
     535SABOR=SABOR.strip()
     536
     537debug('Starting on '+SABOR+' '+RELEASE)
    509538try:
    510539     px= subprocess.Popen(["bash","-c","source /etc/profile && echo $http_proxy"],stdout=subprocess.PIPE)
    511540     proxy=px.stdout.readline().strip()
    512      debug('Detected proxy: '+str(proxy))
     541     if str(proxy) != '':
     542        debug('Detected proxy: '+str(proxy))
    513543except Exception as e:
    514544     debug('Error getting proxy '+str(e))
Note: See TracChangeset for help on using the changeset viewer.