Archive for January, 2010

Application lock file implementation

January 23, 2010 Leave a comment

Its always a good practice to put a check in the code to see if another instance of the same app is running.

This is helpful in case you have a cron job that is called every hour and single execution of an app can take more then a hour, in this case if we dont have a check in place then that means we can have more then one instance of the same at one time.

Recently I had to add the same kind of check for one of my Python scripts, sharing that if it might help someone trying to do the same:

if os.access(os.path.expanduser("~/.application.lock"), os.F_OK):
       lck_fl = open(os.path.expanduser("~/.application.lock"), "r")
       oldpid = lck_fl.readline()
       if os.path.exists("/proc/%s" % oldpid):
           print "lck_fl exist! process is already running"
           print "Process is already running as pid %s," % oldpid
           print "lck_fl exists but no PID found as current process"
           print "Removing lck_fl of application process: %s" % oldpid
lck_fl = open(os.path.expanduser("~/.application.lock"), "w")
lck_fl.write("%s" % os.getpid())

Shoaib Mir

Categories: Python Tags: ,

Printing PDF file with images

January 23, 2010 Leave a comment

A few days back I was having a terrible time when I tried to print a few tickets that I had in a PDF document. It all started since I upgraded my desktop Ubuntu to 9.1, didnt have time at that moment so asked a colleague to do the print for me.

Once I got time, after a little bit of googling found out that it was a package that I was missing which is needed for the rendering of images and that needs to be installed before I go on printing PDF docs with images in them.

It was:


Hope it helps someone else who is going through the same pain of not able to print out PDF docs 🙂

Shoaib Mir

Categories: Operating Systems Tags: , ,

Using pg_hba.d folder for HBA rules

January 23, 2010 Leave a comment

Its been quite a while since I did post something and that was due to a very busy schedule at work but got lucky today to get a few mins and sharing something I always wanted to write about.

We got an environment at work where we have a quite a huge number of databases on each PostgreSQL development database server and it is because of the static images of the production DBs we need to create for QA and Dev most of the time. In such a scenario if we keep on adding rules to the pg_hba.conf file it can be a big mess with around 200-300 lines in there and thats a nightmare to manage for a DBA.

Solution – What we ended up doing for this was by having a folder pg_hba.d like this:


and under pg_hba.d folder:


The above two files then contain the list of databases that need to given access for those hosts.


This way you can have host files for each of your staging servers that are used by QA and then have a list of databases that need to be given access from those.

Last step is adding details for using these pg_hba.d files, this can be done in pg_hba.conf file the following way:

host @pg_hba.d/host1-dbuser1-trust.db dbuser1 trust
host @pg_hba.d/host2-dbuser2-trust.db dbuser2 md5

This way instead of having the whole list of databases in pg_hba.conf file we now just have two entries and making it very easy to manage. When ever you need to give a new database access to those hosts just add it to the specific file for that host under pg_hba.d folder and reload the DB server.

Shoaib Mir

Categories: PostgreSQL Tags: , ,