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

<channel>
	<title>Michael Conigliaro &#187; Mike</title>
	<atom:link href="http://conigliaro.org/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://conigliaro.org</link>
	<description>cat /dev/brain &#124; grep technology &#62;&#62; blog</description>
	<lastBuildDate>Wed, 25 Aug 2010 23:46:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to ensure that only one instance of a script can run at a time</title>
		<link>http://conigliaro.org/2010/07/17/how-to-ensure-that-only-one-instance-of-a-script-can-run-at-a-time/</link>
		<comments>http://conigliaro.org/2010/07/17/how-to-ensure-that-only-one-instance-of-a-script-can-run-at-a-time/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 21:55:05 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=950</guid>
		<description><![CDATA[Whenever someone asks for a quick way to ensure that only one instance of a script can run at a time, I see a lot of people giving advice involving temporary lock/PID files (see here, here, and here). This is probably fine for most purposes, but I wonder why more people don&#8217;t just check the [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever someone asks for a quick way to ensure that only one instance of a script can run at a time, I see a lot of people giving advice involving temporary lock/PID files (see <a href="http://stackoverflow.com/questions/185451/quick-and-dirty-way-to-ensure-only-one-instance-of-a-shell-script-is-running-at-a">here</a>, <a href="http://stackoverflow.com/questions/661684/how-to-ensure-only-one-instance-of-a-ruby-script-is-running-at-a-time">here</a>, and <a href="http://stackoverflow.com/questions/3080991/having-trouble-allowing-only-one-instance-of-a-php-script-at-a-time-using-cron">here</a>). This is probably fine for most purposes, but I wonder why more people don&#8217;t just check the process table:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SCRIPT_NAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">`</span>pgrep <span style="color: #660033;">-c</span> <span style="color: #800000;">${SCRIPT_NAME}</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error: An instance of this script is already running!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>This fragment uses <strong>pgrep</strong> to count the number of running processes with the same name as the currently running script. If the number of these processes is greater than one (the current script will always be counted), then we know that another instance is already running. </p>
<p>As far as I know (and I hope someone will correct me if I&#8217;m wrong), this technique avoids the race conditions associated with lock/PID files. It also avoids the possibility of orphaned lock/PID files in the event that your script doesn&#8217;t complete and is unable to clean up after itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/07/17/how-to-ensure-that-only-one-instance-of-a-script-can-run-at-a-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>dynect4r: A Ruby Library and Command Line Client for the Dynect REST API (Version 2)</title>
		<link>http://conigliaro.org/2010/07/09/dynect4r-a-ruby-library-and-command-line-client-for-the-dynect-rest-api-version-2/</link>
		<comments>http://conigliaro.org/2010/07/09/dynect4r-a-ruby-library-and-command-line-client-for-the-dynect-rest-api-version-2/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 16:39:54 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=943</guid>
		<description><![CDATA[Well, I should have listened to everyone who warned me about UltraDNS&#8217;s obscene prices. But I figured it&#8217;s only DNS, so how much more could they be compared to their competition? $50 per month? Maybe $100? Boy was I surprised to find out that UltraDNS&#8217;s prices are literally 10-25 times more than everyone else&#8217;s! Hilarious&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I should have listened to everyone who warned me about UltraDNS&#8217;s obscene prices. But I figured it&#8217;s only DNS, so how much more could they be compared to their competition? $50 per month? Maybe $100? Boy was I surprised to find out that UltraDNS&#8217;s prices are literally 10-25 times more than everyone else&#8217;s! Hilarious&#8230;</p>
<p>I&#8217;ve actually been a <a href="http://www.dyndns.com/">DynDNS</a> customer since the late nineties or so (I have free custom DNS service for life for making a donation to them back when they were a <em>much</em> smaller company), so I had looked at <a href="http://dyn.com/">Dyn.com</a>&#8216;s products before. I just must have gotten confused with all their different websites and DNS products, because I somehow got the impression that the DynDNS API wasn&#8217;t powerful enough to do what I wanted to do. I was absolutely wrong. After having written command line clients for both APIs (see <a href="/2010/05/15/ultradns4r-a-ruby-library-and-command-line-client-for-the-neustar-ultradns-soap-api/">ultradns4r</a>, and now <a href="http://github.com/mconigliaro/dynect4r">dynectr4</a>), I think I speak from authority when I say the Dynect API is every bit as powerful as UltraDNS&#8217;s. And at 1/10th &#8211; 1/25th the cost of UltraDNS, going with Dynect is a no-brainer. But I&#8217;ve digressed long enough.</p>
<p>I wrote dynect4r for the same reason I wrote ultradns4r; I wanted to be able to manage all my DNS records via the command line. And now that I&#8217;ve learned how to package Ruby projects as gems, you can simply&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> dynect4r</pre></div></div>

<p>and then do things like&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dynect4r-client <span style="color: #660033;">-n</span> test.example.org 1.1.1.1</pre></div></div>

<p>Since the key feature of this project is the command line client, the actual library behind it is a pretty simple wrapper around <a href="http://github.com/archiloque/rest-client">rest-client</a>. If you&#8217;re looking for something a bit more powerful to use in your own Ruby projects, you may be interested in <a href="http://github.com/adamhjk/dynect_rest">dynect_rest</a> by Adam Jacob from <a href="http://opscode.com/">Opscode</a>. We actually discovered each other&#8217;s projects last night in #chef, and realized that it would probably be a good idea to pool our efforts eventually.</p>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/07/09/dynect4r-a-ruby-library-and-command-line-client-for-the-dynect-rest-api-version-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Chef Definition for Managing Iptables Rules</title>
		<link>http://conigliaro.org/2010/05/26/a-chef-definition-for-managing-iptables-rules/</link>
		<comments>http://conigliaro.org/2010/05/26/a-chef-definition-for-managing-iptables-rules/#comments</comments>
		<pubDate>Wed, 26 May 2010 19:04:30 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Chef]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=933</guid>
		<description><![CDATA[I wrote a Chef definition for managing Iptables rules a while back, but until now, it has only existed publicly as gist on github. I figured I&#8217;d post it here as an example of how to write your own Chef definitions. The first thing I did was create an iptables cookbook with a default recipe [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a Chef definition for managing Iptables rules a while back, but until now, it has only existed publicly as gist on github. I figured I&#8217;d post it here as an example of how to write your own Chef definitions.</p>
<p>The first thing I did was create an iptables cookbook with a default recipe that simply ensures that the iptables package is installed:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">package <span style="color:#996600;">&quot;iptables&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  package_name <span style="color:#996600;">&quot;iptables&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Next, I used the <a href="http://wiki.opscode.com/display/chef/Definitions">definitions documentation on the Opscode wiki</a> to write the actual definition. What I&#8217;m basically doing here is accepting a few Iptables-specific parameters (table, chain, options) and dynamically building the <a href="http://wiki.opscode.com/display/chef/Resources#Resources-Execute">execute resources</a> to run the appropriate Iptables commands:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">define <span style="color:#ff3333; font-weight:bold;">:iptables_rule</span>, <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:table</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;filter&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:chain</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>, <span style="color:#ff3333; font-weight:bold;">:options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  include_recipe <span style="color:#996600;">&quot;iptables&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:table</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;Missing required argument: table&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:chain</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:chain</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;Missing required argument: chain&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:options</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">empty</span>?
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">ArgumentError</span>, <span style="color:#996600;">&quot;Missing required argument: options&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  iptables_bin = <span style="color:#996600;">&quot;/sbin/iptables&quot;</span>
  rule_id = <span style="color:#996600;">&quot;Chef Rule: #{params[:name]}&quot;</span>
  comment = <span style="color:#996600;">&quot;-m comment --comment <span style="color:#000099;">\&quot;</span>#{rule_id}<span style="color:#000099;">\&quot;</span>&quot;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:action</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#ff3333; font-weight:bold;">:delete</span>
    execute <span style="color:#996600;">&quot;delete_iptables_rule-#{params[:name]}&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      command <span style="color:#996600;">&quot;#{iptables_bin} --table #{params[:table]} -D #{params[:chain]} #{params[:options]} #{comment}&quot;</span>
      only_if <span style="color:#996600;">&quot;#{iptables_bin} --table #{params[:table]} -S #{params[:chain]} | /bin/grep <span style="color:#000099;">\&quot;</span>#{rule_id}<span style="color:#000099;">\&quot;</span>&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    execute <span style="color:#996600;">&quot;create_iptables_rule-#{params[:name]}&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      command <span style="color:#996600;">&quot;#{iptables_bin} --table #{params[:table]} -A #{params[:chain]} #{params[:options]} #{comment}&quot;</span>
      not_if <span style="color:#996600;">&quot;#{iptables_bin} --table #{params[:table]} -S #{params[:chain]} | /bin/grep <span style="color:#000099;">\&quot;</span>#{rule_id}<span style="color:#000099;">\&quot;</span>&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>So now when I want to manage an Iptables rule with chef, I can just do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">iptables_rule <span style="color:#996600;">&quot;jetty_port_80&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  table <span style="color:#996600;">&quot;nat&quot;</span>
  chain <span style="color:#996600;">&quot;PREROUTING&quot;</span>
  options <span style="color:#996600;">&quot;--proto tcp --dport 80 --jump REDIRECT --to-port 8080&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/26/a-chef-definition-for-managing-iptables-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ultradns4r: A Ruby Library and Command Line Client for the Neustar UltraDNS SOAP API</title>
		<link>http://conigliaro.org/2010/05/15/ultradns4r-a-ruby-library-and-command-line-client-for-the-neustar-ultradns-soap-api/</link>
		<comments>http://conigliaro.org/2010/05/15/ultradns4r-a-ruby-library-and-command-line-client-for-the-neustar-ultradns-soap-api/#comments</comments>
		<pubDate>Sat, 15 May 2010 20:30:53 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[DNS]]></category>
		<category><![CDATA[EC2]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=917</guid>
		<description><![CDATA[I just spent the last week or so learning more about SOAP than I ever wanted to know. ;-) Fortunately, the result of that hard work resulted in something that might benefit the EC2 community. I am pleased to announce ultradns4r; a Ruby library and command line client for the Neustar UltraDNS SOAP API. I [...]]]></description>
			<content:encoded><![CDATA[<p>I just spent the last week or so learning more about SOAP than I ever wanted to know. ;-) Fortunately, the result of that hard work resulted in something that might benefit the EC2 community.</p>
<p>I am pleased to announce <a href="http://github.com/mconigliaro/ultradns4r">ultradns4r</a>; a Ruby library and command line client for the <a href="http://www.ultradns.com/">Neustar UltraDNS</a> <a href="http://www.ultradns.net/api/NUS_API_XML_SOAP.pdf">SOAP API</a>. I created this tool to alleviate the pain in dealing with EC2&#8242;s dynamic hostnames and IP addresses. Since it allows editing of arbitrary DNS records via the command line, it can be used to make EC2 instances update their own DNS records.</p>
<h4>Lessons Learned</h4>
<ul>
<li>If you need to do SOAP in Ruby, just use <a href="http://savon.rubiii.com/">Savon</a>. Trust me on this.</li>
<li>WSSE authentication is a complete pain in the ass. I was unable to find any SOAP library (Ruby, Python, or Perl) that could authenticate with the UltraDNS API servers out of the box (Savon included). I ended up having to build the entire WSSE header manually in order to generate the exact XML needed.</li>
<li>Apparently, element order sometimes matters with SOAP! This is something I never expected, considering that (last I knew) the XML spec does not even allow you to enforce element or attribute order. This was also the cause of a lot of my WSSE problems. I found that for example, if the Password element came after the Nonce and Created elements (which is the case if you use Savon&#8217;s built-in WSSE authentication), then authentication would fail. Could this have been the result of having a buggy XML parser on the server side? In any case, this is one of those annoying issues to be aware of.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/15/ultradns4r-a-ruby-library-and-command-line-client-for-the-neustar-ultradns-soap-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better Disk Monitoring with Ganglia</title>
		<link>http://conigliaro.org/2010/05/10/better-disk-monitoring-with-ganglia/</link>
		<comments>http://conigliaro.org/2010/05/10/better-disk-monitoring-with-ganglia/#comments</comments>
		<pubDate>Mon, 10 May 2010 17:56:44 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Ganglia]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=911</guid>
		<description><![CDATA[The default disk monitoring module for Ganglia (moddisk.so) is pretty stupid, since it simply sums up the free disk space on all of your disks and presents it in a single graph. Frankly, this just doesn&#8217;t tell you much, so I wrote a more useful replacement: moddisk.py moddisk.pyconf This module reads a list of mounted [...]]]></description>
			<content:encoded><![CDATA[<p>The default disk monitoring module for Ganglia (moddisk.so) is pretty stupid, since it simply sums up the free disk space on <strong>all</strong> of your disks and presents it in a single graph. Frankly, this just doesn&#8217;t tell you much, so I wrote a more useful replacement:</p>
<ul>
<li><a href="http://github.com/mconigliaro/Ganglia-Modules/blob/master/moddisk.py">moddisk.py</a></li>
<li><a href="http://github.com/mconigliaro/Ganglia-Modules/blob/master/moddisk.pyconf">moddisk.pyconf</a></li>
</ul>
<p>This module reads a list of mounted file systems from a file (probably <strong>/proc/mounts</strong>) and creates a metric for each one, allowing you to graph disk usage for each file system separately. Enjoy!</p>
<p><strong>Update:</strong> It appears that <a href="http://sourceforge.net/apps/trac/ganglia/browser/trunk/monitor-core/gmond/python_modules/disk/multidisk.py">multidisk.py</a> does the same thing, and is probably already included with your distribution. Oops! ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/10/better-disk-monitoring-with-ganglia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tokyo Tyrant Monitoring with Ganglia</title>
		<link>http://conigliaro.org/2010/05/07/tokyo-tyrant-monitoring-with-ganglia/</link>
		<comments>http://conigliaro.org/2010/05/07/tokyo-tyrant-monitoring-with-ganglia/#comments</comments>
		<pubDate>Fri, 07 May 2010 16:49:58 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Ganglia]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tokyo Tyrant]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=903</guid>
		<description><![CDATA[I&#8217;ve recently written a Python module to graph some interesting Tokyo Tyrant metrics with Ganglia. It basically just parses the output of tcrmgr inform -st localhost, so you&#8217;ll probably need to update the pyconf file with the correct location of the tcrmgr command. But this module also gives you some neat things that tcrmgr doesn&#8217;t, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently written a Python module to graph some interesting Tokyo Tyrant metrics with Ganglia. It basically just parses the output of <strong>tcrmgr inform -st localhost</strong>, so you&#8217;ll probably need to update the pyconf file with the correct location of the tcrmgr command. But this module also gives you some neat things that tcrmgr doesn&#8217;t, like the current number of Get/Put/Out operations per second rather than just the total number of operations since the server was started.</p>
<ul>
<li><a href="http://github.com/mconigliaro/Ganglia-Modules/blob/master/modtokyotyrant.py">modtokyotyrant.py</a></li>
<li><a href="http://github.com/mconigliaro/Ganglia-Modules/blob/master/modtokyotyrant.pyconf">modtokyotyrant.pyconf</a></li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/07/tokyo-tyrant-monitoring-with-ganglia/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to Configure Proper WordPress Permissions</title>
		<link>http://conigliaro.org/2010/05/06/script-to-configure-proper-wordpress-permissions/</link>
		<comments>http://conigliaro.org/2010/05/06/script-to-configure-proper-wordpress-permissions/#comments</comments>
		<pubDate>Thu, 06 May 2010 20:13:25 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=899</guid>
		<description><![CDATA[#!/bin/bash # # This script configures WordPress file permissions based on recommendations # from http://codex.wordpress.org/Hardening_WordPress#File_permissions # # Author: Michael Conigliaro &#60;mike [at] conigliaro [dot] org&#62; # WP_OWNER=changeme WP_GROUP=changeme WP_ROOT=/home/changeme WS_GROUP=changeme &#160; # reset to safe defaults find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} &#123;&#125; \; find ${WP_ROOT} -type d -exec chmod 755 &#123;&#125; \; find ${WP_ROOT} -type [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script configures WordPress file permissions based on recommendations</span>
<span style="color: #666666; font-style: italic;"># from http://codex.wordpress.org/Hardening_WordPress#File_permissions</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Author: Michael Conigliaro &lt;mike [at] conigliaro [dot] org&gt;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">WP_OWNER</span>=changeme
<span style="color: #007800;">WP_GROUP</span>=changeme
<span style="color: #007800;">WP_ROOT</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>changeme
<span style="color: #007800;">WS_GROUP</span>=changeme
&nbsp;
<span style="color: #666666; font-style: italic;"># reset to safe defaults</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #800000;">${WP_OWNER}</span>:<span style="color: #800000;">${WP_GROUP}</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span> <span style="color: #660033;">-type</span> d <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
&nbsp;
<span style="color: #666666; font-style: italic;"># allow wordpress to manage wp-config.php (but prevent world access)</span>
<span style="color: #c20cb9; font-weight: bold;">chgrp</span> <span style="color: #800000;">${WS_GROUP}</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>wp-config.php
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">660</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>wp-config.php
&nbsp;
<span style="color: #666666; font-style: italic;"># allow wordpress to manage .htaccess</span>
<span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>.htaccess
<span style="color: #c20cb9; font-weight: bold;">chgrp</span> <span style="color: #800000;">${WS_GROUP}</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>.htaccess
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">664</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>.htaccess
&nbsp;
<span style="color: #666666; font-style: italic;"># allow wordpress to manage wp-content</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>wp-content <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chgrp</span> <span style="color: #800000;">${WS_GROUP}</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>wp-content <span style="color: #660033;">-type</span> d <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">775</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #800000;">${WP_ROOT}</span><span style="color: #000000; font-weight: bold;">/</span>wp-content <span style="color: #660033;">-type</span> f <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">664</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/06/script-to-configure-proper-wordpress-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML-RPC over SSL with Ruby and &#8220;warning: peer certificate won&#8217;t be verified in this SSL session&#8221;</title>
		<link>http://conigliaro.org/2010/05/03/xml-rpc-over-ssl-with-ruby-and-warning-peer-certificate-wont-be-verified-in-this-ssl-session/</link>
		<comments>http://conigliaro.org/2010/05/03/xml-rpc-over-ssl-with-ruby-and-warning-peer-certificate-wont-be-verified-in-this-ssl-session/#comments</comments>
		<pubDate>Mon, 03 May 2010 21:06:56 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=894</guid>
		<description><![CDATA[When using XML-RPC over SSL with Ruby, you may receive the following annoying warning: warning: peer certificate won't be verified in this SSL session There is a very simple (but very poorly documented) fix for this. After instantiating your XMLRPC::Client object&#8230; server = XMLRPC::Client.new3&#40; ... &#41; Add the following line: server.instance_variable_get&#40;:@http&#41;.instance_variable_get&#40;:@ssl_context&#41;.instance_variable_set&#40;:@verify_mode, OpenSSL::SSL::VERIFY_NONE&#41; Now do your [...]]]></description>
			<content:encoded><![CDATA[<p>When using XML-RPC over SSL with Ruby, you may receive the following annoying warning:</p>
<pre>
warning: peer certificate won't be verified in this SSL session
</pre>
<p>There is a very simple (but very poorly documented) fix for this. After instantiating your XMLRPC::Client object&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">server = <span style="color:#6666ff; font-weight:bold;">XMLRPC::Client</span>.<span style="color:#9900CC;">new3</span><span style="color:#006600; font-weight:bold;">&#40;</span> ... <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Add the following line:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">server.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>:@http<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>:@ssl_context<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">instance_variable_set</span><span style="color:#006600; font-weight:bold;">&#40;</span>:@verify_mode, <span style="color:#6666ff; font-weight:bold;">OpenSSL::SSL::VERIFY_NONE</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now do your XML-RPC calls as usual:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">result = server.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span> ... <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/05/03/xml-rpc-over-ssl-with-ruby-and-warning-peer-certificate-wont-be-verified-in-this-ssl-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tokyo Tyrant Update Log (ulog) Management</title>
		<link>http://conigliaro.org/2010/04/28/tokyo-tyrant-update-log-ulog-management/</link>
		<comments>http://conigliaro.org/2010/04/28/tokyo-tyrant-update-log-ulog-management/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 16:04:26 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Tokyo Tyrant]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=884</guid>
		<description><![CDATA[When setting up dual-master replication for Tokyo Tyrant, it won&#8217;t be long before you discover that old update logs hang around forever and eventually cause your disk to fill up. I found this sample script that attempts to remedy the problem, but I also found it pretty scary that it blindly deletes old logs without [...]]]></description>
			<content:encoded><![CDATA[<p>When setting up dual-master replication for <a href="http://1978th.net/tokyotyrant/">Tokyo Tyrant</a>, it won&#8217;t be long before you discover that old update logs hang around forever and eventually cause your disk to fill up. I found <a href="http://serverfault.com/questions/26777/tokyo-tyrant-ulog-update-log-management">this sample script that attempts to remedy the problem</a>, but I also found it pretty scary that it blindly deletes old logs without taking the replication delay into account. This means that (however unlikely it may be) it&#8217;s possible to delete logs prematurely. The script below uses the replication delay to figure out which logs are safe to delete, and it also allows you retain a certain number of old logs just in case. Stick this in a cron job, and you&#8217;re good to go:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script queries a slave to see how far behind it is in its replication</span>
<span style="color: #666666; font-style: italic;"># (i.e. the 'delay'). This number is used to figure out which update logs are</span>
<span style="color: #666666; font-style: italic;"># safe to delete.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Author: Michael Conigliaro &lt;mike [at] conigliaro [dot] org&gt;</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">SLAVE</span>=ttslave.example.com
<span style="color: #007800;">ALWAYS_KEEP</span>=<span style="color: #000000;">1440</span>
<span style="color: #007800;">ULOG_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>tokyo<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>ttserver.ulog
&nbsp;
<span style="color: #666666; font-style: italic;"># get all slave stats (exit on failure)</span>
<span style="color: #007800;">OUTPUT</span>=<span style="color: #000000; font-weight: bold;">`</span>tcrmgr inform <span style="color: #660033;">-st</span> <span style="color: #007800;">$SLAVE</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># use the delay value to figure out how many minutes worth of ulogs to keep</span>
<span style="color: #007800;">DELAY</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%s&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$OUTPUT</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> delay <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">OLDER_THAN</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${DELAY/\.*/}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">60</span>+<span style="color: #007800;">$ALWAYS_KEEP</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># delete old ulogs</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;delay=%ssec (sec), older_than=%s (mins)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #007800;">$DELAY</span> <span style="color: #007800;">$OLDER_THAN</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #007800;">$ULOG_DIR</span> <span style="color: #660033;">-maxdepth</span> <span style="color: #000000;">1</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.ulog&quot;</span> <span style="color: #660033;">-type</span> f <span style="color: #660033;">-mmin</span> +<span style="color: #800000;">${OLDER_THAN}</span> <span style="color: #660033;">-exec</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-v</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/04/28/tokyo-tyrant-update-log-ulog-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Am I one of the 10% of programmers who can write a binary search?</title>
		<link>http://conigliaro.org/2010/04/19/am-i-one-of-the-10-of-programmers-who-can-write-a-binary-search/</link>
		<comments>http://conigliaro.org/2010/04/19/am-i-one-of-the-10-of-programmers-who-can-write-a-binary-search/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 21:23:18 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://conigliaro.org/?p=871</guid>
		<description><![CDATA[I think I might be! After reading an article claiming that only 10% of programmers can write a binary search I decided to give it a shot. After about 20 minutes, I came up with this: def bsearch&#40;array, search, start_ix=0, end_ix=array.length&#41; mid_ix = start_ix + &#40;&#40;end_ix-start_ix&#41;/2&#41;.ceil if array&#91;mid_ix&#93; == search then puts &#34;%d found at [...]]]></description>
			<content:encoded><![CDATA[<p>I think I might be! After reading an article claiming that <a href="http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/">only 10% of programmers can write a binary search</a> I decided to give it a shot. After about 20 minutes, I came up with this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> bsearch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span>, search, start_ix=<span style="color:#006666;">0</span>, end_ix=<span style="color:#CC0066; font-weight:bold;">array</span>.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    mid_ix = start_ix <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>end_ix<span style="color:#006600; font-weight:bold;">-</span>start_ix<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">ceil</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#91;</span>mid_ix<span style="color:#006600; font-weight:bold;">&#93;</span> == search <span style="color:#9966CC; font-weight:bold;">then</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;%d found at position %d&quot;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#91;</span> search, mid_ix<span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> start_ix == mid_ix <span style="color:#9966CC; font-weight:bold;">then</span>
        <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;%d not found&quot;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#91;</span> search <span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> <span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#91;</span>mid_ix<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> search
        bsearch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span>, search, mid_ix, end_ix<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">elsif</span> <span style="color:#CC0066; font-weight:bold;">array</span><span style="color:#006600; font-weight:bold;">&#91;</span>mid_ix<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&gt;</span> search <span style="color:#9966CC; font-weight:bold;">then</span>
        bsearch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">array</span>, search, start_ix, mid_ix<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
bsearch<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">10</span>, <span style="color:#006666;">20</span>, <span style="color:#006666;">30</span>, <span style="color:#006666;">40</span>, <span style="color:#006666;">50</span>, <span style="color:#006666;">60</span>, <span style="color:#006666;">70</span>, <span style="color:#006666;">80</span>, <span style="color:#006666;">90</span><span style="color:#006600; font-weight:bold;">&#93;</span>, ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>It&#8217;s probably not by best work, and I&#8217;m pretty doubtful that I could have done it in the same amount of time under the stress of a job interview. But it works, and that&#8217;s good enough for me, considering that I haven&#8217;t been a full time programmer in quite some time and haven&#8217;t written anything like this since college. ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://conigliaro.org/2010/04/19/am-i-one-of-the-10-of-programmers-who-can-write-a-binary-search/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
