<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[/* steve jansen */]]></title>
  <link href="http://steve-jansen.github.io/atom.xml" rel="self"/>
  <link href="http://steve-jansen.github.io/"/>
  <updated>2015-08-26T09:28:23-04:00</updated>
  <id>http://steve-jansen.github.io/</id>
  <author>
    <name><![CDATA[Steve Jansen]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Parsing Jenkins secrets in a shell script]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/12/16/parsing-jenkins-secrets-in-a-shell-script/"/>
    <updated>2014-12-16T14:39:54-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/12/16/parsing-jenkins-secrets-in-a-shell-script</id>
    <content type="html"><![CDATA[<p>The <a href="https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Binding+Plugin">Jenkins credentials-binding plugin</a>
provides a convenient way to securely store secrets like usernames/passwords in
Jenkins.  You can even inject these secrets into build steps as environmental
variables in a job like this:</p>

<p><img src="http://steve-jansen.github.io/images/2014-12-16.png" alt="screenshot of a Jenkins job using the credentials-binding plugin" /></p>

<p>For a username/password pair, the plugin will inject the pair as a single value
joined by <code>:</code>.  You can split the credentials into their respective parts
using <a href="http://spin.atomicobject.com/2014/02/16/bash-string-maniuplation/">bash string manipulation operators like <code>%</code> and <code>#</code></a>.</p>

<p>Assuming you configured the job to inject a variable named <code>CREDENTIALS</code>, you can do:</p>

<figure class='code'><figcaption><span>[parsing Jenkins secret credentials with bash]</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">USERNAME</span><span class="o">=</span><span class="k">${</span><span class="nv">CREDENTIALS</span><span class="p">%:*</span><span class="k">}</span>
</span><span class='line'><span class="nv">PASSWORD</span><span class="o">=</span><span class="k">${</span><span class="nv">CREDENTIALS</span><span class="p">#*:</span><span class="k">}</span>
</span><span class='line'>
</span><span class='line'><span class="c"># proof of concept - don&#39;t echo this in real life :)</span>
</span><span class='line'><span class="nb">echo </span><span class="nv">USERNAME</span><span class="o">=</span><span class="nv">$USERNAME</span>
</span><span class='line'><span class="nb">echo </span><span class="nv">USERNAME</span><span class="o">=</span><span class="nv">$PASSWORD</span>
</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Jenkins Job to export Rackspace Cloud DNS Domain As BIND Zone Files]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/12/15/jenkins-job-to-export-rackspace-cloud-dns-domain-as-bind-zone-files/"/>
    <updated>2014-12-15T09:39:33-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/12/15/jenkins-job-to-export-rackspace-cloud-dns-domain-as-bind-zone-files</id>
    <content type="html"><![CDATA[<p>Rackspace Cloud DNS offeres a great web console, along with a solid API for managing
DNS records dynamically from CM tools like Chef.</p>

<p>The web UI @ <a href="https://mycloud.rackspace.com">https://mycloud.rackspace.com</a> doesn&rsquo;t (yet) suppport an action to
export your domain(s) to standard BIND format zone files.</p>

<p>However, the API does support zone file exports,
<a href="http://docs.rackspace.com/cdns/api/v1.0/cdns-devguide/content/GET_exportDomain_v1.0__account__domains__domainId__export_domains.html"><code>GET /v1.0/{account}/domains/{domainId}/export</code></a>.</p>

<p>I wanted to create a scheduled Jenkins job to export a domain managed by
Cloud DNS to GitHub for both versioning and disaster recovery.</p>

<p>One gotcha with the API is it&rsquo;s asynchronous &ndash; you request an export, then
periodically poll on the status of the export.  The API also has rate limiting.
So, the export is a bit more involved than a simple <code>curl</code> call.</p>

<p>Based on <a href="https://community.rackspace.com/products/f/25/t/1743">this Rackspace community support post</a>,
I found a great python utility, <a href="https://github.com/wichert/clouddns">clouddns.py by Wichert Akkerman</a>.</p>

<blockquote><p>Note: I couldn&rsquo;t use the <a href="https://github.com/rackspace/pyrax">https://github.com/rackspace/pyrax</a> official SDK,
as I&rsquo;m on CentOS 6.5 with Python 2.6, and the SDK requires Python 2.7.  I also tried
the <a href="https://gist.github.com/DavidWittman/4727690">gist by DavidWittman</a> but failed
to get it working with the LON region despte following
<a href="https://github.com/rackerlabs/python-clouddns/blob/master/README.rst">the clouddns README</a></p></blockquote>

<p>Here&rsquo;s the basis of the script I used in a Jenkins job to export a domain and subdomains
every 15 minutes, alongw with the Git publisher for Jenkins to push the changes back to
a GitHub repo.</p>

<div><script src='https://gist.github.com/14dddef6fa0318761e3c.js'></script>
<noscript><pre><code>#!/bin/bash
# exports DNS records from Rackspace Cloud DNS to text files
# Depends on https://github.com/wichert/clouddns/blob/master/src/clouddns.py

set -e

me=export-zone
base_domain=
rackspace_region=
rackspace_rate_limit_delay=3
script_root=$(cd `dirname &quot;${BASH_SOURCE[0]}&quot;` &amp;&amp; pwd)

function usage() {
  cat &lt;&lt; EOF
Usage: `basename &quot;${BASH_SOURCE[0]}&quot;` [domain]
  exports a Racksapce Cloud DNS domain and subdomains to zone files&quot;

  domain - an optional filter for the domain to export, defaults to all
EOF
  exit 1
}

[ &quot;$1&quot; == &quot;-?&quot; ] &amp;&amp; usage
[ &quot;$1&quot; == &quot;--help&quot; ] &amp;&amp; usage

echo &quot;[$me] verifying Rackspace API credentials ...&quot;
if [ -z &quot;$OS_USERNAME&quot; ] || [ -z &quot;$OS_PASSWORD&quot; ]; then
  echo &quot;[$me] error - missing rackspace credentials - you may need a openrc file&quot; &gt;&amp;2
  echo &quot;[$me] see http://docs.rackspace.com/servers/api/v2/cs-gettingstarted/content/section_gs_install_nova.html#d6e1129&quot; &gt;&amp;2
  exit 1
fi

if echo &quot;$OS_REGION_NAME&quot; | grep -i &quot;LON&quot; &gt;/dev/null 2&gt;&amp;1; then
  rackspace_region=uk
else
  rackspace_region=us
fi

echo &quot;[$me] verifying python dependencies ...&quot;
if ! python --version &gt;/dev/null 2&gt;&amp;1; then
  echo &quot;[$me] error - python runtime not found&quot; &gt;&amp;2
  echo &quot;[$me] see https://www.python.org/downloads/&quot; &gt;&amp;2
  exit 2
fi

if ! pip --version &gt;/dev/null 2&gt;&amp;1; then
  echo &quot;[$me] error - missing python dependency - pip&quot; &gt;&amp;2
  echo &quot;[$me] see https://pip.pypa.io/en/latest/installing.html&quot; &gt;&amp;2
  exit 2
fi

if ! pip install --user isodate &gt;/dev/null; then
  echo &quot;[$me] error - pip install isodate failed&quot; &gt;&amp;2
  exit 3
fi

if ! pip install --user requests &gt;/dev/null; then
  echo &quot;[$me] error - pip install requets failed&quot; &gt;&amp;2
  exit 3
fi

echo &quot;[$me] downloading wichert/clouddns from GitHub ...&quot;
curl -L -o &quot;$script_root/clouddns.py&quot; &#39;https://raw.githubusercontent.com/wichert/clouddns/master/src/clouddns.py&#39;

if [ -z &quot;$1&quot; ]; then
  base_domain=&quot;.&quot;
else
 base_domain=&quot;$1&quot;
fi

clouddns_command=&quot;python &quot;&quot;$script_root/clouddns.py&quot;&quot; --region &quot;&quot;$rackspace_region&quot;&quot; \
                                                      --username &quot;&quot;$OS_USERNAME&quot;&quot; \
                                                      --api &quot;&quot;$OS_PASSWORD&quot;&quot;&quot;

echo &quot;[$me] exporting zone files for $base_domain ...&quot;
domain_list=`$clouddns_command list | \
             awk &#39;{print $1}&#39; | \
             grep &quot;$base_domain&quot; | \
             sort`

for domain in $domain_list;
do
  echo &quot;[$me] exporting $domain ...&quot;
  # ignore errors in exporting a subdomain, which can happen due to rate limiting
  # assume the next run will export the subdomain
  set +e
  $clouddns_command export-zone &quot;$domain&quot; &gt; &quot;$domain.txt&quot;
  set -e

  # avoid Rackspace API rate limiting errors
  echo &quot;[$me] sleeping $rackspace_rate_limit_delay seconds ...&quot;
  sleep $rackspace_rate_limit_delay
done

exit 0
</code></pre></noscript></div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Troubleshooting GitHub WebHooks SSL Verification]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/12/03/troubleshooting-github-webhooks-ssl-verification/"/>
    <updated>2014-12-03T10:28:37-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/12/03/troubleshooting-github-webhooks-ssl-verification</id>
    <content type="html"><![CDATA[<p>GitHub WebHooks and Jenkins go together like peanut butter and jelly.
<a href="http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/">SCM Webhook trggers are way more efficient for Jenkins over SCM polling</a>.  Webhooks also give you a great UX &ndash; Jenkins reacts
immediately when you push a commit or open a pull request.</p>

<p>I am a huge fan of using <a href="https://github.com/jenkinsci/github-oauth-plugin">GitHub OAuth for single sign on with Jenkins</a>.
The security of OAuth really depends on TLS/SSL for protecting the token in transit,
so your Jenkins should use SSL when using GitHub OAuth.</p>

<p>GitHub&rsquo;s Webhooks have the option to perform SSL certificate validation.  I&rsquo;ve
run into issues with GitHub&rsquo;s &ldquo;Hookshot&rdquo; HTTP engine failing SSL verification for
otherwise valid certificates.  Most of my problems were related to installing
intermediate CA certificates on Jenkins.</p>

<h2>GitHub WebHook configuration and SSL certificate verification</h2>

<p>Here&rsquo;s an example of a pull request webhook failing SSL validation in GitHub:</p>

<p><img src="http://steve-jansen.github.io/images/2014-12-03-A.png" alt="Screenshot of a failed certificate validation in a GitHub WebHook configuratioon screen" /></p>

<p>GitHub will send a &ldquo;hello, world&rdquo; webhook ping when you create a new webhook.  Note
that SSL verification failures will have an usual HTTP response code of <code>0</code>:
<img src="http://steve-jansen.github.io/images/2014-12-03-B.png" alt="Screenshot of a &quot;hello, world&quot; webhook ping from GitHub" /></p>

<p>The response tab will be empty:
<img src="http://steve-jansen.github.io/images/2014-12-03-C.png" alt="Screenshot of a &quot;hello, world&quot; webhook ping from GitHub" /></p>

<h2>Troubleshoot your SSL certificate with the Symantec SSL Toolbox</h2>

<p>Symantec offers a very helpful <a href="https://ssltools.websecurity.symantec.com/checker/">tool to check your certificate installation</a>
as part of their &ldquo;SSL Toolbox&rdquo;. The tool offers suggestions to remedy certificate
issues and links to download missing intermediate CA certificates.</p>

<p>Here&rsquo;s an example of a Symantec diagnostic failure due to a missing intermediate certificate:</p>

<p><img src="http://steve-jansen.github.io/images/2014-12-03-D.png" alt="Screenshot of a failed certificate validation in the Symantec SSL Toolbox" /></p>

<h2>Using the Symantec SSL Toolbox against servers with IP ACLs</h2>

<p>A great feature of the Symantec SSL Tool is how the tool supports non-public servers
behind a firewall.  The tool will first attempt to verify your cert from
a Symantec server.  If your server is behind a firewall that denies public access
except for whitelisted origins, the SSL toolbox has a fallback mode to run a Java applet
in your browser.  The applet will perform the SSL verification
requests from local machine rather than a Symantec server.</p>

<blockquote><p><strong>TIP:</strong> GitHub publishes their public IP range for webhooks as part of the
<a href="https://api.github.com/meta">GitHub metadata API</a> if you wish to create firewall
whitelist rules for GitHub webhook requests.</p></blockquote>

<h2>Symanetc SSL Toolbox Applet and OS X Java security</h2>

<p>Given the recent security vulnerabilities of Java applets, getting the applet to run
on OS X takes some work.  Here are the setting I need to use the applet in Safari 7.1
on OS X 10.9.5 (Mavericks) using the Oracle/Sun JRE 1.7 R71.
(I never succeeded in using the applet in Firefox or Chrome despite serious effort.)</p>

<p>I needed to enable Safari to run the SSL Toolbox applets in &ldquo;unsafe mode&rdquo; without prompting:
<img src="http://steve-jansen.github.io/images/2014-12-03-E.png" alt="Screenshot of a Safari security settings for the Symantec SSL Toolbox" /></p>

<p>I also had to temporarily downgrade the JVM 1.7 browser security level to &ldquo;Medium&rdquo; and
add an execption for <code>https://ssltools.websecurity.symanttec.com</code>:</p>

<p><img src="http://steve-jansen.github.io/images/2014-12-03-F.png" alt="Screenshot of a JVM security settings for the Symantec SSL Toolbox" /></p>

<h2>Green is good!</h2>

<p>Once you&rsquo;ve resolved your certificate issues, you should see green in both the
Symantec SSL Toolbox and the GitHub WebHook requests after enabling SSL verification.</p>

<p><img src="http://steve-jansen.github.io/images/2014-12-03-G.png" alt="Screenshot of a succesful certificate validation in the Symantec SSL Toolbox" /></p>

<p><img src="http://steve-jansen.github.io/images/2014-12-03-H.png" alt="Screenshot of a succesful certificate validation in a GitHub WebHook configuration screen" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Integrating Rackspace Auto Scale Groups with ObjectRocket Mongo databases]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/12/01/integrating-rackspace-auto-scale-groups-with-objectrocket-mongo-databases/"/>
    <updated>2014-12-01T13:00:58-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/12/01/integrating-rackspace-auto-scale-groups-with-objectrocket-mongo-databases</id>
    <content type="html"><![CDATA[<p>Thanks to some pretty awesome support from Jon Fanti and John Moore at <a href="http://objectrocket.com">ObjectRocket</a>,
I learned this week that we had missed two key optimizations for using ObjectRocket MongoDBs with Rackspace
Auto Scaling groups (ASGs).</p>

<h2>ServiceNet</h2>

<p>First, ObjectRocket support can provide medium and large customers with a server FQDN that resolves to a
<a href="http://www.rackspace.com/knowledge_center/frequently-asked-question/what-is-servicenet">ServiceNet</a> private IP.
You can use this FQDN instead of the server name shown in the connect string for your instance.  As long
as your cloud servers and ObjectRocket are in the same Rackspace data center, the ServiceNet connection string
will avoid data transfer charges and keep your packets from transiting the public Internet.</p>

<h2>Dynamic IP ACLs</h2>

<p>We struggled to manually maintain the list of authorized IPs for our ObjectRocket MongoDB instances
when a ASG would add a new node.  We had a backlog plan to script the IP ACLs using Chef, but, hadn&rsquo;t
found the time yet.</p>

<p>Fortunately, ObjectRocket already supports this!  See <a href="https://app.objectrocket.com/external/rackspace">https://app.objectrocket.com/external/rackspace</a></p>

<p><img src="http://steve-jansen.github.io/images/2014-12-01.png" alt="Screenshot of ObjectRocket integration with Rackspace" /></p>

<p>According to John, the ObjectRocket integration with your Rackspace Cloud account will automatically sync
the IP ACLs with your list of current Cloud VMs.  Moreover, the integration will ignore any manual IP ACLs
you create (as long as your description doesn&rsquo;t use the <code>rax-</code> prefix).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How to use Jenkins to monitor cron jobs]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/11/20/how-to-use-jenkins-to-monitor-cron-jobs/"/>
    <updated>2014-11-20T17:46:46-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/11/20/how-to-use-jenkins-to-monitor-cron-jobs</id>
    <content type="html"><![CDATA[<p>Cron jobs have a funny way of being ignored.  Either no one knows the job is failing because the job
doesn&rsquo;t tell anyone.   Or, the job is spamming your e-mail inbox many times a day, regardless of success
or failure, which means you just ignore the e-mails.</p>

<p>I&rsquo;ve seen the &ldquo;Monitor an external job&rdquo; option for new Jenkins jobs before, and never paid much attention.
Turns out it&rsquo;s a great bucket for storing logs and results of cron jobs.</p>

<p>The <a href="https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs">external-monitor-job</a> plugin
seems to ship with the Jenkins war file.  So, your Jenkins should have it out of the box.</p>

<p>Creating a job is pretty simple.  It&rsquo;s just a name and description.  Click &ldquo;New Item&rdquo; in Jenkins and
select the &ldquo;Monitor an external job&rdquo; option.  This creates a job of type <code>hudson.model.ExternalJob</code>.</p>

<p>The <a href="https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs">wiki</a> describes a
fairly complicated method to download the Jenkins jar files onto the server running
your cron jobs, and then use the Java runtime to run a jar with your cron script as an
argument.  The jar presumably forks your a new shell to run your desired cron command and
sends the output/result to Jenkins.</p>

<p>There&rsquo;s a much easier way to do this.  Redirect or <code>tee</code> your job&rsquo;s stdout/stderr output to a
temp file.  Then post the result code and log file via <code>curl</code> to Jenkins.  No need to
download jar files.  No need to even have Java runtime on the server.</p>

<p>Just POST a small XML document with the log contents (binary encoded) and the
exit code to Jenkins @ <code>/job/:jobName/postBuildResult</code> where <code>:jobName</code> is the
URL encoded name of your monitoring job in Jenkins.</p>

<figure class='code'><figcaption><span>[example cron script]</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="c">#!/bin/sh</span>
</span><span class='line'><span class="c"># example cron script to post logs to Jenkins</span>
</span><span class='line'>
</span><span class='line'><span class="c"># exit on error</span>
</span><span class='line'><span class="nb">set</span> -e
</span><span class='line'>
</span><span class='line'><span class="nv">log</span><span class="o">=</span><span class="sb">`</span>mktemp -t tmp<span class="sb">`</span>
</span><span class='line'><span class="nv">timer</span><span class="o">=</span><span class="sb">`</span>date +<span class="s2">&quot;%s&quot;</span><span class="sb">`</span>
</span><span class='line'><span class="nv">jenkins_job</span><span class="o">=</span>my_monitoring_job
</span><span class='line'><span class="nv">jenkins_server</span><span class="o">=</span>http://jenkins.example.com:8080/jenkins/job/<span class="nv">$jenkins_job</span>/postBuildResult
</span><span class='line'><span class="c"># see http://jenkins.example.com:8080/me/configure to get your username and API token</span>
</span><span class='line'><span class="nv">jenkins_username</span><span class="o">=</span>myusername
</span><span class='line'><span class="nv">jenkins_token</span><span class="o">=</span>abcdef0123456789fedcba9876543210
</span><span class='line'>
</span><span class='line'><span class="k">function </span>banner<span class="o">()</span> <span class="o">{</span>
</span><span class='line'>  <span class="nb">echo</span> <span class="k">$(</span><span class="nb">printf</span> <span class="s1">&#39;#%.0s&#39;</span> <span class="o">{</span>1..80<span class="o">}</span><span class="k">)</span> &gt;&gt; <span class="s2">&quot;$log&quot;</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="k">function </span>report<span class="o">()</span> <span class="o">{</span>
</span><span class='line'>  <span class="nv">result</span><span class="o">=</span><span class="nv">$?</span>
</span><span class='line'>  <span class="nv">timer</span><span class="o">=</span><span class="k">$((</span><span class="sb">`</span>date +<span class="s2">&quot;%s&quot;</span><span class="sb">`</span> <span class="o">-</span> <span class="nv">$timer</span><span class="k">))</span>
</span><span class='line'>
</span><span class='line'>  banner
</span><span class='line'>  <span class="nb">echo</span> <span class="s2">&quot;`whoami`@`hostname -f` `date`: elapsed $timer second(s)&quot;</span> &gt;&gt; <span class="s2">&quot;$log&quot;</span>
</span><span class='line'>  <span class="nb">echo</span> <span class="s2">&quot;exit code $result&quot;</span> &gt;&gt; <span class="s2">&quot;$log&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="c"># binary encode the log file for Jenkins</span>
</span><span class='line'>  <span class="nv">msg</span><span class="o">=</span><span class="sb">`</span>cat <span class="s2">&quot;$log&quot;</span> | hexdump -v -e <span class="s1">&#39;1/1 &quot;%02x&quot;&#39;</span><span class="sb">`</span>
</span><span class='line'>
</span><span class='line'>  <span class="c"># post the log to jenkins</span>
</span><span class='line'>  <span class="nb">echo </span>curl -X POST <span class="se">\</span>
</span><span class='line'>       -u <span class="s2">&quot;$jenkins_username:$jenkins_token&quot;</span> <span class="se">\</span>
</span><span class='line'>       -d <span class="s2">&quot;&lt;run&gt;&lt;log encoding=\&quot;hexBinary\&quot;&gt;$msg&lt;/log&gt;&lt;result&gt;$result&lt;/result&gt;&lt;duration&gt;$timer&lt;/duration&gt;&lt;/run&gt;&quot;</span> <span class="se">\</span>
</span><span class='line'>        <span class="nv">$jenkins_server</span>/job/<span class="nv">$jenkins_job</span>/postBuildResult
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="nb">trap </span>report EXIT;
</span><span class='line'>
</span><span class='line'>banner
</span><span class='line'><span class="nb">echo</span> <span class="s2">&quot;hello, world @ `date`!&quot;</span> | tee <span class="s2">&quot;$log&quot;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>[sample `crontab -e` entry]</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nv">MAILTO</span><span class="o">=</span><span class="s2">&quot;&quot;</span>
</span><span class='line'>0 * * * * /bin/sh /your/directory/myjob.sh
</span></code></pre></td></tr></table></div></figure>


<p>A sample of the build log on Jenkins with a green/red build status:</p>

<p><img src="images/2014-11-20.png" alt="Sample Jenkins Build Log" /></p>

<p>Credit to <a href="http://stackoverflow.com/a/25611940/1995977">Taytay on Stackoverflow.com</a>
for figuring out how to use <code>hexdump</code> to properly encode the XML for Jenkins.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Finding Chef nodes bootstrapped in the last X hours]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/10/17/finding-chef-nodes-bootstrapped-in-the-last-x-hours/"/>
    <updated>2014-10-17T18:47:44-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/10/17/finding-chef-nodes-bootstrapped-in-the-last-x-hours</id>
    <content type="html"><![CDATA[<p>I needed to write a script to garbage collect old nodes in Chef related to
auto-scaling groups.</p>

<p>I decided to search for nodes bootstrapped in the last X hours.</p>

<p>I experimented with ways to find nodes that have been up for less than X hours.
In this example, I search for nodes that have been up for 8 hours or less.
Of course, this assumes you never restart your nodes:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>knife exec -E 'search(:node, "uptime_seconds:[0 TO #{ 8 * 60 * 60 }]") { |n| puts n.name }'</span></code></pre></td></tr></table></div></figure>


<p>I also tried finding nodes that converged in the last 8 hours (which would have
to be combined with some other filter of course):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>knife exec -E 'b = Time.now.to_i; a = (b - (8*60*60)).to_i; search(:node, "ohai_time:[#{a} TO #{b}]") { |n| puts n.name }'</span></code></pre></td></tr></table></div></figure>


<p>Overall, I think the easiest option is to just set a node attribute like
&lsquo;bootstrap_date&rsquo; at bootstrap (or set it if it&rsquo;s nil).  This would be a clearcut
way to find out how old a node truly is.</p>

<p>One of my colleagues pointed out that <a href="https://github.com/opscode/chef-metal">Chef Metal</a>
sets a very handy <code>node['metal']['location']['allocated_at']</code> attribute that gets
the job done if you are spinning up new nodes with metal.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[regexes for the serverspec 2 update]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/10/03/regexes-for-the-serverspec-2-update/"/>
    <updated>2014-10-03T18:24:25-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/10/03/regexes-for-the-serverspec-2-update</id>
    <content type="html"><![CDATA[<p>The Serverspec team just released v2 of their outstanding testing library
today, after a very long beta period.  The v2 release had a
<a href="http://serverspec.org/changes-of-v2.html">few breaking breaking changes</a>
due to dropped rspec matchers that had been deprecated.</p>

<p>If your <a href="http://kitchen.ci/">test-kitchen</a> tests recently broke today,
here&rsquo;s a few regexes I used with Sublime Text&rsquo;s regex find/replace
to rewrite the dropped matchers for the new matchers.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>it\s*\{\s*(should|should_not)\s*return_(stdout|stderr)\s*\(?(\/.*\/)\)?\s*\}
</span><span class='line'>its(:\2) { \1 match \3 }
</span><span class='line'>
</span><span class='line'>it\s*\{\s*(should|should_not)\s*return_(stdout|stderr)\s*\(?(\".*\")\)?\s*\}
</span><span class='line'>its(:\2) { \1 contain \3 }
</span><span class='line'>
</span><span class='line'>it\s*\{\s*(should|should_not)\s*return_(stdout|stderr)\s*\(?('.*')\)?\s*\}
</span><span class='line'>its(:\2) { \1 contain \3 }
</span><span class='line'>
</span><span class='line'>it\s*\{\s*(should|should_not)\s*return_exit_status\s*(\d+)\s*\}
</span><span class='line'>its(:exit_status) { \1 eq \2 }</span></code></pre></td></tr></table></div></figure>


<p>Hopefully the kitchen busser project will one day add support for
Gemfile-style constraints on the test node, since busser always
<a href="https://github.com/test-kitchen/test-kitchen/issues/242#issuecomment-28991870">installs the latest version of a busser plugin gem today.</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Chef'ing custom nginx configs with the nginx cookbook]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/08/27/chefing-custom-nginx-configs-with-the-nginx-cookbook/"/>
    <updated>2014-08-27T19:41:10-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/08/27/chefing-custom-nginx-configs-with-the-nginx-cookbook</id>
    <content type="html"><![CDATA[<p>The <a href="http://supermarket.getchef.com/cookbooks/nginx">nginx</a> cookbook has been
super helpful Chef&#8217;ing some web apps recently.  One thing I struggled to
understand was how to use my own custom conf, like <code>/etc/nginx/nginx.conf</code>, that
is optimized for how I use nginx.</p>

<p>One solution I tried, which is probably a Chef anti-pattern, is to only include
the nginx cookbook on the initial converge:</p>

<h2>The Wrong Way</h2>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># the nginx community cookbook will relentlessly revert conf files,</span>
</span><span class='line'><span class="c1"># so avoid running it unless nginx isn&#39;t installed,</span>
</span><span class='line'><span class="c1"># or we explicitly reset/delete the node attribute</span>
</span><span class='line'><span class="n">include_recipe</span> <span class="s1">&#39;nginx&#39;</span> <span class="k">unless</span> <span class="n">node</span><span class="o">[</span><span class="s1">&#39;nginx&#39;</span><span class="o">][</span><span class="s1">&#39;installed&#39;</span><span class="o">]</span>
</span><span class='line'><span class="n">node</span><span class="o">.</span><span class="n">set</span><span class="o">[</span><span class="s1">&#39;nginx&#39;</span><span class="o">][</span><span class="s1">&#39;installed&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># our custom nginx.conf</span>
</span><span class='line'><span class="n">template</span> <span class="s1">&#39;/etc/nginx/nginx.conf&#39;</span> <span class="k">do</span>
</span><span class='line'>   <span class="n">source</span> <span class="s1">&#39;nginx.conf.erb&#39;</span>
</span><span class='line'>   <span class="n">owner</span> <span class="s1">&#39;root&#39;</span>
</span><span class='line'>   <span class="n">group</span> <span class="s1">&#39;root&#39;</span>
</span><span class='line'>   <span class="n">mode</span>  <span class="s1">&#39;0644&#39;</span>
</span><span class='line'>   <span class="n">notifies</span> <span class="ss">:reload</span><span class="p">,</span> <span class="s2">&quot;service[nginx]&quot;</span><span class="p">,</span> <span class="ss">:delayed</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>I knew this was wrong when I wrote it.   Chef is all about idempotency.
But, I couldn&rsquo;t figure out a way to keep the nginx cookbook from reverting my
custom conf during subsequent converges, only to have my <code>template</code> restore my
custom conf a few seconds later.</p>

<h2>The Better Way</h2>

<p>The OpsCode blog <a href="http://www.getchef.com/blog/2013/12/03/doing-wrapper-cookbooks-right/">Doing Wrapper Cookbooks Right</a> shows the right way, and really opened my eyes on the power of
Chef&rsquo;s two phase model (compile, then converge).</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">include_recipe</span> <span class="s1">&#39;nginx&#39;</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># use our custom nginx.conf, rather than the one that ships in the nginx cookbook</span>
</span><span class='line'><span class="c1"># this avoids the nginx and my-app cookbooks from fighting for control of</span>
</span><span class='line'><span class="c1"># the same target file</span>
</span><span class='line'><span class="n">resources</span><span class="p">(</span><span class="s1">&#39;template[nginx.conf]&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">cookbook</span> <span class="s1">&#39;my-app&#39;</span>
</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[json-proxy release 0.2.0]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/07/19/json-proxy-release-0-dot-2-0/"/>
    <updated>2014-07-19T10:20:56-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/07/19/json-proxy-release-0-dot-2-0</id>
    <content type="html"><![CDATA[<p>Happy to announce a new release of <a href="https://www.npmjs.org/package/json-proxy">json-proxy</a>, a
utility for HTML5 devs to run apps locally and proxy calls like <a href="http://localhost:9000/api">http://localhost:9000/api</a> to
a remote server, all without CORS or JSONP.</p>

<h2>Grunt Plugin</h2>

<p>This release includes better support for running as a grunt plugin.
A <a href="https://github.com/gruntjs/grunt-contrib-connect/pull/85">change in grunt-contrib-connect@0.8.0</a>
simplifies life for proxy plugins inside the livereload task of <code>grunt serve</code>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="nx">livereload</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">options</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">middleware</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">connect</span><span class="p">,</span> <span class="nx">options</span><span class="p">,</span> <span class="nx">middlewares</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="c1">// inject json-proxy to the front of the default middlewares array</span>
</span><span class='line'>      <span class="c1">// requires grunt-contrib-connect v0.8.0+</span>
</span><span class='line'>      <span class="nx">middlewares</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span>
</span><span class='line'>        <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;json-proxy&#39;</span><span class="p">).</span><span class="nx">initialize</span><span class="p">({</span>
</span><span class='line'>          <span class="nx">proxy</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>            <span class="nx">forward</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>              <span class="s1">&#39;/api/&#39;</span><span class="o">:</span> <span class="s1">&#39;http://api.example.com:8080&#39;</span>
</span><span class='line'>            <span class="p">},</span>
</span><span class='line'>            <span class="nx">headers</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>              <span class="s1">&#39;X-Forwarded-User&#39;</span><span class="o">:</span> <span class="s1">&#39;John Doe&#39;</span>
</span><span class='line'>            <span class="p">}</span>
</span><span class='line'>          <span class="p">}</span>
</span><span class='line'>        <span class="p">})</span>
</span><span class='line'>      <span class="p">);</span>
</span><span class='line'>
</span><span class='line'>      <span class="k">return</span> <span class="nx">middlewares</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>SSL Endpoints</h2>

<p>This release adds support for proxying to HTTPS endpoints.   Here&rsquo;s a sample
config to forward <a href="http://localhost:9000/channel">http://localhost:9000/channel</a> to <a href="https://www.youtube.com/channel">https://www.youtube.com/channel</a> .</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="p">{</span>
</span><span class='line'>  <span class="s2">&quot;proxy&quot;</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>    <span class="s2">&quot;forward&quot;</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>      <span class="s2">&quot;/channel&quot;</span><span class="o">:</span> <span class="s2">&quot;https://www.youtube.com:443&quot;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>HTTP Proxy Gateways and Basic Authentication</h2>

<p>You can now pass your authentication credentials to a HTTP proxy gateway on
your LAN via the <code>proxy.gateway.auth</code> config setting.  The setting value
uses the <code>username:password</code> format for HTTP basic authentication
(without base64 encoding).  Here&rsquo;s an example config to proxying remote request
via <a href="http://proxy.example.com:8080">http://proxy.example.com:8080</a> as <code>proxyuser</code> with password <code>C0mp13x_!d0rd$$@P!</code></p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class='js'><span class='line'><span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>  <span class="s2">&quot;proxy&quot;</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>    <span class="s2">&quot;gateway&quot;</span><span class="o">:</span> <span class="p">{</span>
</span><span class='line'>      <span class="s2">&quot;protocol: &quot;</span><span class="nx">http</span><span class="o">:</span><span class="s2">&quot;,</span>
</span><span class='line'><span class="s2">      &quot;</span><span class="nx">host</span><span class="s2">&quot;: &quot;</span><span class="nx">proxy</span><span class="p">.</span><span class="nx">example</span><span class="p">.</span><span class="nx">com</span><span class="s2">&quot;,</span>
</span><span class='line'><span class="s2">      &quot;</span><span class="nx">port</span><span class="s2">&quot;: 8080,</span>
</span><span class='line'><span class="s2">      &quot;</span><span class="nx">auth</span><span class="s2">&quot;: &quot;</span><span class="nx">proxyuser</span><span class="o">:</span><span class="nx">C0mp13x_</span><span class="o">!</span><span class="nx">d0rd$$</span><span class="err">@</span><span class="nx">P</span><span class="o">!</span><span class="s2">&quot; /** &#39;user:password&#39; **/</span>
</span><span class='line'><span class="s2">    },  </span>
</span><span class='line'><span class="s2">    &quot;</span><span class="nx">forward</span><span class="s2">&quot;: {</span>
</span><span class='line'><span class="s2">      &quot;</span><span class="o">/</span><span class="nx">api</span><span class="s2">&quot;: &quot;</span><span class="nx">http</span><span class="o">:</span><span class="c1">//api.example.com&quot;,</span>
</span><span class='line'>      <span class="s2">&quot;/foo/\\d+/bar&quot;</span><span class="o">:</span> <span class="s2">&quot;http://www.example.com&quot;</span><span class="p">,</span>
</span><span class='line'>      <span class="s2">&quot;/secure/&quot;</span><span class="o">:</span> <span class="s2">&quot;https://secure.example.com&quot;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">};</span>
</span></code></pre></td></tr></table></div></figure>


<h2>Upgrade to NodeJitsu http-proxy v1.1</h2>

<p>This release required heavy refactoring to use the
<a href="https://github.com/nodejitsu/node-http-proxy/blob/master/UPGRADING.md">latest bits of Nodejitsu&rsquo;s http-proxy v1.1</a></p>

<p>This was necessary since version prior to 1.0 are no longer actively supported.</p>

<h2>Housekeeping</h2>

<p>There&rsquo;s better unit test coverage, and the code validates against a
reasonable set of jshint linting rules.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Including another berksfile in your berksfile]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/05/06/including-another-berksfile-in-your-berksfile/"/>
    <updated>2014-05-06T13:11:57-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/05/06/including-another-berksfile-in-your-berksfile</id>
    <content type="html"><![CDATA[<p>As part of my cooking with <a href="http://www.getchef.com/downloads/chef-dk/">Chef&rsquo;s new workflow</a>,
I wanted Berkshelf to dynamically import the secondary dependencies of my site-cookbook&rsquo;s dependencies.</p>

<p>Thanks <a href="https://coderwall.com/p/j72egw">Vasily Mikhayliche&rsquo;s Coderwall post</a> and <a href="https://sethvargo.com/berksfile-magic/">Seth Vargo&rsquo;s post on Berks magic</a>, I was able to hack something
that worked for me with <a href="http://berkshelf.com/v2.0/">Berkshelf v2.0</a>. (We don&rsquo;t have time to migrate to Berks 3.0 for another couple of weeks, and this feature doesn&rsquo;t seem to be part of Berks 3.0).</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># vi:ft=ruby:</span>
</span><span class='line'><span class="n">site</span> <span class="ss">:opscode</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Extension method to import secondary dependencies in a referenced site-cookbook</span>
</span><span class='line'><span class="c1"># using the constraints in the site-cookbook&#39;s Berkshelf file, rather than just</span>
</span><span class='line'><span class="c1"># the name of the dependencies in the site-cookbook&#39;s metadata.rb file</span>
</span><span class='line'><span class="c1">#</span>
</span><span class='line'><span class="c1"># credit: https://sethvargo.com/berksfile-magic/</span>
</span><span class='line'><span class="c1">#         https://coderwall.com/p/j72egw</span>
</span><span class='line'><span class="k">def</span> <span class="nf">site_cookbook</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
</span><span class='line'>  <span class="n">berksfile</span> <span class="o">=</span> <span class="s2">&quot;../</span><span class="si">#{</span><span class="n">path</span><span class="si">}</span><span class="s2">/Berksfile&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">berksfile</span><span class="p">)</span>
</span><span class='line'>    <span class="n">contents</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">berksfile</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>    <span class="c1"># comment out lines like `site :opscode`, which cannot be imported multiple times</span>
</span><span class='line'>    <span class="n">contents</span> <span class="o">=</span> <span class="n">contents</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/(^\s*site\s)/</span><span class="p">,</span> <span class="s1">&#39;#\1&#39;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>    <span class="c1"># comment out lines like `metadata`, which cannot be imported multiple times</span>
</span><span class='line'>    <span class="n">contents</span> <span class="o">=</span> <span class="n">contents</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/(^\s*metadata\s)/</span><span class="p">,</span> <span class="s1">&#39;#\1&#39;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>    <span class="nb">instance_eval</span><span class="p">(</span><span class="n">contents</span><span class="p">)</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">cookbook</span> <span class="s1">&#39;nginx&#39;</span><span class="p">,</span> <span class="s1">&#39;~&gt; 2.4.4&#39;</span>
</span><span class='line'><span class="n">site_cookbook</span> <span class="s1">&#39;my-site-cookbook&#39;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Happy cooking!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Adding Chef encrypted data bags to source control]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/05/05/adding-chef-encrypted-data-bags-to-source-control/"/>
    <updated>2014-05-05T15:54:25-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/05/05/adding-chef-encrypted-data-bags-to-source-control</id>
    <content type="html"><![CDATA[<p>I&rsquo;ve been using Chef for a bit now and generally a huge fan of the new
<a href="http://www.getchef.com/downloads/chef-dk/">Chef workflow</a>.</p>

<p>We are working hard to attain true continuous delivery and test driven development with Chef.
The devil is in the details now.</p>

<p>One small wrinkle in our effort has been marrying <a href="http://docs.opscode.com/chef/essentials_data_bags.html#encrypt-a-data-bag-item">encrypted data_bags</a> with our chef-repo in GitHub.</p>

<p>I don&rsquo;t want to type the optional argument <code>--secret-file ~/.chef/encrypted_data_bag_secret</code> everytime I interact with a data bag. So, I added this option to my <code>~/.chef/knife.rb</code> file.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">knife</span><span class="o">[</span><span class="ss">:secret_file</span><span class="o">]</span>  <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="n">current_dir</span><span class="si">}</span><span class="s2">/encrypted_data_bag_secret&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>However, this precludes me from easily exporting the edited file to disk.  The export will always be my secret plaintext,
not the encrypted ciphertext.   Not exactly what you want to commit to GitHub.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">knife</span> <span class="n">data_bag</span> <span class="n">create</span> <span class="n">users</span> <span class="n">jenkins</span>
</span><span class='line'><span class="c1"># DON&#39;T COMMIT THIS... the exported file will be unencrypted</span>
</span><span class='line'><span class="n">knife</span> <span class="n">data_bag</span> <span class="n">users</span> <span class="n">jenkins</span> <span class="o">--</span><span class="nb">format</span><span class="o">=</span><span class="n">json</span> <span class="o">&gt;</span> <span class="n">data_bags</span><span class="o">/</span><span class="n">users</span><span class="o">/</span><span class="n">jenkins</span><span class="o">.</span><span class="n">json</span>
</span></code></pre></td></tr></table></div></figure>


<p>So, I decided to create a bash alias to temporarily disable the knife.rb setting and export the data bag to a file:</p>

<p>My <code>~/.bash_profile</code> file contains this alias:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">function</span> <span class="n">knife</span><span class="o">-</span><span class="n">ciphertext</span> <span class="p">()</span> <span class="p">{</span>
</span><span class='line'>   <span class="n">sed</span> <span class="o">-</span><span class="n">e</span> <span class="s2">&quot;s/knife\[\:secret_file\]/</span><span class="se">\#</span><span class="s2">knife\[\:secret_file\]/&quot;</span>  <span class="o">-</span><span class="n">i</span> <span class="o">.</span><span class="n">bak</span>  <span class="o">~</span><span class="sr">/.chef/</span><span class="n">knife</span><span class="o">.</span><span class="n">rb</span>
</span><span class='line'>   <span class="n">knife</span> <span class="vg">$@</span> <span class="o">--</span><span class="nb">format</span><span class="o">=</span><span class="n">json</span>
</span><span class='line'>   <span class="n">mv</span>  <span class="o">~</span><span class="sr">/.chef/</span><span class="n">knife</span><span class="o">.</span><span class="n">rb</span><span class="o">.</span><span class="n">bak</span>  <span class="o">~</span><span class="sr">/.chef/</span><span class="n">knife</span><span class="o">.</span><span class="n">rb</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="k">alias</span> <span class="n">knife</span><span class="o">-</span><span class="n">ciphertext</span><span class="o">=</span><span class="n">knife</span><span class="o">-</span><span class="n">ciphertext</span>
</span></code></pre></td></tr></table></div></figure>


<p>This bash function comments out the secret file option in knife.rb using sed&rsquo;s in-place editing.</p>

<p>Now I can commit the data bag in its encrypted format:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">knife</span><span class="o">-</span><span class="n">ciphertext</span> <span class="n">data_bag</span> <span class="n">show</span> <span class="n">users</span> <span class="n">jenkins</span> <span class="o">&gt;</span> <span class="n">data_bags</span><span class="o">/</span><span class="n">users</span><span class="o">/</span><span class="n">jenkins</span><span class="o">.</span><span class="n">json</span>
</span><span class='line'><span class="n">git</span> <span class="n">add</span> <span class="n">data_bags</span><span class="o">/</span><span class="n">users</span><span class="o">/</span><span class="n">jenkins</span><span class="o">.</span><span class="n">json</span>
</span><span class='line'><span class="n">git</span> <span class="n">commit</span> <span class="o">-</span><span class="n">m</span> <span class="s1">&#39;adding the latest jenkins data bag&#39;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Happing cooking!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A better IIS Express console window]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/03/16/a-better-iis-express-console-window/"/>
    <updated>2014-03-16T18:18:34-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/03/16/a-better-iis-express-console-window</id>
    <content type="html"><![CDATA[<p>IIS Express is the <em>de facto</em>  server to use for local development of ASP.NET MVC and Web Api apps.  It&rsquo;s just like it&rsquo;s big brother IIS
minus a few features rarely used for local development.
Unlike it&rsquo;s big brother, IIS Express runs on demand as a regular console app under the security context of
your current login.  This makes it much easier to start and stop debugging sessions.</p>

<p>Being a console app is great &ndash; you can see <code>System.Diagnostics.Debug.Print</code> and <code>System.Diagnostics.Trace.Write</code>
output right in the console alongside IIS&#8217; usual log statements for HTTP requests.</p>

<p>A really useful trick is to create a Windows Explorer shortcut to iisexpress.exe, and open that shortcut iisexpress.exe.lnk file instead of directly
opening iisexpress.exe. There are two benefits to this:</p>

<ol>
<li><p>iisexpress.exe gets a dedicated icon on the Windows taskbar.  In the screenshot below, I can <code>WinKey + 5</code> to quickly switch to my IIS Express
console output.  (<code>WinKey + N</code> focuses/opens the Nth item on the taskbar; repeat as needed if you have multiple windows grouped for that taskbar icon).</p></li>
<li><p>I can customize the command prompt preferences for just iisexpress.exe.  In the screenshot below, I&rsquo;m using a smaller font in purple color, with the
window stretched the entire 1600 pixel width of my display. This helps greatly with the readability of long lines of text in the console output.</p></li>
</ol>


<p><img src="http://steve-jansen.github.io/images/2014-03-16-A.png" alt="Screenshot of the iisexpress.exe open in a custom window" /></p>

<p>Here&rsquo;s a closer look at the console ouptut:
<img src="http://steve-jansen.github.io/images/2014-03-16-H.png" alt="Screenshot of the iisexpress.exe open in a custom window" /></p>

<p>Here are screenshots of the Explorer settings I used for <code>C:\Program Files\IIS Express\iisexpress.exe.lnk</code>:</p>

<p><img src="http://steve-jansen.github.io/images/2014-03-16-B.png" alt="Screenshot of the iisexpress.exe.lnk settings" />
<img src="http://steve-jansen.github.io/images/2014-03-16-C.png" alt="Screenshot of the iisexpress.exe.lnk settings" />
<img src="http://steve-jansen.github.io/images/2014-03-16-D.png" alt="Screenshot of the iisexpress.exe.lnk settings" />
<img src="http://steve-jansen.github.io/images/2014-03-16-E.png" alt="Screenshot of the iisexpress.exe.lnk settings" />
<img src="http://steve-jansen.github.io/images/2014-03-16-F.png" alt="Screenshot of the iisexpress.exe.lnk settings" />
<img src="http://steve-jansen.github.io/images/2014-03-16-G.png" alt="Screenshot of the iisexpress.exe.lnk settings" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How To verify administrative rights in a Windows batch script]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/03/15/how-to-verify-administrative-rights-in-a-windows-batch-script/"/>
    <updated>2014-03-15T18:50:08-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/03/15/how-to-verify-administrative-rights-in-a-windows-batch-script</id>
    <content type="html"><![CDATA[<p>While working on automated provisioning of a Jenkins slave server on Windows, I needed
to verify that one of my batch scripts was running with administrative privileges.</p>

<p>Turns out this problem is easy to solve these days as long as you don&rsquo;t need to support
XP.  Thanks to <a href="http://stackoverflow.com/a/21295806/1995977">and31415 on SO</a> for the
great post on using <code>fsutil</code>!</p>

<p>Here&rsquo;s a working example:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='console'><span class='line'><span class="go">@ECHO OFF</span>
</span><span class='line'><span class="go">SETLOCAL ENABLEEXTENSIONS</span>
</span><span class='line'>
</span><span class='line'><span class="go">:: verify we have admin privileges</span>
</span><span class='line'><span class="go">CALL :IsAdmin || (ECHO %~n0: ERROR - administrative privileges required &amp;&amp; EXIT /B 1)</span>
</span><span class='line'>
</span><span class='line'><span class="go">ECHO &quot;Hello, Admin!&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="go">:EXIT</span>
</span><span class='line'><span class="go">EXIT /B</span>
</span><span class='line'>
</span><span class='line'><span class="go">:: function to verify admin/UAC privileges</span>
</span><span class='line'><span class="go">:: CREDIT: http://stackoverflow.com/a/21295806/1995977</span>
</span><span class='line'><span class="go">:IsAdmin</span>
</span><span class='line'><span class="go">IF NOT EXIST &quot;%SYSTEMROOT%\system32\fsutil.exe&quot; (</span>
</span><span class='line'><span class="go">  ECHO %~n0: WARNING - fsutil command not found; cannot verify adminstrative rights</span>
</span><span class='line'><span class="go">) ELSE (</span>
</span><span class='line'><span class="go">  &quot;%SYSTEMROOT%\system32\fsutil.exe&quot; dirty query &quot;%SystemDrive%&quot; &gt;NUL 2&gt;&amp;1</span>
</span><span class='line'><span class="go">)</span>
</span><span class='line'><span class="go">EXIT /B</span>
</span></code></pre></td></tr></table></div></figure>


<p>Shameless plug &ndash; learn more tips and tricks for batch scripting in my <a href="http://steve-jansen.github.io/guides/windows-batch-scripting/">Guide to Windows Batch Scripting</a>!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Configuring Vagrant to dynamically match guest and host CPU architectures]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/03/14/configuring-vagrant-to-dynamically-match-guest-and-host-cpu-architectures/"/>
    <updated>2014-03-14T20:06:26-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/03/14/configuring-vagrant-to-dynamically-match-guest-and-host-cpu-architectures</id>
    <content type="html"><![CDATA[<p>Today a work colleague put together a nice Vagrantfile to run a Linux dev environment on our laptops.  <a href="http://www.vagrantup.com">Vagrant</a>
is sweet for DevOps.  The Vagrant file worked great on his Macbook Pro.
But it was no dice running on my Windows box &ndash; the VM was a 64-bit Linux VM (why wouldn&rsquo;t a server be 32-bit?) and I&rsquo;m on a
32-bit laptop (don&rsquo;t ask why my corporate IT still issues 32-bit Windows images on 64-bit hardware!).</p>

<p>To my surprise, VirtualBox can actually a 64-bit guest VM on a 32-bit host OS:</p>

<blockquote><p>If you want to use 64-bit guest support on a 32-bit host operating system, you must also select a 64-bit operating system for the particular VM. Since supporting 64 bits on 32-bit hosts incurs additional overhead, VirtualBox only enables this support upon explicit request.</p>

<p>Source: <a href="http://www.virtualbox.org/manual/ch03.html">http://www.virtualbox.org/manual/ch03.html</a></p></blockquote>

<p>However, I learned Vagrant cloud boxes <a href="https://github.com/mitchellh/vagrant/issues/932">may forget to explicity declare they want VirtualBox to enable  64-on-32 support</a>.  While changing the box &ldquo;Operating System Type&rdquo; from &ldquo;Ubuntu&rdquo; to &ldquo;Ubuntu (64 bit)&rdquo; would be
an easy fix, I decided to see if Vagrant could dynamically choose the right guest CPU architecture based on the host OS&#8217; CPU architecture.
Our app would run as either 32 or 64, so it made sense to run 32 on 32 and 64 on 64, right?</p>

<p>Turns out it is quite easy.  The power of ruby as the config language for Vagrant really shines here:</p>

<p>Here the relevant changes to our Vagrantfile to get Vagrant to run a 64-bit Linux guest on 64-bit hosts,
and a 32-bit Linux guest on 32-bit hosts:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1"># -*- mode: ruby -*-</span>
</span><span class='line'><span class="c1"># vi: set ft=ruby :</span>
</span><span class='line'>
</span><span class='line'><span class="no">Vagrant</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="s2">&quot;2&quot;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
</span><span class='line'>  <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="s2">&quot;hashicorp/precise64&quot;</span>
</span><span class='line'>  <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">box_url</span> <span class="o">=</span> <span class="s2">&quot;https://vagrantcloud.com/hashicorp/precise64/current/provider/virtualbox.box&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1"># support 32 windows hosts :(</span>
</span><span class='line'>  <span class="k">if</span> <span class="no">ENV</span><span class="o">[</span><span class="s2">&quot;PROCESSOR_ARCHITECTURE&quot;</span><span class="o">]</span> <span class="o">==</span> <span class="s2">&quot;x86&quot;</span>
</span><span class='line'>    <span class="nb">puts</span> <span class="s2">&quot;falling back to 32-bit guest architecture&quot;</span>
</span><span class='line'>    <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="s2">&quot;hashicorp/precise32&quot;</span>
</span><span class='line'>    <span class="n">config</span><span class="o">.</span><span class="n">vm</span><span class="o">.</span><span class="n">box_url</span> <span class="o">=</span> <span class="s2">&quot;https://vagrantcloud.com/hashicorp/precise32/current/provider/virtualbox.box&quot;</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1"># ... lots more vagrant plugin and chef goodness ...</span>
</span><span class='line'>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Tips for Vagrant on Windows]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/03/13/tips-for-vagrant-on-windows/"/>
    <updated>2014-03-13T05:55:12-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/03/13/tips-for-vagrant-on-windows</id>
    <content type="html"><![CDATA[<p>I learned some interesting things today about running Vagrant on a Windows machine.
Vagrant is an amazing tool for running a VM on your local dev box with a target platform (e.g., Linux)
provisioned by code (e.g., Chef/Puppet/shell scripts).</p>

<h2>Spaces in Paths</h2>

<p>A hard lesson about Vagrant on Windows was Vagrant uses Ruby heavily, and Ruby on Windows
really, really doesn&rsquo;t like spaces in paths.</p>

<p>The Vagrant installer can&rsquo;t comply with the Windows Installer and Logo requirement to
default to <code>%ProgramFiles%</code> folder <a href="https://github.com/mitchellh/vagrant/issues/1652">due to Ruby&rsquo;s known issues with spaces in paths like C:\Program Files</a>.</p>

<p>I was able to work around this with a symlink:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='console'><span class='line'><span class="go">IF NOT EXIST &quot;%ProgramFiles%\Vagrant&quot; MKDIR &quot;%ProgramFiles%\Vagrant&quot;</span>
</span><span class='line'><span class="go">MKLINK /D &quot;%SystemRoot%\vagrant&quot; &quot;%ProgramFiles%\Vagrant&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>I then ran the <a href="https://www.virtualbox.org/wiki/Downloads">VirtualBox-4.3.8-92456-Win.exe</a> installer using all defaults
except for the USB support and Python scripting.</p>

<p><strong>TIP:</strong> do not install VirtualBox&rsquo;s USB drivers if you have an enterprise USB device blocker/filter</p>

<p>I then followed with installing <a href="http://www.vagrantup.com/download-archive/v1.4.3.html">Vagrant_1.4.3.msi</a> to <code>C:\vagrant</code>.</p>

<p><strong>TIP:</strong> <a href="https://github.com/mitchellh/vagrant/issues/3131">the Vagrant v1.5.0 installer is broken for Windows</a>; use <a href="http://www.vagrantup.com/download-archive/v1.4.3.html">v1.4.3</a> until <a href="http://www.vagrantup.com/downloads.html">v1.5.1</a> is released.</p>

<h2>VirtualBox in XP SP3 compatability mode</h2>

<p>I needed to configure a few VirtualBox binaries to run in XP SP3 compatability mode for my Windows 7 SP1 Enterprise laptop.  YMMV.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='console'><span class='line'><span class="go">REM run VirtualBox in XP SP3 mode</span>
</span><span class='line'><span class="go">REG ADD &quot;HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers&quot; ^</span>
</span><span class='line'><span class="go">        /v &quot;%ProgramFiles%\Oracle\VirtualBox\VirtualBox.exe&quot; ^</span>
</span><span class='line'><span class="go">        /t REG_SZ  ^</span>
</span><span class='line'><span class="go">        /d WINXPSP3</span>
</span><span class='line'><span class="go">REG ADD &quot;HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers&quot; ^</span>
</span><span class='line'><span class="go">        /v &quot;%ProgramFiles%\Oracle\VirtualBox\VBoxSVC.exe&quot; ^</span>
</span><span class='line'><span class="go">        /t REG_SZ  ^</span>
</span><span class='line'><span class="go">        /d WINXPSP3</span>
</span><span class='line'><span class="go">REG ADD &quot;HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers&quot; ^</span>
</span><span class='line'><span class="go">        /v &quot;%ProgramFiles%\Oracle\VirtualBox\VBoxManage.exe&quot; ^</span>
</span><span class='line'><span class="go">        /t REG_SZ  ^</span>
</span><span class='line'><span class="go">        /d WINXPSP3</span>
</span></code></pre></td></tr></table></div></figure>


<h2>Spaces in your home folder path</h2>

<p>If your Windows username (or <code>%USERPROFILE%</code> path) include spaces, you will need to set an environmental variable <code>%VAGRANT_HOME%</code> to a path that
does not use spaces.  This caused many non-obvious errors with <code>vagrant plugin install berkshelf</code> and <code>vagrant plugin install omnibus</code>.</p>

<p>A simple fix was setting <code>%VAGRANT_HOME%</code> to &ldquo;C:\VagrantHome&rdquo;</p>

<h2>Example running a simple 32-bit Ubuntu LTS box on 32-bit Windows 7 SP1</h2>

<p>I don&rsquo;t really need the omnibus plugin here, but, this proves it can install a plugin that would
otherwise fail with spaces in the <code>%USERPROFILE%</code> path.</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='console'><span class='line'><span class="go">SETLOCAL</span>
</span><span class='line'><span class="go">IF NOT EXIST C:\VagrantHome MKDIR C:\VagrantHome</span>
</span><span class='line'><span class="go">PUSHD C:\VagrantHome</span>
</span><span class='line'><span class="go">SET VAGRANT_HOME=C:\VagrantHome</span>
</span><span class='line'><span class="go">PUSHD %TEMP%</span>
</span><span class='line'><span class="go">MKDIR VagrantTest</span>
</span><span class='line'><span class="go">CD VagrantTest</span>
</span><span class='line'><span class="go">vagrant init hashicorp/precise32</span>
</span><span class='line'><span class="go">vagrant box add hashicorp/precise32 https://vagrantcloud.com/hashicorp/precise32/version/1/provider/virtualbox.box</span>
</span><span class='line'><span class="go">vagrant plugin install omnibus</span>
</span><span class='line'><span class="go">vagrant up --provision</span>
</span><span class='line'><span class="go">PAUSE</span>
</span><span class='line'><span class="go">vagrant halt</span>
</span><span class='line'><span class="go">vagrant destroy --force</span>
</span><span class='line'><span class="go">CD ..</span>
</span><span class='line'><span class="go">RMDIR /S /Q &quot;%TEMP%\VagrantTest&quot;</span>
</span><span class='line'><span class="go">POPD</span>
</span><span class='line'><span class="go">ENDLOCAL</span>
</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Binding Jenkins to port 80 on SUSE Linux]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/03/05/binding-jenkins-to-port-80-on-suse/"/>
    <updated>2014-03-05T18:09:00-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/03/05/binding-jenkins-to-port-80-on-suse</id>
    <content type="html"><![CDATA[<p>I&rsquo;ve been helping an awesome colleague on DevOps for our Jenkins farm, which we use
for continuous integration and continuous deployment to our preproduction environments.</p>

<p>We are really trying to do it right:</p>

<ul>
<li>Use Puppet to provision the Jenkins master, Linux VM build slaves, Windows VM slaves,
and even OS X bare metal slaves (for iOS builds)</li>
<li>Automated backups of Jenkins config files to a private GitHub repo for disster recovery</li>
<li>Patches the GitHub OAuth plugin to make sure you have the same collaborator permissions
(read/write/admin) in a Jenkins job as you do the GitHub repo.</li>
<li>Have a Jenkins staging environment to test upgrades to Jenkins and plugins to avoid surprises.</li>
<li>Run Jenkins on the Long Term Support (LTS) release channel to avoid surprises.</li>
</ul>


<p>I wish my shop used CentOS or Debian; sadly we are stuck on SUSE Enterprise.  SUSE is really
good at turning 5 minute tasks on CentOS or Debian into uber frustrating hour-long ordeals.</p>

<p>One of the glitches we faced was running the Jenkins web UI on port 80.  SUSE lacks the
authbind package for binding to port below port 1024 as a non-root user.  We wanted to run the
Jenkins deamon as a regular privilege user, so running as root was not an option.</p>

<p>We are currently smoke testing this LSB <code>/etc/init.d/jenkins.portforwarding</code> script, which is
just a wrapper around <code>iptables</code>.  So far, it seems to get the job done.</p>

<div><script src='https://gist.github.com/9361161.js'></script>
<noscript><pre><code>#!/bin/sh
#
#     SUSE system statup script for port forwarding port 80 to the port
#     for the Jenkins continuous build server.
#
#     Jenkins normally does not run as root, thus /etc/init.d/jenkins cannot
#     bind to ports &lt; 1024 since SUSE does not support authbind (or similar).
#
#     The MIT License (MIT)
#
#     Copyright (C) 2014 Steve Jansen
#
#     Permission is hereby granted, free of charge, to any person obtaining a copy
#     of this software and associated documentation files (the &quot;Software&quot;), to deal
#     in the Software without restriction, including without limitation the rights
#     to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#     copies of the Software, and to permit persons to whom the Software is
#     furnished to do so, subject to the following conditions:
#
#     The above copyright notice and this permission notice shall be included in
#     all copies or substantial portions of the Software.
#
#     THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#     AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#     THE SOFTWARE.
#
### BEGIN INIT INFO
# Provides:          jenkins.portforwarding
# Required-Start:    jenkins
# Should-Start:
# Required-Stop:     jenkins
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Port forwarding for Jenkins continuous build server
# Description:       Forward port 80 traffic to the Jenkins continuous build server
### END INIT INFO

# Check for existence of needed config file and read it
JENKINS_CONFIG=/etc/sysconfig/jenkins
JENKINS_FORWARD_PORT=80

test -r &quot;$JENKINS_CONFIG&quot; || { echo &quot;$JENKINS_CONFIG not existing&quot;;
  if [ &quot;$1&quot; = &quot;stop&quot; ]; then exit 0;
  else exit 6; fi; }

# Read config
. &quot;$JENKINS_CONFIG&quot;

. /etc/rc.status
rc_reset # Reset status of this service

if [ &quot;$JENKINS_PORT&quot; -eq &quot;$JENKINS_FORWARD_PORT&quot; ]
then
  echo &quot;Jenkins already running on port $JENKINS_FORWARD_PORT, skipping port forwarding&quot;
  rc_exit
fi

readonly iptables_table=&quot;-t nat&quot;
readonly base_rule=&quot;-p tcp --dport $JENKINS_FORWARD_PORT -j REDIRECT --to-ports $JENKINS_PORT&quot;
readonly external_rule=&quot;PREROUTING -p tcp -m tcp --dport $JENKINS_FORWARD_PORT -j REDIRECT --to-ports $JENKINS_PORT&quot;
readonly loopback_rule=&quot;OUTPUT -p tcp -m tcp --dport $JENKINS_FORWARD_PORT -j REDIRECT --to-ports $JENKINS_PORT&quot;

check_status ()
{
  iptables-save $iptables_table | grep -- &quot;$external_rule&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; iptables-save $iptables_table | grep -- &quot;$loopback_rule&quot; &gt; /dev/null 2&gt;&amp;1
  return $?
}

case &quot;$1&quot; in
  start)
      check_status
      if [ $? -eq 0 ]
      then
        echo &quot;Jenkins port forwarding already forwarding port $JENKINS_FORWARD_PORT to port $JENKINS_PORT&quot;
        rc_exit
      fi

      echo &quot;Starting Jenkins port forwarding&quot;
      echo &quot;Enabling iptables port forwarding from port $JENKINS_FORWARD_PORT to port $JENKINS_PORT&quot;
      iptables $iptables_table -A $external_interface $external_rule &amp;&amp; iptables $iptables_table -A $loopback_rule
      result=$?

      if [ $result -eq 0 ]
      then
        rc_status -v
      else
        rc_failed $result
        rc_status -v
      fi
    ;;
  stop)
      check_status
      if [ $? -ne 0 ]
      then
        echo &quot;Jenkins port forwarding already stopped&quot;
        rc_exit
      fi

      echo &quot;Disabling iptables port forwarding from port $JENKINS_FORWARD_PORT to port $JENKINS_PORT&quot;
      iptables $iptables_table -D $external_interface $external_rule &amp;&amp; iptables $iptables_table -D $loopback_rule
      result=$?

      if [ $result -eq 0 ]
      then
        rc_status -v
      else
        rc_failed $result
        rc_status -v
      fi
    ;;
  restart)
      $0 stop
      $0 start
      rc_status
    ;;
    status)
      echo &quot;Checking status of iptables port forwarding from port $JENKINS_FORWARD_PORT to port $JENKINS_PORT&quot;
      check_status
      result=$?

      if [ $result -eq 0 ]
      then
        echo &quot;Port forwarding from port $JENKINS_FORWARD_PORT to port $JENKINS_PORT is enabled&quot;
        rc_status -v
      else
        echo &quot;Port forwarding from port $JENKINS_FORWARD_PORT to port $JENKINS_PORT is disabled&quot;
        rc_failed $result
        rc_status -v
      fi
    ;;
  *)
      echo &quot;Usage: $0 {start|stop|status}&quot;
      exit 1
    ;;
esac
rc_exit
</code></pre></noscript></div>


<p>If all goes well, I will merge this logic into a pull request for the <a href="https://github.com/jenkinsci/jenkins/blob/master/opensuse/SOURCES/jenkins.init.in">Jenkins init.d script for OpenSuse</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A better FTP client for Windows you already have: Git bash's curl command]]></title>
    <link href="http://steve-jansen.github.io/blog/2014/02/15/a-better-ftp-client-for-windows-you-already-have-gits-curl-command/"/>
    <updated>2014-02-15T17:24:00-05:00</updated>
    <id>http://steve-jansen.github.io/blog/2014/02/15/a-better-ftp-client-for-windows-you-already-have-gits-curl-command</id>
    <content type="html"><![CDATA[<p>My shop has a couple of internal FTP servers to mirror commonly used installers for .Net devs.
Installers for apps like Visual Studio can be huge, so GitHub isn&rsquo;t the best place for this, and
it would also smoke most of our Dropbox quotas.  So an FTP server seems like the 3rd best option.</p>

<p>We are a geographically distributed team, with a VPN to access internal servers.  Even with a reliable
VPN session over ISP fiber connection, I&rsquo;ve experience lots of realiability problems downloading large files
with the native Windows Explorer / Internet Explorer FTP.</p>

<p>The Windows ftp command line client can be a pain to work with.  Fortunately, the Git bash emulator for Windows
(msysgit) includes a MinGW port of the awesome <code>curl</code> utility.  The <code>curl</code> utility has all kinds of awesome features
for downloading large files.</p>

<p>Here&rsquo;s a few options I found really useful:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>curl -C - -v -O <span class="s2">&quot;ftp://ftp.example.com/path/to/file.zip&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<ul>
<li><code>-C -</code> option tells bash to automatically continue an interrupted download, if the server supports this feature.</li>
<li><code>-v</code> prints verbose stats, including an dynamic progress info</li>
<li><code>-O</code> automatically saves the file using the remote file name to the current working directory</li>
</ul>


<p>I crafted this gist to enable downloading a large number of binaries related to .Net development from our FTP server.</p>

<div><script src='https://gist.github.com/9378219.js'></script>
<noscript><pre><code>SETLOCAL
PUSHD &quot;%USERPROFILE%\Downloads&quot;

IF NOT EXIST &quot;installers&quot; MKDIR &quot;installers&quot;
CD &quot;installers&quot;

ECHO @ECHO OFF &gt; curl.cmd
ECHO TITLE &quot;%~1&quot; &gt;&gt; curl.cmd
ECHO IF NOT &quot;.%~p1&quot;==&quot;.\&quot; IF NOT EXIST &quot;.%~p1&quot; MKDIR &quot;.%~p1&quot; &gt;&gt; curl.cmd
ECHO PUSHD &quot;.%~p1&quot; &gt;&gt; curl.cmd
ECHO &quot;%ProgramFiles%\Git\bin\curl.exe&quot; -C - -v -O &quot;ftp://ftp.example.com/path/to/installers%~1&quot; ^&amp;^&amp; PAUSE &gt;&gt; curl.cmd

START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/dotNetFx40_Full_x86_x64.exe^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Internet Information Services 7.5 Express/iisexpress_1_11_x86_en-US.msi^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Internet Information Services 7.5 Express/rewrite_2.0_rtw_x86.msi^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft SQL Server 2008 Express R2 SP1/SQLEXPRWT_x86_ENU.exe^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft Visual Studio 2010/VS2010PREM_ENU.zip^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft Visual Studio 2010 SP1/VS10sp1-KB983509.exe^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft SQL Server Data Tools/SSDT_10.3.31009.2_EN.iso.zip^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft SQL Server 2012 Tools/SQLManagementStudio_x86_ENU.exe^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft SQL Server 2012 Tools/x86/SqlLocaLDB.MSI^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/Microsoft Web Deploy V3/WebDeploy_x86_en-US.msi^&quot;&quot;
START &quot;&quot; &quot;%COMSPEC%&quot; /D /C &quot;curl.cmd ^&quot;/MSBuild Extension Pack 4.0/MSBuild Extension Pack 4.0.msi^&quot;&quot;

DEL /Q curl.cmd
POPD
ENDLOCAL</code></pre></noscript></div>


<p>Be warned, this hack spawns a new command prompt window for each download, so it can get a bit crazy.  This seemed like
the best worst way to download in parallel while also making sense of each download&rsquo;s status.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Breaking the 3GB memory barrier of 32-bit Windows]]></title>
    <link href="http://steve-jansen.github.io/blog/2013/10/03/breaking-the-3gb-memory-barrier-of-32-bit-windows/"/>
    <updated>2013-10-03T22:22:02-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2013/10/03/breaking-the-3gb-memory-barrier-of-32-bit-windows</id>
    <content type="html"><![CDATA[<p>My corporate laptop has 6 GB of RAM installed, but, only sees 3 GB of logical RAM. Why?  My corporate IT department
images laptops with the 32-bit flavor of  Windows 7.</p>

<p>As you can see in this screenshot from my Control Panel&rsquo;s System information applet, installing more memory hits a glass ceiling with Windows at ~3GB.</p>

<p><img src="http://steve-jansen.github.io/images/2013-10-03-A.gif" alt="System information screenshot showing 3GB of RAM" /></p>

<p>My laptop has 6 GB of physical RAM installed, yet my user applications have access to less than half of the physical memory!</p>

<h2>Hacking a Solution: &ldquo;Physical Virtual Memory&rdquo;</h2>

<p>Fortunately, there is a solution to this problem. It&rsquo;s a hack and it uses a reasonably priced piece of 3rd party commercial software.</p>

<p>The solution combines a feature of Windows known as Physical Address Extensions (PAE) in tandem with a RAMDISK as the storage &ldquo;disk&rdquo; for the virtual memory paging file. The result is a total hack &ndash; we&rsquo;re using a page file to expose the address space of physical memory. It&rsquo;s &ldquo;physical virtual&rdquo; memory. An oxymoron if I ever heard one!</p>

<p>A commercial software package called <a href="http://www.romexsoftware.com/en-us/primo-ramdisk/">Primo Ramdisk Standard</a> by Romex Software is needed to create the Ramdisk. It&rsquo;s $30/seat.</p>

<p>This is the only Ramdisk driver I could find that:</p>

<ol>
<li>Supports Windows 7</li>
<li>Supports PAE</li>
<li>Supports the Intel/AMD physical memory remapping (&ldquo;Invisible Memory&rdquo;) chipset feature (<a href="http://www.polywell.com/us/support/faq/4gb_rev1.pdf">read more</a>)</li>
<li>Not flagged as a removable storage device by our corporate data loss prevention nanny software</li>
</ol>


<h2>Performance</h2>

<p>Indeed, the performance of this hack to use &ldquo;physical virtual memory&rdquo; will be less than just using a 64 bit O/S with it&rsquo;s address space of 2<sup>64</sup> bytes. Nevertheless, paging to a RAMDISK will always beat paging to a magnetic hard drive, and will probably beat paging to a SSD disk as well.</p>

<p>I speculate there are a number of very good reasons why corporate IT would deploy 32-bit over 64-bit &ndash; availability of 64-bit client software for VPNs, anti-malware, remote backup agents, remote support agents, encryption policy engines; the difficulty in recreating and testing a new image from scratch; the density of older 32-bit laptops still in use.</p>

<h2>Known Issues</h2>

<p><strong>Caveat Emptor:</strong>  You must disable hibernation mode.  Hibernating sporadically crashes upon shutdown or startup when using this hack.  The good news is you will not miss much.  My laptop clocked faster times with a normal shutdown/startup cycle compared to the time required to enter and exit hibernation.  The disk IO was just too slow to copy 6 GB of RAM contents to into and out of the C:\hiberfil.sys hibernation file.</p>

<h2>Testing</h2>

<p>This setup was tested successfully for over one year on a Lenovo ThinkPad T410 with 6 GB of RAM (2 GB +4 GB DIMMS) as well as one year on a Lenovo T420s with 8 GB of RAM.  Please test your setup.  Should your machine fail to restart after following below steps, you should boot into Windows Safe Mode and disable/uninstall the RAMDISK driver and paging file.</p>

<h3>Setup (8 steps)</h3>

<h2>Step 1</h2>

<p>Enable PAE in the Windows boot options, disable hibernation in the power options for Windows, and reboot the system.</p>

<p>Run the following commands in Command Prompt (cmd.exe).   Note this will force a restart in 30 seconds, so save your work.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>bcdedit /set pae ForceEnable 
</span><span class='line'>bcdedit /enum | FINDSTR pae 
</span><span class='line'>powercfg.exe /hibernate off 
</span><span class='line'>shutdown /r /t 30 /d p:1:1 </span></code></pre></td></tr></table></div></figure>


<p><img src="http://steve-jansen.github.io/images/2013-10-03-B.gif" alt="Screenshot of command prompt usage in step 1" /></p>

<h2>Step 2</h2>

<p>Install the commercial software <a href="http://www.romexsoftware.com/en-us/primo-ramdisk/index.html">Primo Ramdisk Standard</a> by a vendor named Romex. There is a $30/seat license cost.  Romex offers a 30 day free trial.</p>

<h2>Step 3</h2>

<p>Launch the Primo Ramdisk configuration program. (&ldquo;%ProgramFiles%\Primo Ramdisk Standard Edition\FancyRd.exe&rdquo;)</p>

<h2>Step 4</h2>

<p>Launch the dialog to configure &ldquo;Invisible Memory Management&rdquo;</p>

<p>Click the icon in the lower right corner of the configuration program that resembles an blue SD Card and a yellow wrench.  On the dialog, click the &ldquo;Enable IM&rdquo; button.  The default options worked successfully a Lenovo ThinkPad T410 (BIOS) and a Lenovo T420s (UEFI).  See the Romex documentation on front-end/back-end reserve if you experience video card problems on your hardware.</p>

<p><img src="http://steve-jansen.github.io/images/2013-10-03-C.gif" alt="Screenshot of configuring &quot;Invisible Memory Management&quot; in step 2" /></p>

<h2>Step 5</h2>

<p>Define a new RAMDISK</p>

<p>a) Take note of the maximum amount of available invisible memory as displayed in the lower right hand corner of the main window.  This will be the size of the RAMDISK.</p>

<p>b) Click the &ldquo;Create a new disk&rdquo; toolbar button to define a new persistent RAMDISK</p>

<p>c) Select &ldquo;Direct-IO&rdquo; as the disk type.  This is the faster of the two options.  Also, Credant will only ignore this device type.</p>

<p>d) Assign a drive letter of &ldquo;Z&rdquo;.  This can be changed, however, a later step will need to be manually adjusted.</p>

<p>e) Leave &ldquo;One Time Disk&rdquo; unchecked to make this disk persistent across boots.</p>

<p>f) On the next dialog screen, enable the option for &ldquo;Use Invisible Memory&rdquo;.  Leave all other options unchecked/disabled.</p>

<p>g) On the final dialog screen, select the FAT32 format and label the device &ldquo;RAMDISK&rdquo;.</p>

<p>Screenshots:</p>

<p><img src="http://steve-jansen.github.io/images/2013-10-03-E.gif" alt="Screenshot of defining a new RAMDISK in step 5" />
<img src="http://steve-jansen.github.io/images/2013-10-03-F.gif" alt="Screenshot of defining a new RAMDISK in step 5" />
<img src="http://steve-jansen.github.io/images/2013-10-03-D.gif" alt="Screenshot of defining a new RAMDISK in step 5" />
<img src="http://steve-jansen.github.io/images/2013-10-03-G.gif" alt="Screenshot of defining a new RAMDISK in step 5" /></p>

<h2>Step 6</h2>

<p>Modify Windows&#8217; Virtual Memory settings</p>

<p>a) Run &ldquo;sysdm.cpl&rdquo; to open System Properties</p>

<p>b) Open the virtual memory dialog by selecting  Advanced > Performance > Settings > Advanced > Virtual Memory > Change</p>

<p>c) Uncheck/disable &ldquo;Automatically manage paging file size for all drives&rdquo;</p>

<p>d) Select the &ldquo;C:&rdquo; drive in the drive list, and select the &ldquo;No paging file&rdquo; option.  Click the Set button.</p>

<p>e) Select the &ldquo;Z:&rdquo; drive in the drive list, and select &ldquo;Custom&rdquo; size of X for initial and maximum, where X is the space available listed for the drive. You may need to slightly reduce X by ~5 megabytes.</p>

<p>f) Click the &ldquo;Set&rdquo; button and confirm your settings resemble the screenshot below.  Click the &ldquo;Ok&rdquo; button.</p>

<p><img src="http://steve-jansen.github.io/images/2013-10-03-H.gif" alt="Screenshot of modifying Windows virtual memory settings in step 6" /></p>

<h2>Step 7</h2>

<p>Hide the Z: drive from Explorer</p>

<p>Windows will be very annoying about the Z: drive being full.  You can hide this drive from Explorer and the common dialogs with the following registry setting.  Note you can still explicity access this drive with a full file path in any open/save dialog (e.g., Z:\folder\file.ext). If you changed the drive letter for the RAMDISK from Z: to something else, you will need to adjust the hex value of the registry key (see TechNet for the correct hex value).</p>

<p>Run the following commands in Command Prompt (cmd.exe):</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDrives /t REG_DWORD /d 0x02000000
</span><span class='line'>REG add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoLowDiscSpaceChecks /t REG_DWORD /d 1</span></code></pre></td></tr></table></div></figure>


<p><img src="http://steve-jansen.github.io/images/2013-10-03-I.gif" alt="Screenshot of disabling Explorer disk space warnings for the new RAMDISK in step 7" /></p>

<h2>Step 8</h2>

<p>Reboot</p>

<p>It&rsquo;s Windows, why not throw in a reboot?</p>

<h2>Final Thoughts</h2>

<p>My Windows setup recommends 3 GB of virtual memory.  I&rsquo;d like to try upgrading my physical RAM from 6 GB to 8GB.  This would let me add another gigabyte to the paging file.  It would also leave another 1 GB of free space on Z:.  I&rsquo;m considering using this free space as a NTFS junction point with &ldquo;%TEMP%&rdquo; and &ldquo;%SYSTEMROOT%\TEMP&rdquo; to make the temp folders both fast and non-persistent between reboots.  (Junction points are the Windows equivalent of *nix symlinks for directories.  You can use the Sysinternals utility junction.exe or the Primo Ramdisk utility to define junction points.)</p>

<p>I also want to test setting my IIS document root to Z: to make tests of deployment packages lightning fast (i.e., relocating the IIS document root from C:\inetpub to Z:\inetpub).  This will make disk I/O way faster for copying scores of little image and text files.  It also forces me to run an automated build/package/deploy between reboots (since Z:\ is wiped between reboots).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Are great developers both left and right brain expressive?]]></title>
    <link href="http://steve-jansen.github.io/blog/2013/09/12/are-great-developers-both-left-and-right-brain-expressive/"/>
    <updated>2013-09-12T22:57:00-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2013/09/12/are-great-developers-both-left-and-right-brain-expressive</id>
    <content type="html"><![CDATA[<p>My wondeful wife pointed to me this outstanding visualization of left vs. right brain expression.</p>

<p>It made me thing that a great developer is probably expressive on both sides: you clearly need the academic
properties of the left brain: logic, analysis, objectivity.</p>

<p>But the right side creativity is also going to
be needed to create something worth using, something that impacts our daily lives, something with an
outstanding user experience.</p>

<p><img src="http://steve-jansen.github.io/images/vaxzine.png" alt="Creative Commons visualization by VaXzine" /></p>

<p><a href="http://www.flickr.com/people/vaxzine/">CC visualization by VaXzine</a></p>

<p>What do you think?  Are great devs truly ambidextrous of the mind?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[GitHub sings the praises of a distributed workforce]]></title>
    <link href="http://steve-jansen.github.io/blog/2013/09/10/github-sings-the-praises-of-a-distributed-workforce/"/>
    <updated>2013-09-10T21:41:00-04:00</updated>
    <id>http://steve-jansen.github.io/blog/2013/09/10/github-sings-the-praises-of-a-distributed-workforce</id>
    <content type="html"><![CDATA[<p>Tom Preston-Werner, co-founder of <a href="GitHub.com">GitHub.com</a>, highlights the competitive advantages behind a number
of company virtues I admire.   A few of these virtues are organic growth, outstanding user experience, and a distributed workforce.</p>

<p>Below is an video excerpt from a fireside chat interview with Mr. Preston-Werner from July 2013, speaking to the benefits
of a remote workers, particularly developers:</p>

<div class="embed-video-container"><iframe src="http://www.youtube.com/embed/n1YXkd4r2gw "></iframe></div>


<p>One of the most memorable quotations from the interview is:</p>

<blockquote><p>&ldquo;Companies that aren&rsquo;t distributed can&rsquo;t possibly say that they hire the best people.&rdquo;</p></blockquote>

<p>I have the privilege of working at a great employer that also &ldquo;gets it&rdquo;.  Most of my colleagues are remote workers across
nearly every time zone.  Constraining your team to a single city is a self-imposed barrier,
particularly for creative work like coding that fits brilliantly with remote collaboration.</p>
]]></content>
  </entry>
  
</feed>
