<?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/"
	>

<channel>
	<title>Jon&#039;s Blog</title>
	<atom:link href="http://www.bombdiggity.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bombdiggity.net/blog</link>
	<description>Ramblings of a php coder</description>
	<lastBuildDate>Sat, 06 Mar 2010 22:05:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Alot Has Changed&#8230;</title>
		<link>http://www.bombdiggity.net/blog/2010/03/06/alot-has-changed/</link>
		<comments>http://www.bombdiggity.net/blog/2010/03/06/alot-has-changed/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 22:05:27 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=178</guid>
		<description><![CDATA[Since my last post a lot has changed in my life.  I finally have a job and it&#8217;s going really good.  I&#8217;m a consultant for SugarCRM working on their Internal Application Team.Â  Working at Sugar is very different than any development job that I&#8217;ve had to date.Â  It&#8217;s challenging in may different way [...]]]></description>
			<content:encoded><![CDATA[<p>Since my last post a lot has changed in my life.  I finally have a job and it&#8217;s going really good.  I&#8217;m a consultant for <a href="http://www.sugarcrm.com">SugarCRM </a>working on their Internal Application Team.Â  Working at Sugar is very different than any development job that I&#8217;ve had to date.Â  It&#8217;s challenging in may different way and I&#8217;ve grown to liking the work flow of I log in and work on my assigned tickets and then when when 6 p.m. rolls around I sign off for the day and not have to worry about anything like I did while working at IMS.Â  It&#8217;s a lost less stressful and I have my weekends back to get to spend with friends and family.</p>
<p>With my free time I&#8217;ve had a chance to work on some hobby projects such as <a href="http://www.tigersportsnation.com">Tiger Sports Nation</a> which is a website for finding out about the Warsaw Tigers Sports Teams and providing a way for people around the community to get updates on how the Tigers are doing.Â  It&#8217;s been fun working with my friends from High School on this projects.Â  It&#8217;s really kind of weird as we tried doing this back in &#8216;98 or &#8216;99 and the school shut it down and now they are all for us doing this, my how times have changed.</p>
<p>That&#8217;s all for now.Â  I hope to start posting more and more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2010/03/06/alot-has-changed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine Query Cache &#8211; Sqlite</title>
		<link>http://www.bombdiggity.net/blog/2009/12/23/doctrine-query-cache-sqlite/</link>
		<comments>http://www.bombdiggity.net/blog/2009/12/23/doctrine-query-cache-sqlite/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 20:23:30 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[doctrine]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=172</guid>
		<description><![CDATA[So today in playing with doctrine in one of my projects IÂ decidedÂ to enable query caching to help speed up things a bit. My current host does not run APC or MemCache so I had to use sqlite memory table which they do allow. Â I followed the directions as stated in the manual for 1.2, but [...]]]></description>
			<content:encoded><![CDATA[<p>So today in playing with doctrine in one of my projects IÂ decidedÂ to enable query caching to help speed up things a bit. My current host does not run APC or MemCache so I had to use sqlite memory table which they do allow. Â I followed the directions as stated in the <a title="Doctrine Caching How To" href="http://www.doctrine-project.org/documentation/manual/1_2/en/caching" target="_blank">manual</a> for 1.2, but it didn&#8217;t work. Â It gave me a Table name option not set.</p>
<p><span id="more-172"></span>To fix this problem, I played around a bit and came up with the following fix.</p>
<pre class="brush: php">

$manager = Doctrine_Manager::getInstance();
$cacheConn = Doctrine_Manager::connection(new PDO(&#039;sqlite::memory:&#039;));
$cacheDriver = new Doctrine_Cache_Db(array(&#039;connection&#039; =&gt; $cacheConn, &#039;tableName&#039; =&gt;&#039;cache&#039;));
$cacheDriver-&gt;createTable();
$manager-&gt;setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
</pre>
<p>Please leave a comment if i missed anything or there is a better way of doing something.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/12/23/doctrine-query-cache-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing ZF Application Resources In Controller</title>
		<link>http://www.bombdiggity.net/blog/2009/12/09/accessing-zf-application-resources-in-controller/</link>
		<comments>http://www.bombdiggity.net/blog/2009/12/09/accessing-zf-application-resources-in-controller/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 04:15:35 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[zend_application]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=162</guid>
		<description><![CDATA[My friend Rob Allen recently posted a quick how-to on how to access your configuration data in application.ini file while in a controller or action helper. The one part Rob didn&#8217;t touch on was how to get resources back.

Resources are set when you return something out of your _init&#60;MethodName&#62;. For example when you use the [...]]]></description>
			<content:encoded><![CDATA[<p>My friend Rob Allen recently posted a quick how-to on how to <a href="http://akrabat.com/zend-framework/accessing-your-configuration-data-in-application-ini/">access your configuration data in application.ini</a> file while in a controller or action helper. The one part Rob didn&#8217;t touch on was how to get resources back.</p>
<p><span id="more-162"></span></p>
<p>Resources are set when you return something out of your _init&lt;MethodName&gt;. For example when you use the following source code and return the $_logger, Zend_Application stores the returned value in a registry inside the application.</p>
<pre class="brush: php">
// place in your bootstrap file.
public function _initLogger()
{
    $writer = new Zend_Log_Writer_Firebug();
    $_logger = new Zend_Log($writer);
    return $_logger;
}
</pre>
<p>Now the way you get access to the logger is by doing the following inside your controller or controller helper:</p>
<pre class="brush: php">
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        // action body
        $logger = $this-&gt;getInvokeArg(&#039;bootstrap&#039;)
                        -&gt;getResource(&#039;logger&#039;);
    }
}
</pre>
<p>The key is the getResource() method.  You pass in the part following the _init from your method name.  This will return the instance of what ever object was returned in the _init method. </p>
<p>Where I got stuck, was since I&#8217;m using the Module Bootstrap for my modules and I only want the logger on specific modules and not the whole application when I used the above code it returned null.  The reason for null was because it was not in the global bootstrap file. To get access to the resources from the module bootstrap you need to use the following code:</p>
<pre class="brush: php">
class Admin_IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        // action body
        $logger = $this-&gt;getInvokeArg(&#039;bootstrap&#039;)
                        -&gt;getResource(&#039;modules&#039;)
                        -&gt;offsetGet($this-&gt;getRequest()-&gt;getModuleName())
                        -&gt;getResource(&#039;logger&#039;);
    }
}
</pre>
<p>I hope this helps someone else out there as it was an eye opener to me when I was told about it via the ZF mailing list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/12/09/accessing-zf-application-resources-in-controller/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ZF Curly Quote Character Filter</title>
		<link>http://www.bombdiggity.net/blog/2009/12/09/zf-curly-quote-character-filter/</link>
		<comments>http://www.bombdiggity.net/blog/2009/12/09/zf-curly-quote-character-filter/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 15:15:08 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[curly quotes]]></category>
		<category><![CDATA[ms office]]></category>
		<category><![CDATA[zend_filter]]></category>
		<category><![CDATA[zf]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=144</guid>
		<description><![CDATA[If your like me and have people who like to write stuff in MS Office first and then post it to the web you get the silly quotes and such that word uses. The quotes and such are not valid UFT-8 and that&#8217;s how I like to store my data in my database so it [...]]]></description>
			<content:encoded><![CDATA[<p>If your like me and have people who like to write stuff in MS Office first and then post it to the web you get the silly quotes and such that word uses. The quotes and such are not valid UFT-8 and that&#8217;s how I like to store my data in my database so it usually dumps out with an error.</p>
<p>I&#8217;ve come up with the following Zend_Filer_Interface so that way you can plug it into anything that has the ability to use Zend_Filter.</p>
<p>Read More for the source code.<br />
<span id="more-144"></span></p>
<p><del datetime="2009-12-10T21:39:16+00:00"><strong>Updated on 12/10/09 to include more characters and remove the html version</strong></del></p>
<p><strong>Updated again on 12/10/09 to make it work with UTF-8 Submitted Forms.  I&#8217;ve spent half the day validaing this and testing it with a HEX editor</strong></p>
<pre class="brush: php">
&lt;?php

class Util_Filter_WordChars implements Zend_Filter_Interface
{
    /**
     * Filter out the invalid characters that word puts in.
     * @param string $value
     * @return string
     */
    public function filter($value)
    {

        $search = array(chr(0xe2) . chr(0x80) . chr(0x98),  // &#039;
            chr(0xe2) . chr(0x80) . chr(0x99),  // &#039;
            chr(0xe2) . chr(0x80) . chr(0x9c),  // &quot;
            chr(0xe2) . chr(0x80) . chr(0x9d),  // &quot;
            chr(0xe2) . chr(0x80) . chr(0x93),  // em dash
            chr(0xe2) . chr(0x80) . chr(0x94),  // en dash
            chr(0xe2) . chr(0x80) . chr(0xa6)); // ...

        $replace = array(
            &#039;\&#039;&#039;,
            &#039;\&#039;&#039;,
            &#039;&quot;&#039;,
            &#039;&quot;&#039;,
            &#039;-&#039;,
            &#039;-&#039;,
            &#039;...&#039;);

        return str_replace($search, $replace, $value);
    }
}
</pre>
<p>This could be changed to put them in the html ascii code to display them but I like the standard single quote and double quote online.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/12/09/zf-curly-quote-character-filter/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zend Framework 1.8 Tutorial</title>
		<link>http://www.bombdiggity.net/blog/2009/05/01/zend-framework-18-tutorial/</link>
		<comments>http://www.bombdiggity.net/blog/2009/05/01/zend-framework-18-tutorial/#comments</comments>
		<pubDate>Fri, 01 May 2009 11:39:47 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=140</guid>
		<description><![CDATA[Just a quick post here but my friend Rob Allen of akrabat.com has updated his Zend Framework tutoral to use the new features of Zend Framework 1.8.
This tutorial is intended to give an introduction to using Zend Framework to write a simple database driven application. It has been extensively rewritten for version 1.8 of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://akrabat.com/zend-framework-tutorial/"><img class="alignright" title="Tutorial Screen Shot" src="http://akrabat.com/wp-content/uploads/zf-tutorial_16-300x207.png" alt="" width="300" height="207" /></a>Just a quick post here but my friend Rob Allen of <a title="Akrabat.com" href="http://akrabat.com">akrabat.com</a> has updated his Zend Framework tutoral to use the new features of Zend Framework 1.8.</p>
<blockquote><p>This tutorial is intended to give an introduction to using Zend Framework to write a simple database driven application. It has been extensively rewritten for version 1.8 of the framework and takes full advantage of the Zend_Tool command line script and Zend_Application for bootstrapping. Other components used include Zend_Controller, Zend_View, Zend_Db_Table and Zend_Form.</p></blockquote>
<p><a title="Zend Framework 1.8 Tutoral" href="http://akrabat.com/zend-framework-tutorial/">Click here for the full tutorial and source code Â»</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/05/01/zend-framework-18-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework 1.8 Released</title>
		<link>http://www.bombdiggity.net/blog/2009/04/30/zend-framework-18-released/</link>
		<comments>http://www.bombdiggity.net/blog/2009/04/30/zend-framework-18-released/#comments</comments>
		<pubDate>Fri, 01 May 2009 00:44:27 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[EC2]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=137</guid>
		<description><![CDATA[As I&#8217;m sure everyone is almost aware by now Zend Framework 1.8 has been released. This is an extra special release for me as I spend two good weeks back in March writing the Ec2 Component after being pinged by Zend to do it.
It was fun writing it and learning more that I ever wanted [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;m sure everyone is almost aware by now Zend Framework 1.8 has been released. This is an extra special release for me as I spend two good weeks back in March writing the Ec2 Component after being pinged by Zend to do it.</p>
<p>It was fun writing it and learning more that I ever wanted to know about the Ec2 API&#8217;s but all it all it was a great expierice and I&#8217;m glad that I got the chance to do it.</p>
<p>Other notable items in the 1.8 release are:</p>
<ul>
<li>Zend_Application</li>
<li>Zend_Tool</li>
<li>Zend_Crypt</li>
<li>Zend_Service_Amazon_S3</li>
<li><a title="Zend Framework 1.8 Released" href="http://devzone.zend.com/article/4524-Zend-Framework-1.8.0-Released">and so much more</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/04/30/zend-framework-18-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework Ec2 API</title>
		<link>http://www.bombdiggity.net/blog/2009/03/27/zend-framework-ec2-api/</link>
		<comments>http://www.bombdiggity.net/blog/2009/03/27/zend-framework-ec2-api/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:33:57 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[EC2]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=133</guid>
		<description><![CDATA[So about two weeks ago Wil Sinclair from Zend pinged me about creating an Zend Framework API interface for Amazon Ec2. I was coming off of playing around with Ec2 for work and figured I would give it a shot. With the proposal filed I began the task of coding it out. After two weeks [...]]]></description>
			<content:encoded><![CDATA[<p>So about two weeks ago Wil Sinclair from Zend pinged me about creating an<a href="http://framework.zend.com/"> Zend Framework</a> API interface for Amazon Ec2. I was coming off of playing around with Ec2 for work and figured I would give it a shot. With the <a title="Zend_Service_Amazon_Ec2 Proposal" href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Service_Amazon_Ec2+-+Jon+Whitcraft">proposal filed</a> I began the task of coding it out. After two weeks of writing code I had a working interface for the Query API from Amazon.</p>
<p>I do have to say I learned a lot while doing the inital work and I&#8217;m happy that Wil pinged me to do it. If you want to check out the code currently it lives on <a href="http://github.com/sidhighwind/zend_service_amazon_ec2/tree/master">github</a> but it is on track to make the 1.8 release of Zend Framework.</p>
<p>Please leave a commet here or on the proposal for anything that I may have over looked or if you have any ideas on how I could make it better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/03/27/zend-framework-ec2-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browser Caching with Zend Framework</title>
		<link>http://www.bombdiggity.net/blog/2009/03/27/browser-caching-with-zend-framework/</link>
		<comments>http://www.bombdiggity.net/blog/2009/03/27/browser-caching-with-zend-framework/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 04:27:34 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=130</guid>
		<description><![CDATA[While watching the Zend Devzone RSS feed they posted a link to an article that talks about using the Etag Header to make ZF more cache friendly to the browser.
While I was a little hesitant at first about this in my testing on my dev server it seems to have improved page performance in the [...]]]></description>
			<content:encoded><![CDATA[<p>While watching the <a title="Zend Developer Zone" href="http://devzone.zend.com">Zend Devzone</a> RSS feed they posted a link to an article that talks about using the Etag Header to make ZF more cache friendly to the browser.</p>
<p><span id="more-130"></span>While I was a little hesitant at first about this in my testing on my dev server it seems to have improved page performance in the form of reduced bandwidth coming off the server which is always a good thing.</p>
<p>All that is required is to create and register a new front controller plugin. <a title="Zend Framework Browser Caching" href="http://smartycode.com/performance/zend-framework-browser-caching/">Click here for the most up to date code</a>.</p>
<p>I personally think it&#8217;s worth checking out if you run a zend framework based site as it&#8217;s only about ~35 lines of code at the time of writing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/03/27/browser-caching-with-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Splitting Tar Archives&#8230;</title>
		<link>http://www.bombdiggity.net/blog/2009/03/06/splitting-tar-archives/</link>
		<comments>http://www.bombdiggity.net/blog/2009/03/06/splitting-tar-archives/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 14:32:34 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=117</guid>
		<description><![CDATA[With working on deploying sites on Amazon EC2 we wanted to cut down on the time that it took to sync the sites from our seed servers to the new server.  Our logical way to do this was to put a snapshot of the sites are Amazon S3 as a tgz file.  Our [...]]]></description>
			<content:encoded><![CDATA[<p>With working on deploying sites on Amazon EC2 we wanted to cut down on the time that it took to sync the sites from our seed servers to the new server.  Our logical way to do this was to put a snapshot of the sites are Amazon S3 as a tgz file.  Our sites are around 2gb each and while that is no problem to S3 as it max file size is 5gb but in interest of taking less time to upload each site and save on the chance of the file be corrupted on upload we decided to split the files.</p>
<h3><span id="more-117"></span>Splitting The Archive In To Pieces.</h3>
<pre class="brush: bash">
tar czPf - /dir_to_tar/ | split -b 200m -d - test_backup.tgz.
</pre>
<p>The code is very simple.  First well tell <a title="Gnu Tar man page" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=3&amp;url=http%3A%2F%2Fwww.gnu.org%2Fsoftware%2Ftar%2Fmanual%2Ftar.html&amp;ei=ZTSxSd6YOIKyNM_l7cYE&amp;usg=AFQjCNEzGYgb_p-YLD-0JPJw5Lawxxdj9Q&amp;sig2=H5dSlNqZ1NKfNUKBGI1miw">tar</a> to create (c), gzip (g), absolute names (P) and force (f) and the path that we want in the archive.  It then gets piped to the <a title="Split man page" href="http://www.google.com/url?sa=t&amp;source=web&amp;ct=res&amp;cd=1&amp;url=http%3A%2F%2Funixhelp.ed.ac.uk%2FCGI%2Fman-cgi%3Fsplit&amp;ei=kjSxSdK7KI6-M8fQqMUE&amp;usg=AFQjCNFXY1GH8Ze_F4t8PDhjiObJFdcOTA&amp;sig2=k4MMPmg59miHMyjqaF7Ybw">split</a> command where split is told to make no larger than 200mb files (b) and to put numeric suffixes on the files (d).  Since we don&#8217;t have an input file the &#8211; represents the stream in from the tar command and we want it to output to test_backup.tgz. as the 00, 01, 02&#8230;. will be added to the end of that file.</p>
<p>After that is done running we just put the files on s3 using the <a title="s3Sync" href="http://s3sync.net/wiki">s3Sync</a> utility.</p>
<h3>Combining The Pieces In To One Archive:</h3>
<p>What happens when you want to extract the archive that you split.  You can just extract each file like you normally do.  This is how I do it but I&#8217;m always open for better ideas.</p>
<pre class="brush: bash">
cat test_backup.tgz.* &gt; test_backup.tgz
</pre>
<p>I must state that I&#8217;ve never had a split archive over 09 so i&#8217;m not sure how it will act when when you get more than that but like I said before if you have any better methods I&#8217;m open to new and better ways.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/03/06/splitting-tar-archives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What fun Amazon EC2 is &#8211; Part 1: Instance Management</title>
		<link>http://www.bombdiggity.net/blog/2009/03/04/what-fun-amazon-ec2-is-part-1/</link>
		<comments>http://www.bombdiggity.net/blog/2009/03/04/what-fun-amazon-ec2-is-part-1/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 02:51:42 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Amazon AWS]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[EC2]]></category>

		<guid isPermaLink="false">http://www.bombdiggity.net/blog/?p=92</guid>
		<description><![CDATA[So as of late I have been doing a lot of programming to have a some what automated way to scale out indycar.com and indy500.com when the time calls for us to scale out. To scale out we are using Amazon EC2 with a great deal of success. Last year we successfully made it through [...]]]></description>
			<content:encoded><![CDATA[<p>So as of late I have been doing a lot of programming to have a some what automated way to scale out <a title="IndyCar Series" href="http://www.indycar.com">indycar.com</a> and <a title="Indianapolis 500" href="http://www.indy500.com">indy500.com</a> when the time calls for us to scale out. To scale out we are using <a title="Amazon EC2" href="http://aws.amazon.com/ec2/">Amazon EC2 </a>with a great deal of success. Last year we successfully made it through a season with using EC2. The biggest problem we ran into was the time it took to scale out.</p>
<p><span id="more-92"></span></p>
<p>Scaling out the old way took almost an hour to do and was mostly a non-automated process. Now if you know me at all I automate any thing and everything that I can.</p>
<p>To have an efficent way to automate the instance management I setup a instance admin and support init.d script to help maintain the state of all the running instances.</p>
<p>To create the site I started with Zend Framework as the base for the site as it has everything that I need rolled in to one nice neat package. I created a module to handle the starting, stopping and listing of the instances. To make the start and stop work properly I had to have a bash script that would run on startup and shutdown to notify the instance admin the an instance was started or stopped.</p>
<pre class="brush: bash">
#!/bin/sh
#
# chkconfig: 2345 99 00
# description: register the config with the ims home base servers

. /etc/rc.d/init.d/functions

# Source in our AWS Credentials
. /root/instance/bin/aws_credentials

# check for mysql to be installed
if [ ! -e /usr/bin/mysql ]; then
yum install -y mysql
fi

# Define some Variables

hostname=`hostname`
internal_ip=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4`
get_address=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4`
ip_convert=${get_address//./-}

my_meta=(
&quot;instance-id&quot;
&quot;ami-id&quot;
&quot;local-hostname&quot;
&quot;local-ipv4&quot;
&quot;public-hostname&quot;
&quot;public-ipv4&quot;
&quot;instance-type&quot;
&quot;public-keys&quot;
&quot;placement/availability-zone&quot;
)

for p in ${my_meta[*]}
do
data=( `/usr/bin/curl -s http://169.254.169.254/latest/meta-data/$p/` )
if [[ $data == *=* ]]; then
data=`echo $data | awk -F &quot;=&quot; &#039;{print $2}&#039;`
fi
sql_arg=( &quot;${sql_arg[@]}&quot; &quot;$data&quot; )
done

sql_conn=&quot;-u MYSQLUSER -pMYSQLPASS -h MYSQLSERVER&quot;
assigned_ip=`mysql $sql_conn -B -N -e &quot;select ext_address from cloud.instance where ext_host=&#039;$hostname&#039;;&quot;`
eip_state=`mysql $sql_conn -B -N -e &quot;select eip_state from cloud.instance where ext_host=&#039;$hostname&#039;;&quot;`

start() {

if [ &quot;$eip_state&quot; != &quot;1&quot; ]; then

# we have an elastic ip so assign it
if [[ -n $assigned_ip &amp;amp;&amp;amp; &quot;$get_address&quot; != &quot;$assigned_ip&quot; ]]; then
#we have an elastic ip
/root/instance/ec2/bin/ec2-associate-address --private-key $EC2_PRIVATE_KEY --cert $EC2_CERT $assigned_ip -i ${sql_arg[0]}
get_address=$assigned_ip;
fi

# send the data off to the instanceadmin to have it finish the process
URL_POST=&quot;inst=${sql_arg[0]}&amp;amp;image=${sql_arg[1]}&amp;amp;int_host=${sql_arg[2]}&amp;amp;keypair=${sql_arg[7]}&amp;amp;type=${sql_arg[6]}&amp;amp;zone=${sql_arg[8]}&amp;amp;ext_host=$hostname&amp;amp;ext_address=$get_address&amp;amp;int_address=$internal_ip&quot;

curl -s -d $URL_POST http://INSTANCEADMIN/instance/start

touch /var/lock/subsys/ims_instance
exit 0
else
echo $hostname &quot; has already been registred with home base&quot;
exit 1
fi
}

stop() {
if [ &quot;$eip_state&quot; != &quot;0&quot; ]; then

# send the data off to the instanceadmin to have it finish the process
URL_POST=&quot;inst=&amp;amp;image=&amp;amp;int_host=&amp;amp;keypair=&amp;amp;type=&amp;amp;launched=&amp;amp;zone=&amp;amp;ext_host=$hostname&amp;amp;ext_address=$get_address&amp;amp;int_address=&quot;

curl -s -d $URL_POST http://INSTANCEADMIN/instance/stop

rm -f /var/lock/subsys/ims_instance
exit 0
else
echo $hostname &quot; is already unregistred with home base&quot;
exit 1
fi
}

restart() {
stop
start
}

case &quot;$1&quot; in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo &quot;Usage $0 { start | stop | restart }&quot;
exit 1
;;
esac
exit 0
</pre>
<p>As you can see from the code it&#8217;s your basic init.d script that.  Not this is meant to run on CentOS or RedHat EC2 instances.  When the start is called is sends all the information about the instance to the instance admin where it stores it in the database and sends out an email.  Stop does the same thing except it clears out the database (with exception of the hostname and the external ip, if it&#8217;s an elastic ip).  Doing this makes it easier to see which instances are running because you can actually see a domain associated with an instance-id instead of just an instance-id.</p>
<p>That&#8217;s it for part 1. In Part 2, I will outline the processed I used to have an instance build it self.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bombdiggity.net/blog/2009/03/04/what-fun-amazon-ec2-is-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
