Ejemplo n.º 1
0
def main():
	global upgrade
	pid = -1
	ips = ['127.0.0.1']
	opts = getopt.getopt (sys.argv[1:], 'i:')
	for opt in opts[0]:
		if opt[0] == '-i':
			ips.append (opt[1])
	agn.lockpath = '/var/tmp'
	agn.lock ()
	pid = os.fork ()
	if pid == 0:
		upgrade = None
		set_signals(updhandler)
		upgrade = Upgrade()
		upgrade.start()
	else:
		agn.log (agn.LV_INFO, 'upgrade', 'Starting up')
		set_signals(webhandler)
		server = Server(None)
		while not term:
			server.handle_request()
		time.sleep (2)
		if pid > 0:
			os.kill(pid, signal.SIGTERM)
		try:
			os.unlink(datafile)
		except OSError, e:
			agn.log(agn.LV_ERROR, 'upgrade', 'Failed to remove datafile %s: %s' % (datafile, repr(e.args)))
Ejemplo n.º 2
0
def main ():
	rc = 1
	(opts, param) = getopt.getopt (sys.argv[1:], 'v')
	for opt in opts:
		if opt[0] == '-v':
			agn.outlevel = agn.LV_DEBUG
			agn.outstream = sys.stdout
	agn.lock ()
	agn.log (agn.LV_INFO, 'main', 'Starting up')
	db = agn.DBaseID ()
	if db is not None:
#		db.log = lambda a: agn.log (agn.LV_DEBUG, 'db', a)
		curs = db.cursor ()
		if curs is not None:
			softbounce = Softbounce (db, curs)
			if softbounce.setup ():
				try:
					softbounce.removeOldEntries ()
					softbounce.setupTimestamp ()
					softbounce.collectNewBounces ()
					softbounce.finalizeTimestamp ()
					softbounce.mergeNewBounces ()
					softbounce.convertToHardbounce ()
					rc = 0
				except agn.error, e:
					agn.log (agn.LV_ERROR, 'main', 'Failed due to %s' % e.msg)
					softbounce.ok = False
				softbounce.done ()
			else:
				agn.log (agn.LV_ERROR, 'main', 'Setup of handling failed')
			curs.sync ()
			curs.close ()
		else:
			agn.log (agn.LV_ERROR, 'main', 'Failed to get database cursor')
		db.close ()
Ejemplo n.º 3
0
def main():
    rc = 1
    (opts, param) = getopt.getopt(sys.argv[1:], 'v')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stdout
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')
    db = agn.DBaseID()
    if db is not None:
        #		db.log = lambda a: agn.log (agn.LV_DEBUG, 'db', a)
        curs = db.cursor()
        if curs is not None:
            softbounce = Softbounce(db, curs)
            if softbounce.setup():
                try:
                    softbounce.removeOldEntries()
                    softbounce.setupTimestamp()
                    softbounce.collectNewBounces()
                    softbounce.finalizeTimestamp()
                    softbounce.mergeNewBounces()
                    softbounce.convertToHardbounce()
                    rc = 0
                except agn.error, e:
                    agn.log(agn.LV_ERROR, 'main', 'Failed due to %s' % e.msg)
                    softbounce.ok = False
                softbounce.done()
            else:
                agn.log(agn.LV_ERROR, 'main', 'Setup of handling failed')
            curs.sync()
            curs.close()
        else:
            agn.log(agn.LV_ERROR, 'main', 'Failed to get database cursor')
        db.close()
Ejemplo n.º 4
0
def main ():
	global	running, reread

	delay = 180
	(opts, param) = getopt.getopt (sys.argv[1:], 'vd:')
	for opt in opts:
		if opt[0] == '-v':
			agn.outlevel = agn.LV_DEBUG
			agn.outstream = sys.stderr
		elif opt[0] == '-d':
			delay = int (opt[1])

	signal.signal (signal.SIGINT, handler)
	signal.signal (signal.SIGTERM, handler)
	signal.signal (signal.SIGUSR1, 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')
	data = Data ()
	while running:
		forcedUpdate = reread
		reread = False
		data.update (forcedUpdate)
		n = delay
		while n > 0 and running and not reread:
			time.sleep (1)
			n -= 1
	data.done ()
	agn.log (agn.LV_INFO, 'main', 'Going down')
	agn.unlock ()
Ejemplo n.º 5
0
def main():
    global upgrade
    pid = -1
    ips = ['127.0.0.1']
    opts = getopt.getopt(sys.argv[1:], 'i:')
    for opt in opts[0]:
        if opt[0] == '-i':
            ips.append(opt[1])
    agn.lockpath = '/var/tmp'
    agn.lock()
    pid = os.fork()
    if pid == 0:
        upgrade = None
        set_signals(updhandler)
        upgrade = Upgrade()
        upgrade.start()
    else:
        agn.log(agn.LV_INFO, 'upgrade', 'Starting up')
        set_signals(webhandler)
        server = Server(None)
        while not term:
            server.handle_request()
        time.sleep(2)
        if pid > 0:
            os.kill(pid, signal.SIGTERM)
        try:
            os.unlink(datafile)
        except OSError, e:
            agn.log(
                agn.LV_ERROR, 'upgrade',
                'Failed to remove datafile %s: %s' % (datafile, repr(e.args)))
Ejemplo n.º 6
0
	def main ():
		global	running

		setupSignals ()
		maxChildren = 10
		delay = 10
		spooldir = agn.mkpath (agn.base, 'var', 'spool', 'mail')
		worksize = None
		size = 65536
		(opts, parm) = getopt.getopt (sys.argv[1:], 'c:d:s:w:m:')
		for opt in opts:
			if opt[0] == '-c':
				maxChildren = int (opt[1])
			elif opt[0] == '-d':
				delay = int (opt[1])
			elif opt[0] == '-s':
				spooldir = opt[1]
			elif opt[0] == '-w':
				worksize = int (opt[1])
			elif opt[0] == '-m':
				size = int (opt[1])
		if len (parm) > 0:
			bavDebug (parm)
			sys.exit (0)
		agn.lock ()
		agn.log (agn.LV_INFO, 'bavd', 'Starting up')
		lastCheck = -1
		children = []
		spool = eagn.Mailspool (spooldir, worksize = worksize, scan = False, storeSize = size)
		while running:
			now = time.localtime ()
			if now.tm_yday != lastCheck:
				checkProcmailrc (now, spool.store)
				lastCheck = now.tm_yday
			if len (children) < maxChildren:
				if len (children) == 0:
					spool.scanWorkspaces ()
				for ws in spool:
					agn.log (agn.LV_VERBOSE, 'bavd', 'New child starting in %s' % ws.ws)
					ch = Child (ws)
					ch.start (size)
					children.append (ch)
					if len (children) >= maxChildren:
						break
			n = delay
			while running and n > 0:
				time.sleep (1)
				if children:
					children = waitForChildren (children)
				n -= 1
		while children:
			agn.log (agn.LV_VERBOSE, 'bavd', 'Wait for %d children to terminate' % len (children))
			for child in children:
				child.signal ()
			time.sleep (1)
			children = waitForChildren (children)
		agn.log (agn.LV_INFO, 'bavd', 'Going down')
		agn.unlock ()
Ejemplo n.º 7
0
def main():
    doit = True
    (opts, parm) = getopt.getopt(sys.argv[1:], 'vn')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stderr
        elif opt[0] == '-n':
            doit = False
    agn.lock()

    OpenEMM().run(doit)
    agn.unlock()
Ejemplo n.º 8
0
 def main():
     doit = True
     maxAge = 1
     startUpDelay = 60
     mailings = None
     try:
         (opts, parm) = getopt.getopt(sys.argv[1:], '?nva:d:m:')
         for opt in opts:
             if opt[0] == '-?':
                 usage()
             elif opt[0] == '-n':
                 doit = False
             elif opt[0] == '-v':
                 agn.outlevel = agn.LV_DEBUG
                 agn.outstream = sys.stderr
             elif opt[0] == '-a':
                 agn.validate(opt[1],
                              '[0-9]+',
                              (lambda a: int(a) > 0, 'age must be > 0'),
                              reason='Numeric value expected for age')
                 maxAge = int(opt[1])
             elif opt[0] == '-d':
                 startUpDelay = int(opt[1])
             elif opt[0] == '-m':
                 if mailings is None:
                     mailings = []
                 mailings.append(int(opt[1]))
     except (getopt.GetoptError, agn.error) as e:
         usage(str(e))
     agn.lock()
     agn.log(agn.LV_INFO, 'main', 'Starting up')
     rc = False
     rec = Recovery(maxAge, startUpDelay, mailings, doit)
     if rec.setup():
         try:
             rec.collectMailings()
             rec.recoverMailings()
             rec.reportMailings()
             rc = True
         except agn.error as e:
             agn.log(agn.LV_ERROR, 'main', 'Failed recovery: %s' % e)
     else:
         agn.log(agn.LV_ERROR, 'main', 'Failed to setup recovery process')
     rec.done()
     agn.log(agn.LV_INFO, 'main', 'Going down')
     agn.unlock()
     if not rc:
         sys.exit(1)
Ejemplo n.º 9
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.º 10
0
def main():
    single = False
    (opts, param) = getopt.getopt(sys.argv[1:], 'v')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stderr
            single = True
    pd = Pickdist()
    if single:
        pd.step()
    else:
        agn.lock()
        agn.log(agn.LV_INFO, 'main', 'Starting up')
        wd = eagn.Watchdog()
        wd.mstart([pd])
        agn.log(agn.LV_INFO, 'main', 'Going down')
        agn.unlock()
Ejemplo n.º 11
0
def main():
    background = False
    restartDelay = '60'
    terminationDelay = '10'
    output = False
    prior = None
    limit = 100
    (opts, param) = getopt.getopt(sys.argv[1:], 'vi:br:t:op:l:')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stderr
        elif opt[0] == '-i':
            if opt[1] == '-':
                if param:
                    agn.logname = '%s-wd' % (os.path.basename(param).split(
                        '.', 1)[0], )
            else:
                agn.logname = opt[1]
        elif opt[0] == '-b':
            background = True
        elif opt[0] == '-r':
            restartDelay = opt[1]
        elif opt[0] == '-t':
            terminationDelay = opt[1]
        elif opt[0] == '-o':
            output = True
        elif opt[0] == '-p':
            prior = opt[1]
        elif opt[0] == '-l':
            limit = int(opt[1]) if opt[1] != '-' else None
    if not len(param):
        raise agn.error('No command given to run under watchdog control')
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')
    wd = EWatchdog(param, output)
    if background and wd.pushToBackground():
        return
    if prior:
        wd.setPrior(prior)
    wd.setLimit(limit)
    wd.mstart(wd.Job(agn.logname, wd.run, ()), restartDelay, terminationDelay)
    agn.log(agn.LV_INFO, 'main', 'Going down')
    agn.unlock()
Ejemplo n.º 12
0
def main():
    cfgfile = None
    port = agn._syscfg.iget('trigger-port', 8080)
    (opts, param) = getopt.getopt(sys.argv[1:], 'vc:p:')
    for opt in opts:
        if opt[0] == '-v':
            agn.outlevel = agn.LV_DEBUG
            agn.outstream = sys.stderr
        elif opt[0] == '-c':
            cfgfile = opt[1]
        elif opt[0] == '-p':
            port = int(opt[1])
    cfg = eagn.Config()
    cfg['xmlrpc.port'] = str(port)
    cfg['xmlrpc.server'] = 'forking'
    cfg['merger.port'] = '8089'
    if cfgfile is not None:
        cfg.read(cfgfile)
    agn.lock()
    agn.log(agn.LV_INFO, 'main', 'Starting up')
    launch = Launcher(cfg)
    launch.mstart(launch.Job('webserver', launch.run, ()), restartDelay=5)
    agn.log(agn.LV_INFO, 'main', 'Going down')
    agn.unlock()
Ejemplo n.º 13
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.º 14
0
    if not agn.iswin and sig == signal.SIGUSR1:
        reread = True
    else:
        running = False


signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGTERM, handler)
if not agn.iswin:
    signal.signal(signal.SIGUSR1, handler)
    signal.signal(signal.SIGHUP, signal.SIG_IGN)
    signal.signal(signal.SIGPIPE, signal.SIG_IGN)

agn.log(agn.LV_INFO, 'main', 'Starting up')
agn.lock()
data = Data()
while running:
    forcedUpdate = reread
    reread = False
    data.update(forcedUpdate)
    n = delay
    while n > 0 and running and not reread:

        if agn.iswin and agn.winstop():
            running = False
            break
        time.sleep(1)
        n -= 1
data.done()
agn.unlock()
Ejemplo n.º 15
0
term = False


def handler(sig, stack):
    global term

    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")
Ejemplo n.º 16
0
def main (): #{{{
	oldest = 3
	processes = 4
	restartDelay = '1m'
	terminationDelay = '5m'
	(opts, param) = getopt.getopt (sys.argv[1:], 'vo:p:r:t:')
	for opt in opts:
		if opt[0] == '-v':
			agn.outlevel = agn.LV_DEBUG
			agn.outstream = sys.stderr
			agn.loglevel = agn.LV_DEBUG
		elif opt[0] == '-o':
			oldest = int (opt[1])
		elif opt[0] == '-p':
			processes = int (opt[1])
		elif opt[0] == '-r':
			restartDelay = opt[1]
		elif opt[0] == '-t':
			terminationDelay = opt[1]
	#
	activator = Activator ()
	modules = (agn.Stream.of (globals ().itervalues ())
		.filter (lambda module: type (module) is type and issubclass (module, Task) and hasattr (module, 'interval'))
		.filter (lambda module: activator.check (['%s-%s' % (agn.logname, module.name)]))
		.map (lambda module: (module.name, module))
		.dict ()
	)
	#
	agn.lock ()
	agn.log (agn.LV_INFO, 'main', 'Starting up')
	agn.log (agn.LV_INFO, 'main', 'Active modules: %s' % ', '.join (sorted (modules.iterkeys ())))
	schedule = Schedule (modules, oldest, processes)
	if param:
		schedule.readConfiguration ()
		for name in param:
			if name not in modules:
				print ('** %s not known' % name)
			else:
				agn.log (agn.LV_INFO, name, 'Module found')
				module = modules[name] (schedule)
				rc = module ()
				schedule.status (None, None)
				agn.log (agn.LV_INFO, name, 'Module returns %r' % (rc, ))
				if schedule.pending.queued or schedule.pending.running:
					agn.log (agn.LV_INFO, name, 'Execute backgound processes')
					try:
						while schedule.pending.queued:
							schedule.status (None, None)
							schedule.pendings ()
							if len (schedule.pending.running) == processes:
								agn.log (agn.LV_INFO, name, 'Currently %d processes running, wait for at least one to terminate' % len (schedule.pending.running))
								schedule.status (None, None)
								schedule.wait (True)
						agn.log (agn.LV_INFO, name, 'Wait for %d background process to teminate' % len (schedule.pending.running))
						while schedule.pending.running:
							schedule.status (None, None)
							if not schedule.wait (True):
								break
					except KeyboardInterrupt:
						agn.log (agn.LV_INFO, name, '^C, terminate all running processes')
						for p in schedule.pending.running[:]:
							schedule.pending.control.term (p.pid)
							schedule.wait ()
						agn.log (agn.LV_INFO, name, 'Waiting for 2 seconds to kill all remaining processes')
						time.sleep (2)
						for p in schedule.pending.running:
							schedule.pending.control.term (p.pid, eagn.signal.SIGKILL)
						agn.log (agn.LV_INFO, name, 'Waiting for killed processes to terminate')
						while schedule.wait (True) is not None:
							pass
					agn.log (agn.LV_INFO, name, 'Background processes done')
				if schedule.deferred:
					agn.log (agn.LV_INFO, name, 'Deferred jobs active, process them')
					try:
						last = -1
						while schedule.defers ():
							cur = len (schedule.deferred)
							if cur != last:
								agn.log (agn.LV_INFO, name, '%d jobs remaining' % cur)
								last = cur
							time.sleep (1)
					except KeyboardInterrupt:
						agn.log (agn.LV_INFO, name, '^C, terminating')
	else:
		jq = Jobqueue (schedule)
		jq.start (restartDelay = restartDelay, terminationDelay = terminationDelay)
	agn.log (agn.LV_INFO, 'main', 'Going down')
	agn.unlock ()
Ejemplo n.º 17
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()