Commit 7892c3f2 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

cleaner now marks observers in the database as 'online' and 'offline'

parent ee5a497d
......@@ -229,6 +229,30 @@ def main(argv):
else:
logger.debug("No stuck threads found.")
# Check for offline observers and mark them accordingly in the database
sql = """SELECT `observer_id`, `ethernet_address`, `status` FROM `tbl_serv_observer`
WHERE `status` = 'offline' OR `status` = 'online'
"""
cur.execute(sql)
rs = cur.fetchall()
if rs:
for obs in rs:
cmd = ["timeout", "1", "ping", "-c", "1", obs[1]]
logger.debug("pinging observer fl-%02d with command %s" % (int(obs[0]), " ".join(cmd)))
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ret = p.wait()
if ret != 0:
logger.error("Observer %d (%s) appears to be offline." % (int(obs[0]), obs[1]))
if obs[2] == 'online':
cur.execute("UPDATE `tbl_serv_observer` SET status='offline' WHERE observer_id=%d" % int(obs[0]))
cn.commit()
logger.info("Observer %d (%s) marked as 'offline' in the database." % (int(obs[0]), obs[1]))
else:
logger.debug("Observer %d (%s) is online." % (int(obs[0]), obs[1]))
if obs[2] == 'offline':
cur.execute("UPDATE `tbl_serv_observer` SET status='online' WHERE observer_id=%d" % int(obs[0]))
cn.commit()
logger.info("Observer %d (%s) marked as 'online' in the database." % (int(obs[0]), obs[1]))
except:
msg = "Encountered error: %s: %s\n%s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc())
logger.error(msg)
......
......@@ -40,11 +40,12 @@ else
printf "done.\n"
fi
fi
# tools
RES=$(rsync ${RSYNCPARAMS} -i --dry-run -e 'ssh -q' tools/ ${USER}@${HOST}:tools 2>&1)
if [ -z "$RES" ]; then
# tools -> only sync on dev server
if [ $HOST = "flocklab-dev-server" ]; then
RES=$(rsync ${RSYNCPARAMS} -i --dry-run -e 'ssh -q' tools/ ${USER}@${HOST}:tools 2>&1)
if [ -z "$RES" ]; then
echo "Tools are up to date."
else
else
printf "Updating tools... "
rsync ${RSYNCPARAMS} -e 'ssh -q' tools/ ${USER}@${HOST}:tools
if [ $? -ne 0 ]; then
......@@ -52,4 +53,5 @@ else
else
printf "done.\n"
fi
fi
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment