<?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>Ruby, Rails, OSX and Linux fun &#187; admin</title>
	<atom:link href="http://www.frederico-araujo.com/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederico-araujo.com</link>
	<description>Ruby, Rails, OSX and linux sysadmin</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:13:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Install a Rails enviroment on Snow Leopard with Macports, Mysql and ModRails Passenger (updated)</title>
		<link>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/</link>
		<comments>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 08:36:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sphinx]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=175</guid>
		<description><![CDATA[I choose the simple and I believe clean way to use everything from macports and passenger.
The advantage is that it&#8217;s all isolated from the OS X system and using latest cutting edge version of softwares.
I assume you have textmate, because it&#8217;s easy to edit files that need sudo access. Textmate will just ask for your [...]]]></description>
			<content:encoded><![CDATA[<p>I choose the simple and I believe clean way to use everything from macports and passenger.</p>
<p>The advantage is that it&#8217;s all isolated from the OS X system and using latest cutting edge version of softwares.</p>
<p>I assume you have textmate, because it&#8217;s easy to edit files that need sudo access. Textmate will just ask for your password.</p>
<p>Try and download the 30 days trial for easy of this tutorial. <a href="http://macromates.com/">http://macromates.com/</a></p>
<p>Trust me, you will love Textmate, it&#8217;s state of the art editor.</p>
<p>ps: I use &#8220;mate&#8221; instead of &#8220;open -a TextMate&#8221; but not everyone might have the mate symlink.</p>
<h3>Requirements:</h3>
<ul>
<li> Snow Leopard 10.6.4 or greater</li>
<li> Xcode 3.2.3, 2.4.1 or greater</li>
<li> Admin privileges on your mac.</li>
</ul>
<h3>Software preliminary:</h3>
<ul>
<li> Mysql 5.1.49 (macports)</li>
<li> Ruby 1.8.7 (macports)</li>
<li> Apache 2.2.9 (part of OS X)</li>
<li> Rubygems (download)</li>
<li> passenger (gem)</li>
<li> ImageMagick</li>
<li> rmagick</li>
</ul>
<h3>1. Preparing System</h3>
<p>If you are upgrading from Leopard to Snow Leopard, I recommend you delet your old installation.</p>
<pre class="command">sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports
</pre>
<h4>1.1 Prepare PATH environment:</h4>
<pre class="command">$ open -a TextMate ~/.bash_profile
</pre>
<p>Edit your ~/.bash_profile file and add these 2 line.<br />
Check if they are not there already.</p>
<pre>export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH
</pre>
<h4>1.2 Download and Install Xcode</h4>
<p>http://developer.apple.com/technologies/xcode.html</p>
<p>http://developer.apple.com/technologies/xcode.html</p>
<h4>1.3 Download Macports and install</h4>
<p>Download Page: http://www.macports.org/install.php</p>
<p>Download Direct Link: http://distfiles.macports.org/MacPorts/MacPorts-1.9.1-10.6-SnowLeopard.dmg</p>
<p>You might use this guide for installing Macports:</p>
<p>Full Install Guide: http://guide.macports.org/#installing</p>
<h4>1.3.1 Update macports</h4>
<pre class="command">sudo port -v selfupdate</pre>
<h3>2. Mysql</h3>
<h4>2.1 Intall Mysql</h4>
<pre class="command">sudo port -v install mysql5-server mysql5</pre>
<h4>2.2 Make mysql autoload on startup</h4>
<pre class="command">sudo port load mysql5-server
sudo -u mysql mysql_install_db5
</pre>
<h3>3. Memcached (Optional)</h3>
<pre class="command">sudo port -v install memcached libmemcached</pre>
<h4>3.1 Autoload memcached on startup</h4>
<pre class="command">sudo port load memcached</pre>
<h3>4. Ruby, Rubygems, Rails, other gems</h3>
<p>4.1 Install Ruby from macports</p>
<pre class="command">sudo port -v install ruby</pre>
<pre class="command">$ ruby -v
ruby 1.8.7 (2010-08-08 patchlevel 302) [x86_64-darwin10]
</pre>
<h4>4.2 download rubygems from http://rubygems.org/pages/download</h4>
<pre class="command">cd /tmp
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar xpf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb
</pre>
<h4>4.3 Install rails, rake, rspec etc.</h4>
<pre class="command">sudo gem install rake rails thin tzinfo capistrano ruby-debug rspec</pre>
<p>extra:</p>
<h4>4.4 install mysql gem</h4>
<pre class="command">sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
</pre>
<h3>5. ImageMagick, Rmagick and mini_magick (Optional)</h3>
<p>lets install ImageMagick with support for JPEG, TIFF, WMF, PDF, and PNG images, and for Postscript and TrueType fonts.</p>
<pre class="command">sudo port -v install tiff -macosx imagemagick +q8 +gs +wmf</pre>
<pre class="command">sudo gem install mini_magick rmagick</pre>
<p>Test rmagick</p>
<pre class="command">$ irb -rubygems -r RMagick
&gt;&gt; puts Magick::Long_version
This is RMagick 2.13.1 ($Date: 2009/12/20 02:33:33 $) Copyright (C) 2009 by Timothy P. Hunter
Built with ImageMagick 6.6.3-0 2010-08-19 Q8 http://www.imagemagick.org
Built for ruby 1.8.7
Web page: http://rmagick.rubyforge.org
Email: rmagick@rubyforge.org
=&gt; nil
</pre>
<h3>6. Passenger</h3>
<h4>6.1 Install Passenger gem</h4>
<pre class="command">sudo gem install passenger</pre>
<h4>6.2 Check Passenger path</h4>
<pre class="command">passenger-config --root</pre>
<pre> -&gt; /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15</pre>
<h4>6.3 Build passenger for apache</h4>
<p>follow instructions on screen</p>
<pre class="command">sudo passenger-install-apache2-module</pre>
<h4>6.4 Enable Passenger on apache:</h4>
<pre class="command">open -a TextMate /etc/apache2/extra/httpd-passenger.conf</pre>
<p>Put this on that file, change wherever necessary for your directories.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">LoadModule</span> passenger_module /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.15
PassengerRuby /opt/local/bin/ruby
PassengerMaxPoolSize <span style="color: #ff0000;">6</span>  <span style="color: #adadad; font-style: italic;"># maximum global rails servers</span>
PassengerMaxInstancesPerApp <span style="color: #ff0000;">2</span>  <span style="color: #adadad; font-style: italic;"># maximum rails servers per application</span>
RailsFrameworkSpawnerIdleTime <span style="color: #ff0000;">1800</span>
RailsAppSpawnerIdleTime <span style="color: #ff0000;">600</span>
PassengerPoolIdleTime <span style="color: #ff0000;">600</span>
PassengerMaxRequests <span style="color: #ff0000;">1000</span>  <span style="color: #adadad; font-style: italic;"># after 1000 requests will restart server, to skip memory leak :)</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># Enabling NameBased Virtualhost</span>
<span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">80</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># my rails app virtual host 1</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> my-rails-app.local
    <span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/public&quot;</span> <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
    RailsEnv <span style="color: #7f007f;">&quot;development&quot;</span>
   &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /Users/fred/rails/my-rails-app/public&gt;
        <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
        <span style="color: #adadad; font-style: italic;"># MultiViews must be turned off</span>
        <span style="color: #00007f;">Options</span> -MultiViews
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #00007f;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
    <span style="color: #adadad; font-style: italic;"># logs are optional, change this to match your folder</span>
    <span style="color: #00007f;">CustomLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/log/access_log&quot;</span> combined
    <span style="color: #00007f;">ErrorLog</span>   <span style="color: #7f007f;">&quot;/Users/fred/rails/my-rails-app/log/error_log&quot;</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&nbsp;
<span style="color: #adadad; font-style: italic;"># my rails app virtual host 2</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> myapp-xyz.local
    <span style="color: #00007f;">DocumentRoot</span> <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/public&quot;</span>  <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
    RailsEnv <span style="color: #7f007f;">&quot;development&quot;</span>
    &lt;<span style="color: #000000; font-weight:bold;">Directory</span> /Users/fred/rails/my-rails-app/public&gt;
        <span style="color: #adadad; font-style: italic;"># change this to match your folder</span>
        <span style="color: #adadad; font-style: italic;"># MultiViews must be turned off</span>
        <span style="color: #00007f;">Options</span> -MultiViews
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #00007f;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
    <span style="color: #00007f;">CustomLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/log/access_log&quot;</span> combined
    <span style="color: #00007f;">ErrorLog</span>  <span style="color: #7f007f;">&quot;/Users/fred/rails/myapp-xyz/log/error_log&quot;</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>6.5 Enable Virtual host on apache:</p>
<pre class="command">open -a TextMate /etc/apache2/httpd.conf</pre>
<p>Add this new line at the bottom:</p>
<pre># Include Passenger ModRails config file
Include /private/etc/apache2/extra/httpd-passenger.conf
</pre>
<h4>6.6 Add your .local domain to /etc/hosts/</h4>
<pre class="command">open -a TextMate /etc/hosts</pre>
<p>Add this line to that file and change to the name of your choosen application</p>
<p>You might add as many as you want, each line for each that ServerName on your VirtualHost blocks</p>
<pre>127.0.0.1 my-rails-app.local
127.0.0.1 myapp-xyz.local
</pre>
<p>I have more than 50 .local apps in there.</p>
<h4>5 Start Apache</h4>
<p>first let&#8217;s test apache configuration:</p>
<pre class="command">apachectl configtest</pre>
<p>if you get &#8220;Syntax OK&#8221; then you are ready to start it</p>
<pre class="command">sudo apachectl start</pre>
<p>If you want Apache to autostart when you boot your computer,<br />
then enable Web Sharing from preferences.</p>
<h4>7. Final</h4>
<p>go to your browser and open the url of your application http://my-rails-app.local</p>
<p>If it works, congratulations.</p>
<p>If didn&#8217;t work, let me know here in the comments.</p>
<h3>Extras</h3>
<h4>Nokogiri</h4>
<pre class="command">  sudo port -v install libxml2 libxslt
  sudo gem install nokogiri -- --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
</pre>
<h4>Sqlite</h4>
<pre class="command">sudo port install sqlite3
sudo gem install sqlite3-ruby
</pre>
<h3>9. Sphinx, thinking-sphinx, sphinxsearchlogic</h3>
<pre class="command">sudo port install sqlite3
sudo gem install thinking-sphinx sphinxsearchlogic
</pre>
<h4>Update:</h4>
<p>From the comments, some people might want to enable php and your Sites folder.</p>
<p>To be able to enable php and others you will have to enable another default vhost with localhost as servername.</p>
<p>Edit the file /etc/apache2/httpd.conf to enable vhosts</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Virtual hosts</span>
<span style="color: #00007f;">Include</span> /private/etc/apache2/extra/httpd-vhosts.conf</pre></div></div>

<p>then open /private/etc/apache2/extra/httpd-vhosts.conf file,<br />
delete or comment everything from there and add this block only:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #adadad; font-style: italic;"># Use name-based virtual hosting.</span>
<span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #00007f;">NameVirtualHost</span> *:<span style="color: #ff0000;">80</span>
&nbsp;
<span style="color: #adadad; font-style: italic;"># Change /Users/fred/ to your appropriate login name</span>
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> localhost
    <span style="color: #00007f;">DocumentRoot</span> /Users/fred/Sites/
    <span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
    <span style="color: #00007f;">DefaultType</span> text/html
    &lt;<span style="color: #000000; font-weight:bold;">Directory</span> <span style="color: #7f007f;">&quot;/Users/fred/Sites&quot;</span>&gt;
        <span style="color: #00007f;">DefaultType</span> text/html
        <span style="color: #00007f;">Options</span> +ExecCGI <span style="color: #0000ff;">FollowSymLinks</span> <span style="color: #0000ff;">Indexes</span>
        <span style="color: #00007f;">AllowOverride</span> <span style="color: #00007f;">All</span>
        <span style="color: #00007f;">Order</span> <span style="color: #00007f;">allow</span>,<span style="color: #00007f;">deny</span>
        <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
    &lt;/<span style="color: #000000; font-weight:bold;">Directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<h3>Links and Resources</h3>
<p><a href="http://rmagick.rubyforge.org/install-osx.html">http://rmagick.rubyforge.org/install-osx.html</a></p>
<p><a href="http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk">http://wiki.github.com/tenderlove/nokogiri/what-to-do-if-libxml2-is-being-a-jerk</a></p>
<p><a href="http://www.macports.org/install.php">http://www.macports.org/install.php</a></p>
<p><a href="http://guide.macports.org/#installing">http://guide.macports.org/#installing</a></p>
<p><a href="http://distfiles.macports.org/MacPorts/MacPorts-1.9.1-10.6-SnowLeopard.dmg">http://distfiles.macports.org/MacPorts/MacPorts-1.9.1-10.6-SnowLeopard.dmg</a></p>
<p><a href="http://rob.by/2009/installing-mysql-via-macports-on-snow-leopard-for-ruby-development">http://rob.by/2009/installing-mysql-via-macports-on-snow-leopard-for-ruby-development</a>/</p>
<p><a href="http://macromates.com/">http://macromates.com/</a></p>
<p><a href="http://github.com/joost/sphinxsearchlogic">http://github.com/joost/sphinxsearchlogic</a></p>
<p><a href="http://www.sphinxsearch.com/">http://www.sphinxsearch.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/08/19/installing-rails-enviroment-on-snow-leopard-with-macports-mysql-and-modrails-passenger/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Encrypted image that grows as needed, for linux backups</title>
		<link>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/</link>
		<comments>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 08:47:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=172</guid>
		<description><![CDATA[This command will create an encrypted image on mac OS X that will grow as you need it.
Since I could not find anywhere on the net, I dig on the hdiutil man page and wrapped the command. 
The image starts with about 600MB in size, which is not wasted actually. 
I use this image to [...]]]></description>
			<content:encoded><![CDATA[<p>This command will create an encrypted image on mac OS X that will grow as you need it.<br />
Since I could not find anywhere on the net, I dig on the hdiutil man page and wrapped the command. </p>
<p>The image starts with about 600MB in size, which is not wasted actually. </p>
<p>I use this image to backup my sensitive data such as servers config files, mysql databases and repositories.<br />
I set it to use AES 128bit encryption.<br />
Case-sensitive, because Linux fs are Case-sensitive by default. If you don&#8217;t set it Case-sensitive you cannot use for linux backups.</p>
<p>hdiutil create -encryption AES-128 -stdinpass -fs &#8220;Case-sensitive HFS+&#8221; -type SPARSE -nospotlight -volname Servers Servers</p>
<p>it will create a file named Servers.sparseimage </p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/07/24/encrypted-image-that-grows-as-needed-for-linux-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check guaranteed Ram, burstable Ram and Error Counts on your OpenVZ VPS</title>
		<link>http://www.frederico-araujo.com/2010/07/09/check-guaranteed-ram-burstable-ram-o-openvz/</link>
		<comments>http://www.frederico-araujo.com/2010/07/09/check-guaranteed-ram-burstable-ram-o-openvz/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 14:37:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=151</guid>
		<description><![CDATA[Now a days there are so many good and cheap OpenVZ VPS providers out there.
Just have a look at this blog and you will see what I mean. [http://www.lowendbox.com/tag/openvz/]
The way OpenVZ virtual machines offers RAM resource is quite different from XEN.
You get Dedicated Ram (guaranteed ram) and Burstable Ram. 
Burstable Ram is good when your [...]]]></description>
			<content:encoded><![CDATA[<p>Now a days there are so many good and cheap OpenVZ VPS providers out there.<br />
Just have a look at <a href="http://www.lowendbox.com/tag/openvz/">this blog</a> and you will see what I mean. [http://www.lowendbox.com/tag/openvz/]</p>
<p>The way OpenVZ virtual machines offers RAM resource is quite different from XEN.<br />
You get Dedicated Ram (guaranteed ram) and Burstable Ram. </p>
<p>Burstable Ram is good when your server has sporadic load spikes, such as blogs and news sites.<br />
Ideally you should not rely on burstable ram, it depends on the Host System. if the host system starts get low on free ram, you will lose that memory and the kernel will kill your processes to recover the ram. </p>
<p>Best is to keep below 90% of your Dedicated ram.</p>
<p>So, here I have an script that will monitor your memory limits. Also check for errors on your openVZ.<br />
it&#8217;s perfect for an hourly cron job. It will print output on warnings and errors only.<br />
Will suppress output if your openVZ container is behaving well. <img src='http://www.frederico-araujo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>for example, put on /etc/cron.hourly/</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># Program to check for failed count on OpenVZ systems</span>
<span style="color:#008000; font-style:italic;">#   Failed counts indicate over commit on memory. </span>
<span style="color:#008000; font-style:italic;">#   it should always be zero.</span>
&nbsp;
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@file</span> = <span style="color:#996600;">`cat /proc/user_beancounters`</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Delete the first 3 lines, which are irrelevant to us.</span>
<span style="color:#0066ff; font-weight:bold;">@file</span>.<span style="color:#9900CC;">delete_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@file</span>.<span style="color:#9900CC;">delete_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@file</span>.<span style="color:#9900CC;">delete_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@failcnt</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#0066ff; font-weight:bold;">@file</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
  tmp = t.<span style="color:#CC0066; font-weight:bold;">split</span>
  <span style="color:#9966CC; font-weight:bold;">unless</span> tmp.<span style="color:#9900CC;">last</span> == <span style="color:#996600;">&quot;0&quot;</span>
    <span style="color:#0066ff; font-weight:bold;">@failcnt</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> tmp
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Check that 'held' is less than 'barrier' </span>
<span style="color:#008000; font-style:italic;">#   held = current count</span>
<span style="color:#008000; font-style:italic;">#   barrier = soft limit</span>
<span style="color:#008000; font-style:italic;"># only checking for:</span>
<span style="color:#008000; font-style:italic;">#   privvmpages @file[1] </span>
<span style="color:#008000; font-style:italic;">#   oomguarpages @file[7] </span>
<span style="color:#008000; font-style:italic;"># </span>
<span style="color:#008000; font-style:italic;"># oomguarpages : </span>
<span style="color:#008000; font-style:italic;">#   The out-of-memory guarantee, in pages. </span>
<span style="color:#008000; font-style:italic;">#   Any VE process will not be killed even in case of heavy </span>
<span style="color:#008000; font-style:italic;">#   memory shortage if the current memory consumption </span>
<span style="color:#008000; font-style:italic;">#   (including both physical memory and swap) </span>
<span style="color:#008000; font-style:italic;">#   does not reach the oomguarpages barrier.</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># privvmpages: </span>
<span style="color:#008000; font-style:italic;">#  The size of private (or potentially private) memory allocated by an application. </span>
<span style="color:#008000; font-style:italic;">#  The memory that is always shared among different applications </span>
<span style="color:#008000; font-style:italic;">#  is not included in this resource parameter.</span>
<span style="color:#008000; font-style:italic;"># </span>
<span style="color:#008000; font-style:italic;"># Sources: </span>
<span style="color:#008000; font-style:italic;">#  - http://wiki.openvz.org/UBC_secondary_parameters</span>
<span style="color:#008000; font-style:italic;">#  - http://wiki.vpslink.com/Meaning_of_the_/proc/user_beancounters_Values</span>
&nbsp;
privvmpages = <span style="color:#0066ff; font-weight:bold;">@file</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span>
privvmpages_current = privvmpages<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span>
privvmpages_limit = privvmpages<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#9966CC; font-weight:bold;">if</span> privvmpages_current <span style="color:#006600; font-weight:bold;">&gt;</span> privvmpages_limit
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: #{privvmpages[0]} has passed the limit: #{privvmpages_current}/#{privvmpages_limit}&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: Server may crash or reboot&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># Also check it we are getting close to 70% of usage</span>
privvmpages_pc = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>privvmpages_current.<span style="color:#9900CC;">to_f</span><span style="color:#006600; font-weight:bold;">/</span>privvmpages_limit<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">100</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> privvmpages_pc <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">70</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: #{privvmpages[0]} is high: #{privvmpages_pc}% of limit&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
oomguarpages = <span style="color:#0066ff; font-weight:bold;">@file</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">7</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#CC0066; font-weight:bold;">split</span>
oomguarpages_current = oomguarpages<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span>
oomguarpages_limit = oomguarpages<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_i</span>
<span style="color:#9966CC; font-weight:bold;">if</span> oomguarpages_current <span style="color:#006600; font-weight:bold;">&gt;</span> oomguarpages_limit
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: #{oomguarpages[0]} has passed the limit: #{oomguarpages_current}/#{oomguarpages_limit}&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: Some Processes may be killed&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># Also check it we are getting close to 85% of usage</span>
oomguarpages_pc = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>oomguarpages_current.<span style="color:#9900CC;">to_f</span><span style="color:#006600; font-weight:bold;">/</span>oomguarpages_limit<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">100</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> oomguarpages_pc <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">85</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;WARNING: #{oomguarpages[0]} is high: #{oomguarpages_pc}% of limit&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@failcnt</span>.<span style="color:#9900CC;">empty</span>?
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;==================================&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Found Memory problems with OpenVZ:&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;==================================&quot;</span>
  <span style="color:#0066ff; font-weight:bold;">@failcnt</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{t.join(' - ')}&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;==================================&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/07/09/check-guaranteed-ram-burstable-ram-o-openvz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server monitoring with gentoo and iStat on the iPhone</title>
		<link>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/</link>
		<comments>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 07:00:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[istatd]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=137</guid>
		<description><![CDATA[You can monitor your servers nicely graphs using iStat for iphone.
these are instructions for Gentoo:

1
2
3
4
5
6
7
8
9
wget http://github.com/downloads/tiwilliam/istatd/istatd-0.5.7.tar.gz
tar xpf istatd-0.5.7.tar.gz
cd istatd-0.5.7
./configure
make
make install 
useradd istat
mkdir -p /var/&#123;run,cache&#125;/istat /home/istat
chown istat.istat /var/&#123;run,cache&#125;/istat /home/istat

Create and edit /etc/istat.conf to match your server specs.
This config is for my OpenVZ vps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#
# /etc/istat.conf: Configuration for iStat server
#
&#160;
# IP Address to listen
network_addr     [...]]]></description>
			<content:encoded><![CDATA[<p>You can monitor your servers nicely graphs using iStat for iphone.<br />
these are instructions for Gentoo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>tiwilliam<span style="color: #000000; font-weight: bold;">/</span>istatd<span style="color: #000000; font-weight: bold;">/</span>istatd-0.5.7.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xpf istatd-0.5.7.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> istatd-0.5.7
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> 
useradd istat
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>run,cache<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>istat <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>istat
<span style="color: #c20cb9; font-weight: bold;">chown</span> istat.istat <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>run,cache<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>istat <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>istat</pre></td></tr></table></div>

<p>Create and edit /etc/istat.conf to match your server specs.<br />
This config is for my OpenVZ vps.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># /etc/istat.conf: Configuration for iStat server</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># IP Address to listen</span>
network_addr           77.88.xx.xx
&nbsp;
<span style="color: #666666; font-style: italic;"># choose any port, Default is 5109</span>
network_port           <span style="color: #000000;">55666</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># this is password, 5 digits</span>
server_code            <span style="color: #000000;">12345</span>
&nbsp;
server_user            istat
server_socket          <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>istat<span style="color: #000000; font-weight: bold;">/</span>istat.sock
server_pid             <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>istat<span style="color: #000000; font-weight: bold;">/</span>istat.pid
cache_dir              <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>cache<span style="color: #000000; font-weight: bold;">/</span>istat
monitor_net              venet0
monitor_disk             <span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>simfs <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>

<p>Start istatd server:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> istat istatd <span style="color: #660033;">-d</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>istat.conf</pre></td></tr></table></div>

<p>you might add it to /etc/conf.d/local.start to auload on startup</p>
<p>Then download iStat for iphone http://bjango.com/apps/istat/  it&#8217;s only $0.99<br />
and add your server to the list. </p>
<p>Here are some screenshots, first is server and second image is my macbook discovered with bonjour. </p>

<a href='http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/img_0016/' title='IMG_0016'><img width="150" height="150" src="http://www.frederico-araujo.com/wp-content/uploads/2010/06/IMG_0016-150x150.png" class="attachment-thumbnail" alt="" title="IMG_0016" /></a>
<a href='http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/img_0019/' title='IMG_0019'><img width="150" height="150" src="http://www.frederico-araujo.com/wp-content/uploads/2010/06/IMG_0019-150x150.png" class="attachment-thumbnail" alt="" title="IMG_0019" /></a>

]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2010/06/25/server-monitoring-with-gentoo-and-istat-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Really checking the content-type/mime_type of a file in OSX and Linux</title>
		<link>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:55:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[content_type]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mime_type]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=95</guid>
		<description><![CDATA[I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.
Methods I have seen so far:
1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will [...]]]></description>
			<content:encoded><![CDATA[<p>I have came across many projects where checking file uploads and content-type (mime-type) is poorly implemented or heavy in resource.</p>
<p>Methods I have seen so far:</p>
<p>1. Checking content-type from file name: this inefficient, a user can just rename a file and you are fooled, or the file can have a different file format and you will not get the expected result.</p>
<p>2. Using Rmagick to check if the file is an image. This is so slow and uses so much Ram. You can try to initialize an rmagick object from an image file, then rescue when the file is not an image.</p>
<p>3. Using mini_magick to check if a file. This method is faster than rmagick. Implemen ted same way as rmagick.</p>
<p>A Better method for OSX and Linux,  is to use the command line tool &#8220;file&#8221; included in most UNIX operating systems.</p>
<p>It is very fast and very accurate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">file = <span style="color:#996600;">&quot;/path/to/file.ext&quot;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> RUBY_PLATFORM.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>darwin<span style="color:#006600; font-weight:bold;">|</span>linux<span style="color:#006600; font-weight:bold;">|</span>unix<span style="color:#006600; font-weight:bold;">|</span>solaris<span style="color:#006600; font-weight:bold;">|</span>bsd<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
 content_type = <span style="color:#996600;">`file --raw --brief &quot;#{file}&quot;`</span>.<span style="color:#CC0066; font-weight:bold;">chomp</span>
 <span style="color:#9966CC; font-weight:bold;">case</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>image<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">|</span>jpeg<span style="color:#006600; font-weight:bold;">|</span>gif<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;image&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>pdf<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;pdf&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">when</span> content_type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Microsoft Word|Microsoft Office Document&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   real_type = <span style="color:#996600;">&quot;doc&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span> <span style="color:#008000; font-style:italic;"># This can go on and on</span>
   real_type = <span style="color:#996600;">&quot;Unknown&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Some examples of content types:</p>
<p>.doc =  Microsoft Word document data</p>
<p>.doc = Microsoft Office Document</p>
<p>.pdf = PDF document, version 1.4</p>
<p>.pdf = PDF document, version 1.3</p>
<p>.psd = Adobe Photoshop Image</p>
<p>.png  = PNG image data, 3508 x 4961, 8-bit/color RGBA, non-interlaced</p>
<p>.gif = GIF image data, version 89a, 195 x 109</p>
<p>.jpg = JPEG image data, EXIF standard</p>
<p>etc&#8230;</p>
<p>I hope this can be useful to someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/really-finding-the-content-type-of-a-file-in-osx-and-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Easy installing Nginx + mod_rails passenger OSX</title>
		<link>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/</link>
		<comments>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 18:39:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=92</guid>
		<description><![CDATA[Requirements:
1. XCODE  you can download xcode from http://developer.apple.com/tools/xcode/index.html
2. OSX 10.4, 10.5 or 10.6
Procedures:
1. Install Passenger
$ sudo gem install passenger
now check where is passenger installed:

$ passenger-config --root

in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5
2. Install nginx
If you have nginx from macports, deactivate it in case of conflicts.
You can activate anytime later
$ sudo port deactivate nginx
$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz
$ wget [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Requirements</strong>:</p>
<p>1. XCODE  you can download xcode from <a href="http://developer.apple.com/tools/xcode/index.html">http://developer.apple.com/tools/xcode/index.html</a></p>
<p>2. OSX 10.4, 10.5 or 10.6</p>
<p><strong>Procedures</strong>:</p>
<p><strong>1. Install Passenger</strong></p>
<p>$ sudo gem install passenger</p>
<p>now check where is passenger installed:</p>
<pre>
$ passenger-config --root
</pre>
<p>in my case is: /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5</p>
<p><strong>2. Install nginx</strong></p>
<p>If you have nginx from macports, deactivate it in case of conflicts.</p>
<p>You can activate anytime later</p>
<p>$ sudo port deactivate nginx</p>
<p><del datetime="2009-06-16T13:04:06+00:00">$ wget http://sysoev.ru/nginx/nginx-0.7.59.tar.gz</p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.7.62.tar.gz</p>
<p>$ tar xpf nginx-0.7.62.tar.gz</p>
<p>$ cd nginx-0.7.62</p>
<p></del></p>
<p><del datetime="2009-09-23T22:31:19+00:00">
<p>I Recommend using nginx 0.6 series because I had a lot of  &#8220;502 Bad Gateway&#8221; with 0.7 series. </p>
<p>$ wget http://sysoev.ru/nginx/nginx-0.6.37.tar.gz</p>
<p>$ tar xpf nginx-0.6.37.tar.gz</p>
<p>$ cd nginx-0.6.37<br />
</del></p>
<pre>
$ sudo ./configure --add-module=/opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/nginx/ \
  --with-http_ssl_module --user=nobody --group=nobody --with-http_gzip_static_module \
  --with-poll_module --prefix=/opt/local --with-pcre
</pre>
<pre>
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1 library is not used
+ using system zlib library

nginx path prefix: "/opt/local"
nginx binary file: "/opt/local/sbin/nginx"
nginx configuration prefix: "/opt/local/conf"
nginx configuration file: "/opt/local/conf/nginx.conf"
nginx pid file: "/opt/local/logs/nginx.pid"
nginx error log file: "/opt/local/logs/error.log"
nginx http access log file: "/opt/local/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
</pre>
<p>$ sudo make</p>
<p>$ sudo make install</p>
<p>$ cd /opt/local/conf</p>
<p>$ sudo cp mime.types.default mime.types</p>
<p>$ sudo cp nginx.conf.default nginx.conf</p>
<p><strong>Edit nginx.conf</strong></p>
<p>$ mate nginx.conf</p>
<p>or</p>
<p>$ sudo vi nginx.conf</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;">&nbsp;
<span style="color: #00007f;">user</span> nobody;
worker_processes  <span style="color: #ff0000;">2</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log;</span>
<span style="color: #adadad; font-style: italic;">#error_log  logs/error.log  notice;</span>
error_log  logs/error.log  info;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Pid</span>
pid  logs/nginx.pid;
&nbsp;
events {
worker_connections <span style="color: #ff0000;">1024</span>;
}
&nbsp;
http {
<span style="color: #00007f;">include</span>       mime.types;
default_type  application/octet-stream;
&nbsp;
sendfile        <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;">#tcp_nopush     on;</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#keepalive_timeout  0;</span>
keepalive_timeout  <span style="color: #ff0000;">65</span>;
&nbsp;
gzip  <span style="color: #0000ff;">on</span>;
<span style="color: #adadad; font-style: italic;"># if a precompiled gzip of the file exists, use it and force http proxies</span>
<span style="color: #adadad; font-style: italic;"># to use separate cache's based on User-Agent</span>
gzip_static <span style="color: #0000ff;">on</span>;
gzip_min_length <span style="color: #ff0000;">2000</span>;
gzip_buffers    <span style="color: #ff0000;">16</span> 8k;
gzip_types      text/plain text/html text/css image/x-icon application/xml application/xml+rss text/javascript;
gzip_disable    <span style="color: #7f007f;">&quot;MSIE [1-6] <span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>;
gzip_vary         <span style="color: #0000ff;">on</span>;
gzip_comp_level   <span style="color: #ff0000;">2</span>;
&nbsp;
gzip_proxied any;
&nbsp;
server {
<span style="color: #00007f;">listen</span>       <span style="color: #ff0000;">80</span>;
server_name  localhost;
<span style="color: #00007f;">location</span> / {
root   /Users/fred/Sites ;
autoindex <span style="color: #0000ff;">on</span>;
index  index.html index.htm;
}
}
&nbsp;
passenger_root /opt/local/lib/ruby/gems/<span style="color: #ff0000;">1.8</span>/gems/passenger-2.2.2;
passenger_max_pool_size <span style="color: #ff0000;">8</span>;
passenger_max_instances_per_app <span style="color: #ff0000;">1</span>;
<span style="color: #adadad; font-style: italic;"># The maximum number of seconds that an application instance may be idle.</span>
<span style="color: #adadad; font-style: italic;"># That is, if an application instance hasn’t received any traffic after the given number of seconds,</span>
<span style="color: #adadad; font-style: italic;"># then it will be shutdown in order to conserve memory.</span>
passenger_pool_idle_time <span style="color: #ff0000;">3600</span>;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 1</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project1.local;
root /Users/fred/rails/project1/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project1/log/nginx.access.log;
error_log  /Users/fred/rails/project1/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 2</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project2.local;
root /Users/fred/rails/project2/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project2/log/nginx.access.log;
error_log  /Users/fred/rails/project2/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># Project 3</span>
server {
<span style="color: #00007f;">listen</span> <span style="color: #ff0000;">80</span>;
client_max_body_size 250M;
server_name project3.local;
root /Users/fred/rails/project3/public;
passenger_enabled <span style="color: #0000ff;">on</span>;
rails_env development;
access_log  /Users/fred/rails/project3/log/nginx.access.log;
error_log  /Users/fred/rails/project3/log/nginx.error.log info;
}
&nbsp;
<span style="color: #adadad; font-style: italic;"># And so on... as many projects as you want</span>
&nbsp;
}</pre></td></tr></table></div>

<p>Now edit your /etc/hosts and add the hosts for your local project</p>
<p>$ mate /etc/hosts</p>
<pre>

127.0.0.1   project1.local

127.0.0.1   project2.local

127.0.0.1   project3.local
</pre>
<p><strong>3. Start nginx</strong></p>
<p>sudo nginx</p>
<p><strong>4. go to your browser and open project1.local</strong></p>
<p><strong> <img src='http://www.frederico-araujo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></p>
<p><strong>5. Easy start/restart/stop</strong></p>
<p>add this to your ~/.bash_profile file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_reload<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</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;Reloading NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-HUP</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</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;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> nginx_restart<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">FILE</span>=<span style="color: #ff0000;">&quot;/opt/local/logs/nginx.pid&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$FILE</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;Stopping NGINX...&quot;</span>
<span style="color: #007800;">PID</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>nginx.pid<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-INT</span> <span style="color: #007800;">$PID</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting NGINX...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> nginx
<span style="color: #000000; font-weight: bold;">else</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nginx pid file not found&quot;</span>
<span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p><strong>Troubleshooting</strong></p>
<p>1. Nginx is not running</p>
<p>- check the logs</p>
<p>- check if it is really not running:</p>
<p>$ ps aux | grep nginx</p>
<p>2. you see the nginx error &#8220;502 Bad Gateway&#8221;</p>
<p>- may there is a problem with the /var/folders/ permissions on OSX:</p>
<pre>

2009/06/13 16:14:33 [crit] 1106#0: *1 connect() to unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: hassan.local, request: "GET / HTTP/1.1", upstream: "unix:/var/folders/xl/xlSRYvzFHH8Fcehc51ciyE+++TI/-Tmp-//passenger.1091/master/helper_server.sock:", host: "hassan.local"
</pre>
<p>to fix it I did this:</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;master&#8221; -exec chmod 755 {} \;</p>
<p>$ sudo find /var/folders/xl/ -name &#8220;-Tmp-&#8221; -exec chmod 755 {} \;</p>
<p>everytime I reboot my mac I had to do that&#8230; I still dont know how to fix it&#8230;</p>
<p>anybody knows?</p>
<p>That is it for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/06/14/easy-installing-nginx-mod_rails-passenger-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop http Pipeline from overloading your server, using connlimit iptables</title>
		<link>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/</link>
		<comments>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 08:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=79</guid>
		<description><![CDATA[Have you edited or tweaked your pipeline settings in Firefox?
You can do it by typing about:config in your firefox url tab.
Most blogs and tutorial will tell you to set high values to improve the speed, such as this one: www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/
Many people will go crazy and make values even higher such as:
network.http.pipelining.maxrequests 32
network.http.max-persistent-connections-per-proxy 128
network.http.max-persistent-connections-per-server 128
network.http.max-connections-per-server 256
These [...]]]></description>
			<content:encoded><![CDATA[<p>Have you edited or tweaked your pipeline settings in Firefox?</p>
<p>You can do it by typing about:config in your firefox url tab.</p>
<p>Most blogs and tutorial will tell you to set high values to improve the speed, such as this one: <a href="http://www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/">www.mydigitallife.info/2007/10/16/speed-up-your-firefox-by-adjusting-your-http-pipelining/</a></p>
<p>Many people will go crazy and make values even higher such as:</p>
<p>network.http.pipelining.maxrequests 32<br />
network.http.max-persistent-connections-per-proxy 128<br />
network.http.max-persistent-connections-per-server 128<br />
network.http.max-connections-per-server 256</p>
<p>These settings are very high and will create at least 32 connections to your server.</p>
<p>if you have many images and SSI includes, it could overload your apache webserver.<br />
If you use apache2.2 with worker_mpm it will create 1 thread for each connection, thus you will have 32 new threads forked within just a few seconds.</p>
<p>Of course if you have a quad-core server with lots of ram you should not bother to read this.<br />
But for most cheap vps and single core servers, it can really help.</p>
<p>so how you do it? simple, just use iptables conn_limit module</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-I</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--syn</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">80</span> <span style="color: #660033;">-m</span> connlimit <span style="color: #660033;">--connlimit-above</span>  <span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> REJECT</pre></div></div>

<p>you may need to adjust the order or to insert or append like</p>
<p># to apped to the end of the INPUT chain:<br />
iptables -A input &#8230;<br />
or<br />
# to insert at position 10 of the input chain:<br />
iptables -I input 10 &#8230;</p>
<p>I have tested this schema and work very well with firefox pipeline freaks.</p>
<p>the server will only then take up to 8 simultaneously connections per IP</p>
<p>to test the established connections you can try with netstat from the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-na</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> esta <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> 127.0.0.1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> -t. <span style="color: #660033;">-k2</span></pre></div></div>

<p>Any comments, suggestions are welcome &#8230;</p>
<p>Update:</p>
<p>This can be not so good to legit users behind a proxy or firewall, because the the IP will be unique to all users behind the proxy/firewall.</p>
<p>in this case, you would increase the limit value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/01/25/stop-http-pipeline-from-overloading-your-server-with-iptables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux script to collect system statistics and send to your email</title>
		<link>http://www.frederico-araujo.com/2009/01/08/linux-script-to-collect-system-statistics-and-send-to-your-email/</link>
		<comments>http://www.frederico-araujo.com/2009/01/08/linux-script-to-collect-system-statistics-and-send-to-your-email/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 08:11:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=67</guid>
		<description><![CDATA[This script I use to daily send me the system statistics on my gentoo server.
It will also reformat the output to replace tabs with 5 spaces so it will display nicely on your email client.
On mail.app the fonts Monaco and Inconsolata displays nicely, but the default font does not.
requirements:
- app-admin/sysstat
- net-mail/sendEmail
- app-admin/procinfo
- local postfix server [...]]]></description>
			<content:encoded><![CDATA[<p>This script I use to daily send me the system statistics on my gentoo server.<br />
It will also reformat the output to replace tabs with 5 spaces so it will display nicely on your email client.<br />
On mail.app the fonts Monaco and Inconsolata displays nicely, but the default font does not.</p>
<p>requirements:<br />
- app-admin/sysstat<br />
- net-mail/sendEmail<br />
- app-admin/procinfo<br />
- local postfix server able to deliver emails.<br />
- perl</p>
<pre>
emerge -va app-admin/sysstat net-mail/sendEmail app-admin/procinfo
</pre>
<p>I put the script under /etc/cron.daily</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">SERVER</span>=<span style="color: #ff0000;">&quot;mydomain.com&quot;</span>
<span style="color: #007800;">EMAIL_TO</span>=<span style="color: #ff0000;">&quot;your_email@gmail.com&quot;</span>
<span style="color: #007800;">EMAIL_FROM</span>=<span style="color: #ff0000;">&quot;amin@mydomain.com&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># logged in users and what are they running</span>
<span style="color: #007800;">WHO</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">w</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># processor stats</span>
<span style="color: #007800;">MPSTAT</span>=<span style="color: #000000; font-weight: bold;">`</span>mpstat<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># virtual memory stats</span>
<span style="color: #007800;">VMSTAT</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">vmstat</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Top 20 memory hog applications</span>
<span style="color: #007800;">PS_MEM</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-A</span> <span style="color: #660033;">-o</span> pid,pcpu,pmem,start_time,state,<span style="color: #000000; font-weight: bold;">time</span>,<span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'($_ = join &quot;&quot;,&lt;&gt;) =~ s/(\t)/     /g; print;'</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> -<span style="color: #000000;">20</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Top 10 CPU usage applications</span>
<span style="color: #007800;">PS_CPU</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-A</span> <span style="color: #660033;">-o</span> pid,pcpu,pmem,start_time,state,<span style="color: #000000; font-weight: bold;">time</span>,<span style="color: #c20cb9; font-weight: bold;">comm</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'($_ = join &quot;&quot;,&lt;&gt;) =~ s/(\t)/     /g; print;'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-g</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> -<span style="color: #000000;">10</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#  memory usage in MB</span>
<span style="color: #007800;">FREE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">free</span> -m<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">PROCINFO</span>=<span style="color: #000000; font-weight: bold;">`</span>procinfo<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># iptables status</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #000000; font-weight: bold;">`</span>iptables -nL<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># established connections</span>
<span style="color: #007800;">NETSTAT</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> <span style="color: #660033;">-na</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-i</span> esta <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> 127.0.0.1 <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-n</span> -t. -k2<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># line divider</span>
<span style="color: #007800;">DL</span>=<span style="color: #ff0000;">&quot;==================================================================================&quot;</span>
&nbsp;
<span style="color: #007800;">FINAL</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${DL}</span> 
<span style="color: #780078;">`date`</span>
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${SERVER}</span> 
<span style="color: #007800;">${DL}</span> 
<span style="color: #007800;">${WHO}</span> 
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${FREE}</span>
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${MPSTAT}</span>
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${VMSTAT}</span> 
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${PROCINFO}</span>
<span style="color: #007800;">${DL}</span> 
Top 10 CPU processes
<span style="color: #007800;">${PS_CPU}</span> 
<span style="color: #007800;">${DL}</span>
Top 20 Memory processes
<span style="color: #007800;">${PS_MEM}</span> 
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${IPTABLES}</span>
<span style="color: #007800;">${DL}</span>
<span style="color: #007800;">${NETSTAT}</span>
<span style="color: #007800;">${DL}</span>
&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${FINAL}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> 
  <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'($_ = join &quot;&quot;,&lt;&gt;) =~ s/(\t)/     /g; print;'</span> <span style="color: #000000; font-weight: bold;">|</span> 
  sendEmail <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${EMAIL_FROM}</span>&quot;</span> <span style="color: #660033;">-u</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${SERVER}</span> comparator&quot;</span> <span style="color: #660033;">-t</span> <span style="color: #800000;">${EMAIL_TO}</span></pre></div></div>

<p>Resources:</p>
<p>- http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html<br />
- http://pagesperso-orange.fr/sebastien.godard/documentation.html<br />
- http://caspian.dotconf.net/menu/Software/SendEmail/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2009/01/08/linux-script-to-collect-system-statistics-and-send-to-your-email/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Blazing Fast Firefox using OSX RamDisk</title>
		<link>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/</link>
		<comments>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 09:32:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ramdisk]]></category>
		<category><![CDATA[tmpfs]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=55</guid>
		<description><![CDATA[Firefox does a lot of IO to the disk even thou you have lots of spare Ram, due to Sqlite, Bookmarks, History and Cache.
To make Firefox faster is to store the whole profile folder into a Ram Disk.
RamDisk in Linux are called TmpFS. You can also use shared memory folder /dev/shm if you have it [...]]]></description>
			<content:encoded><![CDATA[<p>Firefox does a lot of IO to the disk even thou you have lots of spare Ram, due to Sqlite, Bookmarks, History and Cache.</p>
<p>To make Firefox faster is to store the whole profile folder into a Ram Disk.<br />
RamDisk in Linux are called TmpFS. You can also use shared memory folder /dev/shm if you have it in your fstab.</p>
<p>This <a href="http://forums.gentoo.org/viewtopic.php?p=5319242"> post </a> in the gentoo forums explains how to do it in Gentoo linux.</p>
<p>I made a similar script to make it work in OSX Leopard.</p>
<p>The Script have 2 parts, Start.sh and Stop.sh<br />
Here are the Scripts:</p>
<p>Start.sh</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;"># Run this script to enable the Ramdisk for Firefox profiles</span>
<span style="color: #007800;">VolumeName</span>=<span style="color: #ff0000;">&quot;Mozilla&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Size in MB, make sure is not too low or not too high</span>
<span style="color: #007800;">SizeInMB</span>=<span style="color: #000000;">220</span>
&nbsp;
<span style="color: #007800;">NumSectors</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">*</span>SizeInMB<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #007800;">DeviceName</span>=<span style="color: #000000; font-weight: bold;">`</span>hdid <span style="color: #660033;">-nomount</span> ram:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$NumSectors</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$DeviceName</span>
&nbsp;
diskutil eraseVolume HFS+ RAMDisk <span style="color: #007800;">$DeviceName</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># move the current profiles folder</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> Profiles Profiles_ <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># make a symlink to the ramdisk</span>
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>RAMDisk .<span style="color: #000000; font-weight: bold;">/</span>Profiles <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># then copy it to the ramdisk</span>
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> Profiles_<span style="color: #000000; font-weight: bold;">/*</span> Profiles</pre></div></div>

<p>Stop.sh</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: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Cache<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># clean the cache</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span>  Profiles<span style="color: #000000; font-weight: bold;">/*/</span>Cache<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># will save your modifications back to the DISK</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #660033;">-av</span> <span style="color: #660033;">--delete</span> .<span style="color: #000000; font-weight: bold;">/</span>Profiles<span style="color: #000000; font-weight: bold;">/</span> .<span style="color: #000000; font-weight: bold;">/</span>Profiles_<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
&nbsp;
<span style="color: #666666; font-style: italic;"># sometimes during unmount it will say disk is in use.</span>
<span style="color: #666666; font-style: italic;"># make sure you close firefox before.</span>
<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>RAMDisk <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> Profiles <span style="color: #000000; font-weight: bold;">&amp;</span>amp;<span style="color: #000000; font-weight: bold;">&amp;</span>amp;
<span style="color: #c20cb9; font-weight: bold;">mv</span> Profiles_ Profiles</pre></div></div>

<p>You can also use &#8216;tar&#8217; instead of &#8216;rsync&#8217;. I just love rsync more.</p>
<p>* Warning: The ramdisk contents will be erased after you umount the ramdisk.</p>
<p>Have fun.</p>
<p><strong><a href="http://www.gentoo.org">Gentoo Linux ROCKS</a></strong></p>
<p>Update:</p>
<p>To speed up firefox even more  run these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Caches<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>Profiles
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*/*</span>.sqlite; <span style="color: #000000; font-weight: bold;">do</span> sqlite3 <span style="color: #007800;">$i</span> VACUUM;<span style="color: #000000; font-weight: bold;">done</span>;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Application\ Support<span style="color: #000000; font-weight: bold;">/</span>Firefox<span style="color: #000000; font-weight: bold;">/</span>Profiles
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*/*</span>.sqlite; <span style="color: #000000; font-weight: bold;">do</span> sqlite3 <span style="color: #007800;">$i</span> VACUUM;<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/12/18/blazing-fast-firefox-using-osx-ramdisk/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Getting Filevault on a HFS+ Case-Sensitive Filesystem</title>
		<link>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/</link>
		<comments>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 13:55:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[osx]]></category>
		<category><![CDATA[filevault]]></category>

		<guid isPermaLink="false">http://www.frederico-araujo.com/?p=45</guid>
		<description><![CDATA[The OSX file vault feature will only let you activate it on your current home folder if you have a HFS+ case-insensitive file system. It will not let you activate it on a current HFS case-sensitive.
But there is a trick, when creating a &#8220;new&#8221; clean user it will allow you to enable filevault for that [...]]]></description>
			<content:encoded><![CDATA[<p>The OSX file vault feature will only let you activate it on your current home folder if you have a HFS+ case-insensitive file system. It will not let you activate it on a current HFS case-sensitive.</p>
<p>But there is a trick, when creating a &#8220;new&#8221; clean user it will allow you to enable filevault for that new user.</p>
<p>So, here is how you do it.</p>
<p>But before you try, make sure you have enough free space, try to get rid of huge files and folders, backup your data. (in this case, we will copy your data, so you will have 2 copies for safety)</p>
<p>Also clean your applications cache, such as firefox cache, camino, opera,<br />
~/Library/caches/com.apple.Safari/Webpage\ Previews/ , etc&#8230;: and close most of your applications.</p>
<p>$ cd ~/Library/Caches</p>
<p>$ find ./ -name &#8220;Cache&#8221; -exec rm -rf {} \;</p>
<p>$ rm -rf ~/Library/Caches/com.apple.Safari/Webpage\ Previews/Incoming/*</p>
<p>Steps</p>
<p>1. Create another admin user, for example &#8220;admin&#8221;, with administrator privileges</p>
<p>2. login as that user.</p>
<p>3. move your old user folder.</p>
<p>$ cd /Users/</p>
<p>$ sudo mv myusername myusername.bak</p>
<p>3. delete your old user from the &#8220;Accounts&#8221; preferences pane.</p>
<p>4. then create it again and check the option to use filevault</p>
<p>5. Logout from &#8220;admin&#8221;  and login again as newuser.</p>
<p>6. Now copy the old data to your home folder. ( will take a very long time for that)<br />
update: You must use rsync instead of cp, so that you also copy your VERY important hidden files. such as .ssh .gnupg .vimrc .gem .gitconfig  etc..</p>
<p>$ sudo /usr/bin/rsync -av /Users/myusername.bak/ /Users/myusername/</p>
<p># watch out if you have files that should not change the ownership, such as server backups.<br />
$ sudo chown -R  myusername ~/</p>
<p>7. Logout and login again, for your preferences to take effect</p>
<p>8. If everything looks fine, you might just delete the backup folder.</p>
<p>$ sudo rm -rf /Users/myusername.bak</p>
<p>if you have any confusions let me know in comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederico-araujo.com/2008/11/04/getting-filevault-on-a-hfs-case-sensitive-filesystem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
