Ignore:
Timestamp:
Jan 18, 2017, 5:54:11 PM (3 years ago)
Author:
mabarracus
Message:

Fix proxy usage in daemon mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lliurex-statistics/trunk/fuentes/lliurex-statistics.install/usr/sbin/analytics

    r3330 r3349  
    1717import lockfile
    1818import xmlrpclib
    19 import urllib
    2019
    2120######### END CONFIG ###########
     
    266265    f.close();
    267266
    268     global filename;
     267    global filename,url,proxy,headers;
    269268   
    270269    db = sqlite3.connect(filename);
     
    295294    except Exception as e:
    296295        debug("Error debugging data to send")
    297 
    298     r = requests.post(url,data=payload,headers=headers,proxies=urllib.getproxies(),timeout=5);
    299     debug("S("+r.text+')',2);
     296    #debug('proxy set to '+proxy)
     297    p={}
     298    p['http']=proxy
     299    #debug('p='+str(p))
     300    try:
     301        if proxy != '':
     302            r = requests.post(url,data=payload,headers=headers,proxies=p,timeout=5)
     303        else:
     304            r = requests.post(url,data=payload,headers=headers,timeout=5)
     305        debug("S("+r.text+')',2);
     306    except Exception as e:
     307        debug("Error sending request: "+str(e))
    300308#END def send_data():
    301309
     
    381389#
    382390def update_db():
    383         debug('U',2)
     391        debug('U',1)
    384392        global LIST,filename
    385393        #debug("updating "+filename);
     
    414422def daemonize():
    415423        debug('Running daemon...')
    416         with daemon.DaemonContext(detach_process=True,working_directory='/tmp',umask=002,pidfile=lockfile.FileLock('/var/run/analytics')):
     424        try:
     425            with daemon.DaemonContext(detach_process=True,working_directory='/tmp',umask=002,pidfile=lockfile.FileLock('/var/run/analytics')):
    417426                start()
     427        except Exception as e:
     428            debug("Error daemonizing "+str(e))
    418429#END def daemonize():
    419430
     
    493504
    494505debug("filename="+filename+' next='+next_filename)
     506try:
     507     px= subprocess.Popen(["bash","-c","source /etc/profile && echo $http_proxy"],stdout=subprocess.PIPE)
     508     proxy=px.stdout.readline().strip()
     509     debug('Detected proxy: '+str(proxy))
     510except Exception as e:
     511     debug('Error getting proxy '+str(e))
    495512
    496513if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.