Keeping GridEngine configuration information in git

If indeed “imitation is the highest form of flattery”, then Edward Dale should indeed be flattered since I’ve taken his idea about Keeping Grid Engine configuration information in Subversion that I noticed thanks to Chris’ blog entry and simply used git for the backend storage.

After seeing the simplicity of the solution and its usefulness, it looked to be a must have, except that I generally use git for almost everything and adding subversion to the mix would be annoying. The crux point thus seemed to be replacing svn_load_dirs.pl (to import and update everything) with an equivalent git-load-dirs. Unfortunately, git-load-dirs would make the script dependent on a number of additional python modules.

Luckily, every now and then it pays to RTFM instead of just searching everywhere in the internet for a solution. Using git --help or man git reveals two obviously useful command-line options:

--git-dir=<path>
    Set the path to the repository. This can also be controlled by
    setting the GIT_DIR environment variable...

--work-tree=<path>
    Set the path to the working tree... This can also be controlled by
    setting the GIT_WORK_TREE environment variable...

The resulting GridEngine-git-config script is now part of the programs in flex-grid.

In the current long form it adds various error checking and intelligence to avoid creating unnecessary snapshots, but stripped of all that it essentially boils down to this:

#!/bin/sh
# configuration variables
SGE_ROOT=/opt/grid
SGE_CELL=default
GIT_DIR=/some/share/git-repo/gridengine-config.git
export SGE_ROOT SGE_CELL GIT_DIR

# GridEngine settings
. $SGE_ROOT/$SGE_CELL/common/settings.sh

# Create a fresh empty directory
tmpDir=$(mktemp -d)
trap "rm -rf $tmpDir 2>/dev/null; exit 0" EXIT TERM INT

$SGE_ROOT/util/upgrade_modules/save_sge_config.sh $GIT_WORK_TREE

(
    cd $tmpDir || exit 1
    GIT_WORK_TREE=.; export GIT_WORK_TREE

    # use backup_date for the commit message
    msg=$(cat backup_date)

    # various cleanup of files, contents etc.
    # see full version for the detailed implementation
    needsCommit=true

    if [ "$needsCommit" = true ]
    then
        # register all new files
        git add .

        # commit everything
        git commit -a -m "$msg"
    else
        echo "no changes to be committed $msg"
    fi
)

Stripped down to the essentials, the svn_load_dirs.pl has been replaced by the tandem

git add .

and

git commit -a

both of which only rely on git being installed.

For convenience, the GridEngine-git-config script provides a pass-through for some common git commands:

  • GridEngine-git-config log
  • GridEngine-git-config ls-files
  • GridEngine-git-config show
  • GridEngine-git-config whatchanged

Under normal circumstances, the show and whatchanged would be the most useful means of seeing which changes have occurred.

The git instaweb or the gitweb.cgi can also be used to browse the changes.

05 Nov 2009 | gridengine, git