From: Michael Casadevall Date: Tue, 30 Dec 2008 12:47:06 +0000 (-0500) Subject: Updated update_db.py to use a lockfile properly and to properly wait. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9defe0eb79b8defb578d69bec2649fd37ae1e37;p=dak Updated update_db.py to use a lockfile properly and to properly wait. Signed-off-by: Michael Casadevall --- diff --git a/ChangeLog b/ChangeLog index 1f5e33c3..ec9bdc0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-12-29 Michael Casadevall + + * dak/update_db.py - Modified to use the lockfile and uncommented sleep() call + 2008-12-28 Michael Casadevall * dak/process_unchecked.py - Modified DM to comply strictly with the DM GR diff --git a/dak/update_db.py b/dak/update_db.py index 33d3ebb9..665724e9 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -26,7 +26,7 @@ ################################################################################ -import psycopg2, sys +import psycopg2, sys, fcntl, os import apt_pkg import time from daklib import database @@ -156,8 +156,17 @@ Updates dak's database schema to the lastest version. You should disable crontab utils.warn("dak update-db takes no arguments.") usage(exit_code=1) + self.update_db() + try: + lock_fd = os.open(Cnf["Dinstall::LockFile"], os.O_RDWR | os.O_CREAT) + fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) + except IOError, e: + if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN': + utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.") + + ################################################################################ if __name__ == '__main__':