<?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>Chris Page - Software Engineer &#187; Ubuntu Linux</title>
	<atom:link href="http://www.chriswpage.com/category/programming/ubuntu-linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chriswpage.com</link>
	<description>... and student of Life, Philosophy, and Learning</description>
	<lastBuildDate>Sat, 17 Jul 2010 02:46:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Apache Low Memory Settings + PHP + APC</title>
		<link>http://www.chriswpage.com/2010/04/apache-low-memory-settings-php-apc/</link>
		<comments>http://www.chriswpage.com/2010/04/apache-low-memory-settings-php-apc/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 19:27:07 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=413</guid>
		<description><![CDATA[In addition to moving my servers to save costs, I ran into a two part issue that I lumped into:  &#8220;I need to tune memory usage a bit&#8221;.  
Part 1:  Apache
Since I moved my Apache servers to lower memory instances, I was running into swap space usage that I could easily avoid, [...]]]></description>
			<content:encoded><![CDATA[<p>In addition to moving my servers to save costs, I ran into a two part issue that I lumped into:  &#8220;I need to tune memory usage a bit&#8221;.  </p>
<h3>Part 1:  Apache</h3>
<p>Since I moved my Apache servers to lower memory instances, I was running into swap space usage that I could easily avoid, ie:</p>
<pre>
free -m
                      total       used       free     shared    buffers     cached
Mem:               268        245         22          0         71         53
-/+ buffers/cache:        120        147
Swap:               511         29        482
</pre>
<p>Some of the reasoning behind this was that, by default, Apache expects a bit more memory to be available than what I provided to it in the move.  The fix was to introduce a few settings to lower child processes and limit concurrent connections to something more reasonable to the type of traffic my site really gets &#8211; which is near nothing most days.</p>
<p>The settings I dropped into apache were:</p>
<p><strong>httpd.conf</strong>:</p>
<pre>
    #Low Memory Settings
    StartServers 1
    MinSpareServers 4
    MaxSpareServers 2
    ServerLimit 6
    MaxClients 6
    MaxRequestsPerChild 3000
</pre>
<p>I made the adjustments, cleared out the swap space with:</p>
<pre>
swapoff -a
swapon -a
</pre>
<p>Then restarted apache:</p>
<pre>
/etc/init.d/apache2 stop
/etc/init.d/apache2 start
</pre>
<p>And all was well in the world.</p>
<pre>
free -m
                       total       used       free     shared    buffers     cached
Mem:                268        207         60          0         31         79
-/+ buffers/cache:           97        170
Swap:                 511          0        511
</pre>
<h3>Part 2-1:  PHP</h3>
<p>A bit simpler, my blog site was running into max memory allocation limits.  I had left the default php.ini in place in the upgrade, so I needed to do a once over of configs and change memory_limit from 16M to something more reasonable for my site.</p>
<p><strong>php.ini</strong></p>
<pre>
memory_limit = 64M      ; Maximum amount of memory a script may consume (16MB)
</pre>
<h4>Part 2-2:  APC</h4>
<p>Having Apache settings set for lower memory usage also allowed me more room to increase my APC cache limit a bit higher to keep more pages faster.  From 30 MB to 50 MB.</p>
<p><strong>apc.ini</strong></p>
<pre>
extension=apc.so
apc.enabled=1
apc.shm_size=50
</pre>
<p>Other obvious solutions in consideration, switch to Rackspace to invert my memory/cpu requirement/cost ratios.  Any other tips are welcome <img src='http://www.chriswpage.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2010/04/apache-low-memory-settings-php-apc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mysql:  Force Localhost to Use TCP, Not a Unix Socket File</title>
		<link>http://www.chriswpage.com/2010/04/mysql-force-localhost-to-use-tcp-instead-of-unix-socket-file/</link>
		<comments>http://www.chriswpage.com/2010/04/mysql-force-localhost-to-use-tcp-instead-of-unix-socket-file/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 18:28:32 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=407</guid>
		<description><![CDATA[So, recently I decided I was paying too much for my server because I was not maximizing performance across all the various daemons.  So I decided to split my larger server into a handful of smaller servers to be able to fine tune each one to dedicated purposes.  All went well, but I [...]]]></description>
			<content:encoded><![CDATA[<p>So, recently I decided I was paying too much for my server because I was not maximizing performance across all the various daemons.  So I decided to split my larger server into a handful of smaller servers to be able to fine tune each one to dedicated purposes.  All went well, but I had some trouble for a few evenings figuring out how I could port forward localhost:3306 to the, now remote, database server.  This should have been dirt simple with an iptables rule &#8211; but after digging in, I discovered MySQL treats localhost &#8220;special&#8221; by sending connections through the unix socket file, which is absolutely faster, but only works if the database daemon is on the same host as the connecting application.</p>
<p>After doing some research, I found it is possible to use a tool like <a href="http://manpages.ubuntu.com/manpages/jaunty/man1/socat.1.html">socat</a> and <a href="http://manpages.ubuntu.com/manpages/gutsy/man1/autossh.1.html">autossh</a> to wrap an ssh tunnel to forward connections through the socket file to a remote IP over TCP.  This however, was more complex and one off than I cared to explore for my simple problem.  I finally resorted to using DNS and to stop using localhost as the host name.  However, a few tid bits for the weary traveler:</p>
<ul>
<li>The mysql client library is responsible for selecting the protocol.</li>
<li>PHP&#8217;s internal mysql libraries, unfortunately, as far as I could discover ( please correct me if I am wrong here ), do not allow you to select the protocol.</li>
<li>So if you&#8217;re using &#8220;localhost&#8221; as your host name in a PHP mysql_connect, you&#8217;re forced to go through the socket file, however, you can use 127.0.0.1 instead of localhost to force TCP.</li>
<li>The linux mysql-client package command line tool offers a <strong>&#8211;protocol=tcp</strong> flag if you want to force TCP.  You can also set this as a default inside <strong>/etc/mysql/my.cnf</strong> under the [client] heading</li>
</ul>
<p>my.cnf:</p>
<pre>
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
protocol        = TCP
</pre>
<p>Again, this appears to work fine if you&#8217;re not using PHP as your client.  </p>
<p>I hope this lesson learned ( use DNS ) comes as a helping hand to others out there.  If anybody has some other suggestions, please do leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2010/04/mysql-force-localhost-to-use-tcp-instead-of-unix-socket-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Performance Testing with Apache Benchmark</title>
		<link>http://www.chriswpage.com/2010/01/simple-performance-testing-with-apache-benchmark/</link>
		<comments>http://www.chriswpage.com/2010/01/simple-performance-testing-with-apache-benchmark/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 04:34:45 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=386</guid>
		<description><![CDATA[




I&#8217;ve been knee deep in performance and scalability for some time now, and have used and learned of many useful tools and techniques to help out.  One of my favorite command line tools for seeing how well a single Apache server is churning out pages in development comes stock on Ubuntu, and Mac OS [...]]]></description>
			<content:encoded><![CDATA[<div style='float:left; width: 340px; height: 280px; padding: 0px; margin: 0px;'><script type="text/javascript"><!--
google_ad_client = "pub-2610131420861366";
/* 336x280, created 1/17/10 */
google_ad_slot = "7274979671";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><span style='padding: 5px;'><br />
I&#8217;ve been knee deep in performance and scalability for some time now, and have used and learned of many useful tools and techniques to help out.  One of my favorite command line tools for seeing how well a single Apache server is churning out pages in development comes stock on Ubuntu, and Mac OS X:  <a href="http://httpd.apache.org/docs/2.0/programs/ab.html" target="_blank">Apache Benchmark</a>.</p>
<p>A simple performance test against the homepage of one of my client site&#8217;s using AB at the command line:<br />
</span></p>
<pre style='clear: both; margin-top: 80px;'>
ab -t5 -n100 http://www.teamgzfs.com/
</pre>
<p>The results:</p>
<pre>
This is ApacheBench, Version 2.3 &lt;$Revision: 655654 $&gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/</code>

Benchmarking www.teamgzfs.com (be patient)
Finished 664 requests

Server Software:        Apache/2.2.8
Server Hostname:        www.teamgzfs.com
Server Port:            80

Document Path:          /
Document Length:        306 bytes

Concurrency Level:      100
Time taken for tests:   5.054 seconds
Complete requests:      664
Failed requests:        0
Write errors:           0
Total transferred:      465003 bytes
HTML transferred:       205326 bytes
Requests per second:    131.38 [#/sec] (mean)
Time per request:       761.143 [ms] (mean)
Time per request:       7.611 [ms] (mean, across all concurrent requests)
Transfer rate:          89.85 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:       38   78  48.7     64     994
Processing:   114  540 226.2    493    1690
Waiting:      114  531 205.6    493    1485
Total:        191  618 236.0    558    1808

Percentage of the requests served within a certain time (ms)
50%    558
66%    587
75%    598
80%    617
90%    845
95%   1163
98%   1402
99%   1746
100%   1808 (longest request)
</pre>
<p>There is quite a bit of useful information here that can help you tune your code and server.  It&#8217;s important to note however, that when working on a larger site, that expects quite a bit more traffic, you might want to investigate some more thorough solutions outside of just a single machine and ab.  It is, however, a nice starting point into useful information.</p>
<div style='margin: auto auto; width:468px; padding-bottom: 10px;'><div style='margin: auto auto; width:468px; padding-bottom: 10px;'>
<script type="text/javascript"><!--
google_ad_client = "pub-2610131420861366";
/* 468x60, created 1/17/10 */
google_ad_slot = "0179337850";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div>
<p>One rather funny pitfall you can run into however, is if the host you are sending requests to is smartly secured &#8211; these types of tests become a bit useless, as they may have security settings to limit or delay requests &#8211; providing you with timeouts and/or inaccurate information.  Best to run these types of things in a semi-developmental mode with those types of security settings turned down, and rely on bigger guns or fleets of boxes and scripts to hit a production secure site.</p>
<p>In addition to hitting just a landing page, you can use AB to send COOKIE or POST data too!  This is very useful if you want to see how pages perform but need credentials to get in first.  This is a little trickier to do using the -c, -T, -p, and -v flags.  I noticed there are under-useful resources online to figuring it out with AB, so it would seem worthwhile to write it &#8211; as it took me some trickery to figuring it out as well:</p>
<p><strong>Sending POST data to a login form:</strong></p>
<p>First we create a file that contains our URL encoded post data.  Note, AB expects the values to be URL encoded, but not the equal (=) or ampersands (&amp;).</p>
<p><em>post_data.txt</em></p>
<pre>
username=foo%40bar.com&amp;password=foobar
</pre>
<p><strong>Capturing a cookie:</strong></p>
<p>Here, we use the verbosity (-v) flag so we can see the response headers that come back &#8212; many sites will send back a cookie once authenticated, we&#8217;ll want to capture that cookie here.  Though, some sites will not require it, I demonstrate it for the sake of example:</p>
<pre>
ab -v4 -n1 -T 'application/x-www-form-urlencoded' -p post_data.txt http://www.foobar.com/login
</pre>
<p>The returned response header will fly by quick, you&#8217;re looking for something like the following:</p>
<pre>
Set-cookie somesession=somerandomsessiondata...;
</pre>
<p>The session data may come back encrypted, unencrypted, a serialization, or just a number.  That varies by site.  The point here is you have a key/value pair for the cookie.  All you need is the part up to the semi-colon ( not including the semi-colon ).  Copy that &#8220;key=val&#8221; string, and use it when hitting other pages on the site you are testing, ie:</p>
<p><strong>Using a cookie to test a page that requires a cookie:</strong></p>
<pre>
ab -t10 -n100 -c 'somessession=somerandomsessiondata' http://www.foobar.com/login_required_page
</pre>
<p>This can become a lot of fun once you get the hang of it.  Now you have the know how, go enjoy creating an arsenal of these scripts and start performance tuning your sites &#8211; or script hacking your favorite social network ( or obnoxious Blizzard clan website hahaha&#8230; drum roll for D3 &#8211; 2010?  Please???! ).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2010/01/simple-performance-testing-with-apache-benchmark/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Upgrading from PHP 5.2 to 5.3 in Ubuntu &#8211; Part 1</title>
		<link>http://www.chriswpage.com/2009/07/upgrading-from-php-5-2-to-5-3-in-ubuntu-part-1/</link>
		<comments>http://www.chriswpage.com/2009/07/upgrading-from-php-5-2-to-5-3-in-ubuntu-part-1/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 16:11:40 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=290</guid>
		<description><![CDATA[( I&#8217;m publishing this partially done so that it acts as a reminder for me to FINISH it&#8230; bare with me! )
Overview of Important Changes
variable class naming
Previously in PHP, only method and function names could be variables.  Ie:
$func = "print";
$func("Hello World");
class Foo {
  public static function Bar()
  {
     echo [...]]]></description>
			<content:encoded><![CDATA[<p>( I&#8217;m publishing this partially done so that it acts as a reminder for me to FINISH it&#8230; bare with me! )</p>
<h2>Overview of Important Changes</h2>
<h4>variable class naming</h4>
<p>Previously in PHP, only method and function names could be variables.  Ie:</p>
<pre>$func = "print";
<span style="color:green">$func("Hello World");</span></pre>
<pre>class Foo {
  public static function Bar()
  {
     echo "Hello World";
  }
}

$method = "Bar";
<span style="color:green">Foo::$method();</span></pre>
<p>Now, in PHP 5.3+, variable class naming is also supported &#8211; making possible this syntax:</p>
<pre>class Foo {
  public static function Bar()
  {
     echo "Hello World";
  }
}

$class = "Foo";
$method = "Bar";
<span style="color:green">$class::$method</span></pre>
<p>This new class variable naming should provide a much desired level of ambiguity for PHP developers, I know for my MVC framework, it could really change the <a title="Typhoon PHP Run" href="http://dev.shockwavelabs.com/repositories/entry/swltyphoon/trunk/init.php#L165" target="_blank">Typhoon PHP Typhoon-&gt;run() method</a> in a positive way.</p>
<h4>late static binding</h4>
<p>This is a more advance PHP OOP topic &#8211; that almost came off as a bug in previous versions of PHP.  I&#8217;ve personally ran into it myself on occasion, and am happy to see a solution available in PHP 5.3.  In previous versions of PHP, static calls resolved to the inherited class.  In cases where one needed a static call to resolve in it&#8217;s own scope, unexpected results were common.  Ie:</p>
<pre>class Foo {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        self::who();
    }
}

class Bar extends Foo {
    public static function who() {
         echo __CLASS__;
    }
}

Bar::test();</pre>
<p>Output:</p>
<pre>Foo</pre>
<p>The solution, &#8220;Late Static Bindings&#8221;, solves this using the <span style="color:green">static</span> keyword:</p>
<pre>class Foo {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        <span style="color:green">static::who();</span>
    }
}

class Bar extends Foo {
    public static function who() {
         echo __CLASS__;
    }
}

Bar::test();</pre>
<p>The <span style="color:green">static</span> keyword resolves to the calling class and produces the expected output:</p>
<pre>Bar</pre>
<h4>Additions to Standard PHP Library (SPL)</h4>
<h4>Circular Garbage Collection</h4>
<h4>Lambda Functions (Anonymous Functions)</h4>
<h4>Closures</h4>
<h4>Overriding Internal Functions</h4>
<h4>New Reserved Words</h4>
<h4>Namespaces</h4>
<h4>Jump Labels</h4>
<h4>Changes to Functions and Methods</h4>
<h4>Extensions</h4>
<h3>Phar</h3>
<h4>php.ini Changes</h4>
<h4>Deprecated Methods</h4>
<h2>Install php 5.3 on Ubuntu</h2>
<pre>mkdir download &amp;&amp; cd download
wget http://snaps.php.net/php5.3-200906131830.tar.gz</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2009/07/upgrading-from-php-5-2-to-5-3-in-ubuntu-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ubuntu + Compiz</title>
		<link>http://www.chriswpage.com/2009/06/ubuntu-compiz/</link>
		<comments>http://www.chriswpage.com/2009/06/ubuntu-compiz/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 21:41:17 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=267</guid>
		<description><![CDATA[This is actually from awhile ago ( almost a year ), but I thought I&#8217;d share.  It&#8217;s my desktop pc, running Ubuntu 8.04 and Compiz Fusion engine.

To be honest, it was a fun exploration for the novelty, but these days, the most I really use from the effects engine is the magnifier to help [...]]]></description>
			<content:encoded><![CDATA[<p>This is actually from awhile ago ( almost a year ), but I thought I&#8217;d share.  It&#8217;s my desktop pc, running Ubuntu 8.04 and Compiz Fusion engine.</p>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="405" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/SHQqka7Wm40&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="500" height="405" src="http://www.youtube.com/v/SHQqka7Wm40&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>To be honest, it was a fun exploration for the novelty, but these days, the most I really use from the effects engine is the magnifier to help people standing over my shoulder focus on whatever I&#8217;m demonstrating.</p>
<p>Pretty cool none the less!  Read up at <a title="Compiz Desktop Effects" href="http://www.compiz-fusion.org" target="_blank">Compiz Fusion</a> and <a title="Ubuntu Desktop" href="http://www.ubuntu.com" target="_blank">Ubuntu </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2009/06/ubuntu-compiz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup a webcam security system with Ubuntu Linux and Motion</title>
		<link>http://www.chriswpage.com/2009/05/setup-an-advanced-webcam-security-system-with-ubuntu-8-04-and-motion/</link>
		<comments>http://www.chriswpage.com/2009/05/setup-an-advanced-webcam-security-system-with-ubuntu-8-04-and-motion/#comments</comments>
		<pubDate>Sun, 17 May 2009 22:51:20 +0000</pubDate>
		<dc:creator>cpage</dc:creator>
				<category><![CDATA[Cool Tech]]></category>
		<category><![CDATA[Ubuntu Linux]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[motion detection]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[webcam]]></category>

		<guid isPermaLink="false">http://www.chriswpage.com/?p=54</guid>
		<description><![CDATA[So, now that I&#8217;m in Morgantown &#8211; my home is too small to comfortably work on side gigs and personal projects &#8211; especially now that my family is getting bigger with the baby!  I&#8217;ve been using the office space I leased out more and more.  While exploring video conferencing with Matt last week, I had [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_57" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-57" title="camera-1-03-20090510165704-02-motion" src="http://www.chriswpage.com/wp-content/uploads/2009/05/camera-1-03-20090510165704-02-motion-300x225.jpg" alt="Snap from Office Security Cam" width="300" height="225" /><p class="wp-caption-text">Snap from Office Security Cam</p></div>
<p>So, now that I&#8217;m in Morgantown &#8211; my home is too small to comfortably work on side gigs and personal projects &#8211; especially now that my family is getting bigger with the baby!  I&#8217;ve been using the office space I leased out more and more.  While exploring video conferencing with Matt last week, I had the thought &#8220;wouldn&#8217;t it be cool to have a security camera in the office?&#8221;.  So I did just that, and it&#8217;s actually quite easy for Ubuntu linux users.</p>
<h5>What you need:</h5>
<ul>
<li>Ubuntu Linux ( I was using 8.04.1 at the time of installation )</li>
<li>one or more USB web cameras</li>
</ul>
<h5>What you can do:</h5>
<ul>
<li>Motion detection &#8211; record video/and or frames if there is motion.</li>
<li>Snapshot intervals &#8211; take time interval snapshots regardless of motion detection.</li>
<li>Live video IP stream in mjpeg format.</li>
<li>Specify recorded video to be saved in your choice mpeg, avi, flv, swf format.</li>
<li>When motion exists, have frames and videos draw a box around the specific motion for more obvious recognition of subtle movements ( this actually shows the shadow of the janitor near the door around 6 a.m. every morning &#8211; I wouldn&#8217;t have noticed otherwise! )</li>
<li>Easily send all data to a backup server in a variety of ways &#8211; I keep it simple by saving data to my <a title="Dropbox" href="http://www.getdropbox.com" target="_blank">Dropbox</a> directory, a wonderful cross-platform data syncronization and sharing utility.</li>
</ul>
<h5>Steps:</h5>
<p><strong>1.  Plugin your webcam.</strong><br />
For me, the <a title="Logitech QuickCam Pro 9000" href="http://www.logitech.com/index.cfm/webcam_communications/webcams/devices/3056&amp;cl=US,EN" target="_blank">Logitech QuickCam® Pro 9000</a> worked right out of the box, and was only 105$.</p>
<p><strong>2.  Install <a title="Motion - Software Motion Detector" href="http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome" target="_blank">Motion</a> &#8211; software motion detector, and turn it on.</strong></p>
<pre>sudo apt-get install motion
sudo motion</pre>
<p><strong>3.  Configure Motion</strong></p>
<p>Everything really works out of the box with this &#8211; but isn&#8217;t quite organized to my liking, and probably not yours either.  Global configuration is located inside /etc/motion.conf ( You&#8217;ll notice there are multiple threadN.conf files in this directory &#8211; which can be used for custom configured individual cameras if you are setting up more than one ).</p>
<p><strong>Note:</strong> Be sure to restart the Motion server everytime you make a configuration change.</p>
<pre>sudo /etc/init.d/motion restart</pre>
<p>Take a look at the files, they are well documented.  Below are a few helpful configurations to get your data organized quicker:</p>
<pre>#/etc/motion/motion.conf

# Locate and draw a box around the moving object.
locate on

# Draws the timestamp using same options as C function strftime(3)
text_right %Y-%m-%dn%T-%q

# Text is placed in lower left corner
text_left SECURITY CAMERA %t - Office</pre>
<p>Organize the filesytem to save data by date, instead of all in one directory.</p>
<pre># File path for snapshots (jpeg or ppm) relative to target_dir
snapshot_filename %Y%m%d/camera-%t/snapshots/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-snapshot

# File path for motion triggered images (jpeg or ppm) relative to target_dir
jpeg_filename %Y%m%d/camera-%t/motions/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-%q-motion

# File path for motion triggered ffmpeg films (mpeg) relative to target_dir
movie_filename %Y%m%d/camera-%t/movies/hour-%H/camera-%t-%v-%Y%m%d%H%M%S-movie

# File path for timelapse mpegs relative to target_dir
timelapse_filename %Y%m%d/camera-%t/timelapses/hour-%H/camera-%t-%Y%m%d-timelapse</pre>
<p><strong>4.  (Optional)  Setup a backup solution</strong></p>
<p><strong>a.</strong> Easy solution, get and install Dropbox &#8212; instructions on the Dropbox site.  Then update your motion.conf to save to your Dropbox directory:</p>
<pre>#/etc/motion/motion.conf
...
target_dir /path/to/dropbox/security_camera
...</pre>
<p><strong>b.</strong> A more granular solution is to take advantage of hooks configurable in motion.conf.  Using these, you can create bash scripts to do anything your heart desires ( like trigger a silent alarm on motion detection outside business hours ).  Available hooks:  on_event_start, on_event_end, on_picture_save, on_motion_detected, on_movie_start, on_movie_end.</p>
<p>If you have <a title="wput" href="http://wput.sourceforge.net/wput.1.html" target="_blank">wput</a> installed, you can easily upload files to a remote backup server with these hooks:</p>
<pre>#motion.conf
...
on_picture_save wput ftp://user@pass@server %f
...</pre>
<p>However, this solution is somewhat less secure, as it uses FTP.  In a future post I will detail how to secure this up using encrypted transfer and phrase free keys.  ( Stay tuned! )</p>
<p><strong>5.  Live feed</strong></p>
<p>This comes working out of the box with Motion.  Check out your live stream in your web browser by navigating to:  http://localhost:8081</p>
<p>That&#8217;s it!  Webcam security made easy <img src='http://www.chriswpage.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="ngg-related-gallery"><a href="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/camera-1-104-20090514175450-01-motion.jpg" title="" class="thickbox" rel="Related images for Setup a webcam security system with Ubuntu Linux and Motion" ><img title="camera-1-104-20090514175450-01-motion.jpg" alt="camera-1-104-20090514175450-01-motion.jpg" src="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/thumbs/thumbs_camera-1-104-20090514175450-01-motion.jpg" /></a>
<a href="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/camera-1-104-20090514175544-02-motion.jpg" title="" class="thickbox" rel="Related images for Setup a webcam security system with Ubuntu Linux and Motion" ><img title="camera-1-104-20090514175544-02-motion.jpg" alt="camera-1-104-20090514175544-02-motion.jpg" src="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/thumbs/thumbs_camera-1-104-20090514175544-02-motion.jpg" /></a>
<a href="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/camera-1-104-20090514175446-03-motion.jpg" title="" class="thickbox" rel="Related images for Setup a webcam security system with Ubuntu Linux and Motion" ><img title="camera-1-104-20090514175446-03-motion.jpg" alt="camera-1-104-20090514175446-03-motion.jpg" src="http://www.chriswpage.com/wp-content/gallery/motion-detection-security-cam/thumbs/thumbs_camera-1-104-20090514175446-03-motion.jpg" /></a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.chriswpage.com/2009/05/setup-an-advanced-webcam-security-system-with-ubuntu-8-04-and-motion/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
