Changeset 6929 for lliurex-statistics


Ignore:
Timestamp:
Feb 28, 2018, 10:32:41 AM (20 months ago)
Author:
mabarracus
Message:

Fix bugs

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

Legend:

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

    r6927 r6929  
     1lliurex-statistics (0.5.1) xenial; urgency=medium
     2
     3  * Fix bugs
     4
     5 -- M.Angel Juan <m.angel.juan@gmail.com>  Wed, 28 Feb 2018 10:29:11 +0100
     6
    17lliurex-statistics (0.5-2) xenial; urgency=medium
    28
  • lliurex-statistics/trunk/fuentes/debian/lliurex-statistics.postinst

    r6816 r6929  
    77
    88. /usr/share/debconf/confmodule
     9db_get lliurex-statistics/acknowledge
     10ACK="$RET"
     11db_stop
    912
    1013# summary of how this script can be called:
     
    5861            # AVOID TO RESTART !! Could block ltsp's chroot builder
    5962            #service auditd restart
     63           
     64            #DEBCONF
     65            ACKNOWLEDGE="$(echo $ACK|egrep -E -i -o 'true|false')"
     66            if [ "$ACKNOWLEDGE" = "true" ]; then
     67                echo yes > /etc/lliurex-analytics/status
     68            fi
     69            if [ "$ACKNOWLEDGE" = "false" ]; then
     70                echo no > /etc/lliurex-analytics/status
     71            fi
    6072    ;;
    6173   
  • lliurex-statistics/trunk/fuentes/lliurex-statistics.install/usr/sbin/analytics

    r6927 r6929  
    201201    global log
    202202
    203     output = bin_to_ascii(subprocess.check_output(['lliurex-version', '-n']))
     203    output = bin_to_ascii(subprocess.check_output(['bash','lliurex-version','-n']))
    204204    release = output[0:2].strip()
    205205    if release == '15':
    206         use = 'lliurex-detect'
     206        use = ['lliurex-detect','-f']
     207        output = bin_to_ascii(subprocess.check_output(use))
    207208    else:
    208         use = 'lliurex-version'
    209     output = bin_to_ascii(subprocess.check_output([use, '-f']))
     209        use = ['bash','lliurex-version','-f']
     210        output = bin_to_ascii(subprocess.check_output(use))
    210211    flavour = output.strip()
    211     log.info("Detected release:'{}' flavour:'{}'".format(release, flavour))
     212    #log.info("Detected release:'{}' flavour:'{}'".format(release, flavour))
    212213    return release, flavour
    213214
     
    218219    px = subprocess.Popen(["bash", "-c", "source /etc/profile && echo $http_proxy"], stdout=subprocess.PIPE)
    219220    proxy = bin_to_ascii(px.stdout.readline()).strip()
    220     log.info("Detected proxy: '{}'".format(proxy))
     221    #log.info("Detected proxy: '{}'".format(proxy))
    221222    return proxy
    222223
     
    236237                                  pidfile=lockfile.FileLock(filelock),
    237238                                  files_preserve=[log.handlers[0].socket.fileno()]):
    238             start(daemon_mode=True)
     239            start(**kwargs)
    239240    except Exception as e:
    240241        log.critical("Error daemonizing {}".format(e))
     
    252253    for i in range(len(parts_item)):
    253254        executable = parts_item[i].strip()
    254         if not re.match(executable[0]):
     255        if not re.match(regexp,executable):
    255256            log.debug('Skipping malformed executable {}'.format(executable))
    256257            executable = None
     
    274275        if executable in the_list:
    275276            the_list[executable] = the_list[executable] + 1
    276             log.info('+++ Incrementing {} = {}'.format(executable, the_list[executable]))
    277         else:
    278             log.info('*** Adding {} = 1'.format(executable, 1))
     277            log.debug('+++ Incrementing {} = {}'.format(executable, the_list[executable]))
     278        else:
     279            log.debug('*** Adding {} = 1'.format(executable, 1))
    279280            the_list[executable] = 1
    280281    glob['LIST'] = the_list
    281 
    282282
    283283def monitor():
     
    459459
    460460
    461 def start(*args, daemon_mode=False, **kwargs):
     461def start(*args, daemon_mode=False,release='Unknown',flavour='Unknown',proxy=False, **kwargs):
    462462    global THREADS, oldsignals, log, CONFIG, glob
    463463
    464464    log.info("Starting analytics")
    465 
     465    log.info('Initialization with release={} flavour={} proxy={}'.format(release,flavour,proxy))
     466   
    466467    mgr = Manager()
    467468    glob = mgr.dict()
     
    470471    glob['config'] = CONFIG
    471472
    472     try:
    473         glob['release'], glob['flavour'] = get_llx_version()
    474     except Exception as e:
    475         log.error('Error getting llx version {}'.format(e))
    476         glob['release'] = 'Unknown'
    477         glob['flavour'] = 'Unknown'
    478 
    479     try:
    480         glob['proxy'] = detect_proxy()
    481         if glob['proxy'] == '':
    482             log.info('Not using proxy')
    483             glob['use_proxy'] = False
    484         else:
    485             glob['use_proxy'] = True
    486     except Exception as e:
    487         log.warning('Error detecting proxy {}'.format(e))
     473    glob['release'] = release
     474    glob['flavour'] = flavour
     475    if proxy:
     476        glob['proxy'] = proxy
     477        glob['use_proxy'] = True
     478    else:
     479        glob['proxy'] = False
    488480        glob['use_proxy'] = False
    489481
     
    863855
    864856if __name__ == '__main__':
    865     exit = False
     857    exit = 0
    866858    keyword='analytics'
     859    interpreter='python3'
    867860    for proc in psutil.process_iter():
    868         for argument in proc.cmdline():
    869             #print('{} {} {}'.format(proc.cmdline(),keyword,argument[-len(keyword):]))
     861        a=False
     862        b=False
     863        for argument in proc.cmdline:
     864            #print('{} {} {}'.format(proc.cmdline,keyword,argument[-len(keyword):]))
     865            if interpreter in argument[-len(interpreter):]:
     866                a = True
    870867            if keyword in argument[-len(keyword):]:
    871                 exit = True
    872                 break
    873         if exit:
    874             break
    875     if exit:
     868                b = True
     869            if a and b:
     870                exit = exit +1
     871    if exit > 1:
    876872        log.error('Another daemon is running')
    877873        sys.exit(1)
     
    890886    THREADS = {}
    891887
     888    try:
     889        release, flavour = get_llx_version()
     890    except Exception as e:
     891        log.error('Error getting llx version {}'.format(e))
     892        release = 'Unknown'
     893        flavour = 'Unknown'
     894
     895    proxy = ''
     896    try:
     897        proxy = detect_proxy()
     898        if proxy == '':
     899            #log.info('Not using proxy')
     900            proxy = False
     901    except Exception as e:
     902        log.warning('Error detecting proxy {}'.format(e))
     903        proxy = False
     904
    892905    DAEMON_MODE = get_var_value('DAEMON_MODE', CONFIG, 'bool')
    893906
    894907    if DAEMON_MODE:
    895         daemonize(daemon_mode=True)
     908        daemonize(daemon_mode=True,flavour=flavour,release=release,proxy=proxy)
    896909    else:
    897         start(daemon_mode=False)
     910        start(daemon_mode=False,flavour=flavour,release=release,proxy=proxy)
    898911
    899912    log.debug('End main')
Note: See TracChangeset for help on using the changeset viewer.