Ejemplo n.º 1
0
 def run(self):
     while self.watchdog.running:
         agn.mark(agn.LV_INFO, 'loop', 180)
         self.step()
         delay = 30
         while self.watchdog.running and delay > 0:
             delay -= 1
             time.sleep(1)
Ejemplo n.º 2
0
def main():
    global term

    maillog = '/var/log/maillog'
    saveFile = agn.mkpath(agn.base, 'var', 'run', 'slrtscn.save')
    bounceLog = agn.mkpath(agn.base, 'log', 'extbounce.log')
    providerLog = agn.normalize_path(None)
    (opts, param) = getopt.getopt(sys.argv[1:], 'vm:s:b:p:')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stderr
        elif opt[0] == '-m':
            maillog = opt[1]
        elif opt[0] == '-s':
            saveFile = opt[1]
        elif opt[0] == '-b':
            bounceLog = opt[1]
        elif opt[0] == '-p':
            providerLog = opt[1]
    scanners = {
        None: ScannerSendmail,
        'sendmail': ScannerSendmail,
        'postfix': ScannerPostfix
    }
    mta = agn.MTA()
    scanner = scanners.get(mta.mta, scanners[None])(maillog, saveFile,
                                                    bounceLog, providerLog)
    #
    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGPIPE, signal.SIG_IGN)
    #
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')
    agn.log(agn.LV_INFO, 'main',
            'Scanning for %s using %s' % (mta.mta, scanner.__class__.__name__))
    while not term:
        time.sleep(1)
        agn.mark(agn.LV_INFO, 'loop', 180)
        scanner.scan()
    #
    scanner.done()
    agn.log(agn.LV_INFO, 'main', 'Going down')
    agn.unlock()
Ejemplo n.º 3
0
    term = True


signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)

signal.signal(signal.SIGHUP, signal.SIG_IGN)
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
#
agn.lock()
agn.log(agn.LV_INFO, "main", "Starting up")
#
pd = Pickdist()
while not term:
    time.sleep(1)
    agn.mark(agn.LV_INFO, "loop", 180)
    if pd.scanForData() == 0:
        delay = 30
        agn.log(agn.LV_VERBOSE, "loop", "No ready to send data file found")
    else:
        delay = 0
        while not term and pd.hasData():
            queue = pd.queueIsFree()
            if queue is None:
                agn.log(agn.LV_INFO, "loop", "Queue is already filled up")
                delay = 180
                break
            blk = pd.getNextBlock()
            if blk.unpack(queue):
                blk.moveTo(agn.mkArchiveDirectory(pd.archive))
            else:
Ejemplo n.º 4
0
        nu = UpdateBounce()
    elif u == 'account':
        nu = UpdateAccount()
    else:
        nu = None
        agn.log(agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
    if not nu is None:
        if updparm.has_key(u):
            nu.options(updparm[u])
        updates.append(nu)
if len(updates) == 0:
    agn.die(agn.LV_ERROR, 'main', 'No update procedure found')
agn.lock()
agn.log(agn.LV_INFO, 'main', 'Starting up')
while not term:
    agn.mark(agn.LV_INFO, 'loop', 180)
    db = None
    for upd in updates:
        if not term and upd.shouldRun() and upd.exists():
            if db is None:
                db = agn.DBase()
                if db is None:
                    agn.log(agn.LV_ERROR, 'loop',
                            'Unable to connect to database')
            if not db is None:
                instance = db.cursor()
                if not instance is None:
                    if not upd.update(instance):
                        agn.log(agn.LV_ERROR, 'loop',
                                'Update for %s failed' % upd.name)
                    instance.close()
Ejemplo n.º 5
0
def main ():
    global  term

    signal.signal (signal.SIGINT, handler)
    signal.signal (signal.SIGTERM, handler)

    if not agn.iswin:
        signal.signal (signal.SIGHUP, signal.SIG_IGN)
        signal.signal (signal.SIGPIPE, signal.SIG_IGN)
    #
    opts = getopt.getopt (sys.argv[1:], 'vso:')
    verbose = False
    single = False
    updparm = {}
    use = []
    for opt in opts[0]:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stdout
            verbose = True
        elif opt[0] == '-s':
            single = True
        elif opt[0] == '-o':
            parm = opt[1].split (':', 1)
            if len (parm) == 2:
                v = parm[1].split ('=', 1)
                if len (v) == 1:
                    v.append ('true')
                if updparm.has_key (parm[0]):
                    updparm[parm[0]].append (v)
                else:
                    updparm[parm[0]] = [v]
                if not parm[0] in use:
                    use.append (parm[0])
    for u in opts[1]:
        if not u in use:
            use.append (u)
    updates = []
    for u in use:
        if u == 'bounce':
            nu = UpdateBounce ()
        elif u == 'account':
            nu = UpdateAccount ()
        else:
            nu = None
            agn.log (agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
        if not nu is None:
            if updparm.has_key (u):
                nu.options (updparm[u])
            updates.append (nu)
    if len (updates) == 0:
        agn.die (agn.LV_ERROR, 'main', 'No update procedure found')
    agn.lock ()
    agn.log (agn.LV_INFO, 'main', 'Starting up')

    if True:
        while not term:
            db = None
            agn.mark(agn.LV_INFO, 'loop', 180)
            for upd in updates:
                if not term and upd.shouldRun() and upd.exists():
                    if db is None:
                        db = agn.DBaseID()
                        if db is None:
                            agn.log(agn.LV_ERROR, 'loop', 'Unable to connect to database')
                    if db:
                        if verbose:
                            db.log = lambda a: sys.stdout.write('%s\n' % a)
                        instance = db.cursor()
                        if instance:
                            if not upd.update(instance):
                                agn.log(agn.LV_ERROR, 'loop', 'Update for %s failed' % upd.name)
                            instance.close()
                        else:
                            agn.log(agn.LV_ERROR, 'loop', 'Unable to get database cursor')
            if db:
                db.close()
            if single:
                term = True
            #
            # Zzzzz....
            countDelay = delay
            while countDelay > 0 and not term:

                if agn.iswin and agn.winstop ():
                        term = True
                        break
                time.sleep(1)
                countDelay -= 1
        for upd in updates:
            upd.done()

    agn.log (agn.LV_INFO, 'main', 'Going down')
    agn.unlock ()
Ejemplo n.º 6
0
		nu = UpdateBounce ()
	elif u == 'account':
		nu = UpdateAccount ()
	else:
		nu = None
		agn.log (agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
	if not nu is None:
		if updparm.has_key (u):
			nu.options (updparm[u])
		updates.append (nu)
if len (updates) == 0:
	agn.die (agn.LV_ERROR, 'main', 'No update procedure found')
agn.lock ()
agn.log (agn.LV_INFO, 'main', 'Starting up')
while not term:
	agn.mark (agn.LV_INFO, 'loop', 180)
	db = None
	for upd in updates:
		if not term and upd.shouldRun () and upd.exists ():
			if db is None:
				db = agn.DBase ()
				if db is None:
					agn.log (agn.LV_ERROR, 'loop', 'Unable to connect to database')
			if not db is None:
				instance = db.cursor ()
				if not instance is None:
					if not upd.update (instance):
						agn.log (agn.LV_ERROR, 'loop', 'Update for %s failed' % upd.name)
					instance.close ()
				else:
					agn.log (agn.LV_ERROR, 'loop', 'Unable to get database cursor')
Ejemplo n.º 7
0
def main():
    global term

    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    if not agn.iswin:
        signal.signal(signal.SIGHUP, signal.SIG_IGN)
        signal.signal(signal.SIGPIPE, signal.SIG_IGN)
    #
    opts = getopt.getopt(sys.argv[1:], 'vso:')
    verbose = False
    single = False
    updparm = {}
    use = []
    for opt in opts[0]:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stdout
            verbose = True
        elif opt[0] == '-s':
            single = True
        elif opt[0] == '-o':
            parm = opt[1].split(':', 1)
            if len(parm) == 2:
                v = parm[1].split('=', 1)
                if len(v) == 1:
                    v.append('true')
                if updparm.has_key(parm[0]):
                    updparm[parm[0]].append(v)
                else:
                    updparm[parm[0]] = [v]
                if not parm[0] in use:
                    use.append(parm[0])
    for u in opts[1]:
        if not u in use:
            use.append(u)
    updates = []
    for u in use:
        if u == 'bounce':
            nu = UpdateBounce()
        elif u == 'account':
            nu = UpdateAccount()
        else:
            nu = None
            agn.log(agn.LV_ERROR, 'main', 'Invalid update: %s' % u)
        if not nu is None:
            if updparm.has_key(u):
                nu.options(updparm[u])
            updates.append(nu)
    if len(updates) == 0:
        agn.die(agn.LV_ERROR, 'main', 'No update procedure found')
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')

    if True:
        while not term:
            db = None
            agn.mark(agn.LV_INFO, 'loop', 180)
            for upd in updates:
                if not term and upd.shouldRun() and upd.exists():
                    if db is None:
                        db = agn.DBaseID()
                        if db is None:
                            agn.log(agn.LV_ERROR, 'loop',
                                    'Unable to connect to database')
                    if db:
                        if verbose:
                            db.log = lambda a: sys.stdout.write('%s\n' % a)
                        instance = db.cursor()
                        if instance:
                            if not upd.update(instance):
                                agn.log(agn.LV_ERROR, 'loop',
                                        'Update for %s failed' % upd.name)
                            instance.close()
                        else:
                            agn.log(agn.LV_ERROR, 'loop',
                                    'Unable to get database cursor')
            if db:
                db.close()
            if single:
                term = True
            #
            # Zzzzz....
            countDelay = delay
            while countDelay > 0 and not term:

                if agn.iswin and agn.winstop():
                    term = True
                    break
                time.sleep(1)
                countDelay -= 1
        for upd in updates:
            upd.done()

    agn.log(agn.LV_INFO, 'main', 'Going down')
    agn.unlock()