<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>scompt.com &#187; subversion</title>
	<atom:link href="http://scompt.com/blog/archives/tag/subversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://scompt.com</link>
	<description>The website of Edward Dale</description>
	<lastBuildDate>Sat, 23 Jan 2010 15:32:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Keeping Grid Engine configuration information in Subversion</title>
		<link>http://scompt.com/blog/archives/2009/10/13/versioned-grid-engine-configuration</link>
		<comments>http://scompt.com/blog/archives/2009/10/13/versioned-grid-engine-configuration#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:46:17 +0000</pubDate>
		<dc:creator>Edward Dale</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[gridengine]]></category>
		<category><![CDATA[sge]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://scompt.com/?p=305</guid>
		<description><![CDATA[Something I&#8217;ve been doing for the past couple weeks on the BASS is storing the Grid Engine configuration in Subversion.  This allows me to do cool stuff like diff&#8217;ing and rolling back to previous configurations.

The Script

#!/bin/bash

# Configuration values
SGE_ROOT=/usr/share/gridengine
SGE_CELL=default
SVN_URL=file:///home/user/subversion
SVN_IMPORT_DIR=gridconfig
SVN_LOAD=/usr/share/doc/subversion-1.4.2/svn_load_dirs.pl

# The real work
TMPD=`mktemp -d`
source $SGE_ROOT/$SGE_CELL/common/settings.sh
$SGE_ROOT/util/upgrade_modules/save_sge_config.sh $TMPD
find $TMPD -name accounting -exec rm -v {} \;
sed -i &#34;/^load_values/d&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Something I&#8217;ve been doing for the past couple weeks on the <a href="http://www.cs.unc.edu/bass" title="Biomedical Analysis and Simulation Supercomputer">BASS</a> is storing the <a href="http://gridengine.sunsource.net/">Grid Engine</a> configuration in Subversion.  This allows me to do cool stuff like diff&#8217;ing and rolling back to previous configurations.</p>
<p><span id="more-305"></span></p>
<h2>The Script</h2>
<pre class="brush: bash;">
#!/bin/bash

# Configuration values
SGE_ROOT=/usr/share/gridengine
SGE_CELL=default
SVN_URL=file:///home/user/subversion
SVN_IMPORT_DIR=gridconfig
SVN_LOAD=/usr/share/doc/subversion-1.4.2/svn_load_dirs.pl

# The real work
TMPD=`mktemp -d`
source $SGE_ROOT/$SGE_CELL/common/settings.sh
$SGE_ROOT/util/upgrade_modules/save_sge_config.sh $TMPD
find $TMPD -name accounting -exec rm -v {} \;
sed -i &quot;/^load_values/d&quot; $TMPD/execution/*

$SVN_LOAD -no_user_input $SVN_URL $SVN_IMPORT_DIR $TMPD

rm -fr $TMPD
</pre>
<p>Run this regularly from cron to enable the real power that I&#8217;ll discuss below.</p>
<h2>Explanation</h2>
<p>Lines 4-8 define configuration variables used later on.  The <code>SGE_*</code> variables might already be defined for your shell.  If not, you know what they should be.  <code>SVN_URL</code> is the URL of the Subversion repository you&#8217;d like to store the configuration in.  It should have already been created using <code>svnadmin create &lt;dir&gt;</code>.  <code>SVN_IMPORT_DIR</code> is the name of the directory in your repository that will store the configuration information.  The real magic of this script comes from <code>svn_load_dirs.pl</code>, which comes with Subversion.  Provide the path to it in the <code>SVN_LOAD</code> variable.</p>
<p>Lines 11-13 setup the SGE environment and dump the current configuration to a temporary directory.  The <code>save_sge_config.sh</code> script comes with Grid Engine and is a gem.  It writes the grid configuration to a directory structure.  It&#8217;s worthwhile to run it on your own and browse the output.</p>
<p>Lines 14 and 15 do some post-processing on the dumped configuration.  In particular, the <code>accounting</code> file is deleted because in our case, it&#8217;s huge and dynamic, so I don&#8217;t want to store multiple copies of it in the repository.  Another piece of dynamic information is the <code>load_values</code> for each execution host.  These will change each time you run the script and don&#8217;t provide any useful historical information that you can&#8217;t get in better form from <a href="http://ganglia.sourceforge.net/">Ganglia</a>, so I get rid of them.  One last piece of dynamic information is the <code>backup_date</code> file which contains the date and time that <code>save_sge_config.sh</code>.  I like to keep this around because it provides some context, but you could also delete that file here.</p>
<p>With the configuration gathered, line 17 simply calls <code>svn_load_dirs.pl</code> to load it into Subversion.  A commit message in the form of &#8216;Load /tmp/sakfjaskfj into gridconfig.&#8217; is attached to the import.</p>
<h2>Cool stuff</h2>
<p>Now that all the configuration information is stored in Subversion, the world is our oyster.  We can use any of the normal Subversion tools to learn more about the configuration.</p>
<h3>Finding out what&#8217;s changed</h3>
<p>By using <code>svn diff</code>, you can find out what&#8217;s changed between different dates.  For example, here are the changes that I made between October 2nd and 3rd:</p>
<pre class="brush: bash;">
user@host ~$ svn diff file:///home/user/subversion/gridconfig -r {2009-10-02}:{2009-10-03}
Index: backup_date
============================================
--- backup_date (revision 177)
+++ backup_date (revision 181)
@@ -1 +1 @@
-2009-10-01_00:10:01
+2009-10-02_00:10:01
Index: usersets/superusers
============================================
--- usersets/superusers  (revision 177)
+++ usersets/superusers  (revision 181)
@@ -2,4 +2,4 @@
 type    ACL
 fshare  0
 oticket 0
-entries johnny
+entries johnny,billy
</pre>
<p>You&#8217;ll notice the <code>backup_date</code> is there, as I mentioned previously.  Additionally, you&#8217;ll notice I added billy to the superusers userset.  Good to know.</p>
<p><a href="http://scompt.com/wordpress/wp-content/uploads/2009/10/websvn.png"><img src="http://scompt.com/wordpress/wp-content/uploads/2009/10/websvn-150x150.png" alt="WebSVN Example" title="WebSVN Example" width="150" height="150" class="alignright size-thumbnail wp-image-312" /></a></p>
<h3>WebSVN</h3>
<p><a href="http://www.websvn.info/">WebSVN</a> is an online Subversion repository browser.  Set it up correctly to point at your new <code>gridconfig</code> repository and you can get the same diff information as before through your browser.</p>
<h3 style="clear:both">Rollback your grid configuration</h3>
<p>Did something go horribly wrong with your configuration?  Rollback to a previous version using the <code>load_sge_config.sh</code> that also comes with Grid Engine and is located in <code>$SGE_ROOT/util/upgrade_modules</code>.  Simply checkout the version of the repository you want to load and pass it to <code>load_sge_config.sh</code>.  If you do this successfully, let me know.  So far we haven&#8217;t had any catestrophic configuration changes.</p>
<h2>Something else?</h2>
<p>If you manage to do something else interesting with your versioned configuration information, leave a comment below or send me a <a href="/contact/">message</a>.</p>
<p><strong>Update: </strong>Fixed a typo in the code with the <code>$TMPD</code> variable.</p>
]]></content:encoded>
			<wfw:commentRss>http://scompt.com/blog/archives/2009/10/13/versioned-grid-engine-configuration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
