<?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>Ivan Kuznetsov &#187; Linux</title>
	<atom:link href="http://www.ivankuznetsov.com/category/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ivankuznetsov.com</link>
	<description>Entrepreneur, Ruby on Rails and Ubuntu fanatic, consultant</description>
	<lastBuildDate>Fri, 01 Jul 2011 22:03:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>vim is the best editor, also for RoR development</title>
		<link>http://www.ivankuznetsov.com/2011/06/vim-is-the-best-editor-also-for-ror-development.html</link>
		<comments>http://www.ivankuznetsov.com/2011/06/vim-is-the-best-editor-also-for-ror-development.html#comments</comments>
		<pubDate>Wed, 15 Jun 2011 15:35:15 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=329</guid>
		<description><![CDATA[vim is a natural choice when you&#8217;re starting a new programming project (if you&#8217;re emacs or textmate adept &#8211; you can stop reading now If you&#8217;re starting a Ruby on Rails project there are a couple of scripts/configurations you might want to install to make development with vim an even more pleasant experience. 1. Rails.vim [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vim.org/"><a href="http://www.ivankuznetsov.com/wp-content/uploads/Screenshot.png"><img class="alignleft size-full wp-image-330" title="Rails and vim " src="http://www.ivankuznetsov.com/wp-content/uploads/Screenshot.png" alt="" width="300" height="176" /></a>vim</a> is a natural choice when you&#8217;re starting a new programming project (if you&#8217;re emacs or textmate adept &#8211; you can stop reading now <img src='http://www.ivankuznetsov.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  If you&#8217;re starting a Ruby on Rails project there are a couple of scripts/configurations you might want to install to make development with vim an even more pleasant experience.</p>
<p>1. <a href="https://github.com/tpope/vim-rails" target="_blank">Rails.vim</a> by <a href="http://tpo.pe/" target="_blank">Tim Pope</a></p>
<p>To install just copy autoload/rails.vim, plugin/rails.vim, and doc/rails.txt to corresponding directories in ~/.vim</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=1567" target="_blank">Vim scripts section</a> has a full description of the functionality. Some highlights:</p>
<ul>
<li>Easy navigation between models, controllers and views with :Rmodel, :Rview, :Rcontroller commands</li>
<li>Syntax highlighting</li>
<li>CTRL-X CTRL-U for autocompletion</li>
<li>:Rtree for project tree (see item 2)</li>
</ul>
<p>2. <a href="http://www.vim.org/scripts/script.php?script_id=1658" target="_blank">NERD Tree</a> by <a href="http://got-ravings.blogspot.com/" target="_blank">Marty Grenfell</a></p>
<p>Another must-have. Provides you with an easy way to navigate your project tree. Rails.vim nicely integrates with this one.</p>
<p>3. Colour schemas</p>
<p>If you want to save your eyes &#8211; use dark background when developing. Personally I prefer one of the standard vim themes &#8211; Desert , but <a href="http://www.vim.org/scripts/script.php?script_id=368" target="_blank">Ocean Deep</a> is also very good.</p>
<p>Copy theme file to ~/.vim/colors and then use</p>
<pre>:colorscheme oceandeep
</pre>
<p>command to apply it.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2011%2F06%2Fvim-is-the-best-editor-also-for-ror-development.html&amp;title=vim%20is%20the%20best%20editor%2C%20also%20for%20RoR%20development" id="wpa2a_2"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2011/06/vim-is-the-best-editor-also-for-ror-development.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Flash player browser plugin in 64-bit Ubuntu 11.04</title>
		<link>http://www.ivankuznetsov.com/2011/06/installing-flash-player-browser-plugin-in-64-bit-ubuntu-11-04.html</link>
		<comments>http://www.ivankuznetsov.com/2011/06/installing-flash-player-browser-plugin-in-64-bit-ubuntu-11-04.html#comments</comments>
		<pubDate>Wed, 15 Jun 2011 09:30:48 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=322</guid>
		<description><![CDATA[I got a new hard drive for my laptop and decided to make a leap of faith and move to 64-bit version of Ubuntu, since I had to install a fresh system anyway. In case you didn&#8217;t know &#8211; Adobe doesn&#8217;t have stable Flash player version for 64-bit Linux. Adobe Labs offer preview release codenamed [...]]]></description>
			<content:encoded><![CDATA[<p>I got a new hard drive for my laptop and decided to make a leap of faith and move to 64-bit version of Ubuntu, since I had to install a fresh system anyway.</p>
<p>In case you didn&#8217;t know &#8211; Adobe doesn&#8217;t have stable Flash player version for 64-bit Linux. Adobe Labs offer <a href="http://labs.adobe.com/technologies/flashplayer10/square/">preview release codenamed &#8220;Square&#8221;</a> for 64-bit platforms. It can&#8217;t be installed via standard Ubuntu repositories, so get ready to get your hands dirty in the terminal.</p>
<p>To install 64-bit Flash player plugin do the following:</p>
<p>1. Download the latest version of the plugin at <a href="http://labs.adobe.com/downloads/flashplayer10_square.html" target="_blank">http://labs.adobe.com/downloads/flashplayer10_square.html</a> (currently it is v.10.2 preview 3 from November 30th, 2010)<br />
2. Go to your downloads directory and extract the plugin binary</p>
<pre>tar xvzf flashplayer10_2_p3_64bit_linux_111710.tar.gz</pre>
<p>3. Create a directory for browser plugins in your users home directory</p>
<pre>mkdir -p ~/.mozilla/plugins</pre>
<p>4. Move extracted in step 2 Flash player plugin binary to its new location</p>
<pre>mv libflashplayer.so ~/.mozilla/plugins</pre>
<p>5. Close all browser windows and restart the browser.</p>
<p>6. In Firefox or Chrome go to about:plugins to verify that there&#8217;s Shockwave Flash plugin available</p>
<p>&nbsp;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2011%2F06%2Finstalling-flash-player-browser-plugin-in-64-bit-ubuntu-11-04.html&amp;title=Installing%20Flash%20player%20browser%20plugin%20in%2064-bit%20Ubuntu%2011.04" id="wpa2a_4"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2011/06/installing-flash-player-browser-plugin-in-64-bit-ubuntu-11-04.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Increasing Ruby interpreter performance by adjusting garbage collector settings</title>
		<link>http://www.ivankuznetsov.com/2010/10/increasing-ruby-interpreter-performance-by-adjusting-garbage-collector-settings.html</link>
		<comments>http://www.ivankuznetsov.com/2010/10/increasing-ruby-interpreter-performance-by-adjusting-garbage-collector-settings.html#comments</comments>
		<pubDate>Sun, 10 Oct 2010 23:10:12 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[garbage collector]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=305</guid>
		<description><![CDATA[According to Evan Weaver from Twitter it is possible for a typical production Rails app on Ruby 1.8 to recover 20% to 40% of user CPU by simply adjusting Ruby garbage collector settings. In August I set out on a quest to verify that statement on HeiaHeia servers. Results have really exceeded my expectations. Time to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ivankuznetsov.com/wp-content/uploads/garbage.jpg"><img class="alignleft size-thumbnail wp-image-309" title="garbage" src="http://www.ivankuznetsov.com/wp-content/uploads/garbage-150x150.jpg" alt="" width="150" height="150" /></a>According to <a href="http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/" target="_blank">Evan Weaver from Twitter</a> it is possible for a typical production Rails app on Ruby 1.8 to recover 20% to 40% of user CPU by simply adjusting Ruby garbage collector settings. In August I set out on a quest to verify that statement on <a href="http://www.heiaheia.com" target="_blank">HeiaHeia</a> servers. Results have really exceeded my expectations. Time to execute application tests locally decreased by 46%. On production servers CPU utilisation decreased by almost 40%.</p>
<div><span id="more-305"></span></div>
<p>But let&#8217;s start from the beginning. I should say right away that we at HeiaHeia are using <a href="http://www.rubyenterpriseedition.com/" target="_blank">Ruby Enterprise Edition</a>, so I didn&#8217;t have to apply patches to Ruby source code that Evan is talking about in his post. Before starting to analyse GC current usage it will be useful to read a brilliant <a href="http://timetobleed.com/garbage-collection-and-the-ruby-heap-from-railsconf/">overview of Ruby garbage collection</a> by Joe Damato. It&#8217;ll help to understand what&#8217;s going to happen next. It is also useful to read <a href="http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning" target="_blank">REE documentation on garbage collector performance tuning</a>.</p>
<p>And as before any optimisation it is good to get the reference metrics, so that you know you actually improved something by changing settings, and didn&#8217;t make it worse. In this case I measured:</p>
<div>
<ul>
<li>number of garbage collector calls when loading HeiaHeia-feed</li>
<li>local tests execution time (unit + functional)</li>
<li>application server CPU load and average response time</li>
</ul>
</div>
<p>To measure number of garbage collector calls per one page I used <a href="http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/" target="_blank">Scrap &#8211; a nice tool by Chris Heald</a>. Chris also describes the tuning process in great detail, so I&#8217;m not going to repeat it &#8211; just go and read his blog.</p>
<p>To measure local test execution time I just ran <span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">rake test </span>5 times and took the average of all runs.</p>
<p>To measure application server CPU load and average response time I used <a href="http://www.newrelic.com/" target="_blank">NewRelic</a> tool (free version should be enough to do the measurement).</p>
<p>When I first loaded feed page with Scrap enabled I saw 36 GC cycles, and Ruby spend 1.12s in GC cycles (these figures are from the development server, so response time is big). After playing a bit with the settings and monitoring GC cycles number and unused heap after each allocation with Scrap, I ended up with the same settings as Twitter uses in production:</p>
<pre><code>export RUBY_HEAP_MIN_SLOTS=500000
export RUBY_HEAP_SLOTS_INCREMENT=250000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000</code></pre>
<p>These settings reduced GC cycles number down to 7 (from 36), and Ruby spent now only 0.62s in GC instead of 1.12s when loading feed page (again, load times are bigger on our development server).</p>
<p>After introducing same settings on my local machine project tests took only 148s &#8211; down from 274 seconds before optimisation &#8211; a whopping 46% improvement.</p>
<p>We have multiple identical application servers, so I introduced the new settings only on one of the application servers, to compare the results on a live system (during low traffic hours). Here&#8217;s the picture from NewRelic:</p>
<pre><span style="font-family: monospace;">Server        Instances        Apdex          Resp.time    Throughput    CPU          Memory
</span><span style="font-family: monospace;">hh-app1     3 Instances         0.86      	407 ms       30 rpm      14 %	      349 MB
</span><span style="font-family: monospace;">hh-app2     3 Instances         0.91   	        311 ms	     30 rpm       8 %	      413 MB</span></pre>
<p>hh-app2 had optimised garbage collector. With the same throughput CPU load  was only 8% vs 14% with non-optimised GC. However that improvement came at a cost of increased memory consumption (413M vs 349M). However response time and lower CPU load proved to be a lot more important than memory consumption, so I rolled out the new settings on all production servers.</p>
<p>Making <a href="http://nginx.org/" target="_blank">nginx</a> utilise GC settings when spawning <a href="http://www.modrails.com/" target="_blank">Passenger</a> instances is easy, and is well <a href="http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/" target="_blank">described by Chris</a>. Here are instructions that work nice with server and Nginx setup on Ubuntu as I described in <a href="http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html" target="_blank">earlier posts</a>.</p>
<p>Create /usr/local/bin/ruby-with-env file (as a root) that will set GC settings in the environment and then launch Ruby:</p>
<pre>#!/bin/bash
export RUBY_HEAP_MIN_SLOTS=1500000
export RUBY_HEAP_SLOTS_INCREMENT=500000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000
exec "/usr/local/bin/ruby" "$@"</pre>
<div>Make this file executable by all:</div>
<pre>sudo chmod a+x /usr/local/bin/ruby-with-env</pre>
<div>Now tell Passenger to use that file instead of launching Ruby directly &#8211; edit /opt/nginx/conf/nginx.conf and replace</div>
<pre>passenger_ruby /usr/local/bin/ruby;</pre>
<div>with</div>
<pre>passenger_ruby /usr/local/bin/ruby-with-env;</pre>
<div>Now restart Nginx &#8211; and you&#8217;ve got yourself a faster Ruby!</div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F10%2Fincreasing-ruby-interpreter-performance-by-adjusting-garbage-collector-settings.html&amp;title=Increasing%20Ruby%20interpreter%20performance%20by%20adjusting%20garbage%20collector%20settings" id="wpa2a_6"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/10/increasing-ruby-interpreter-performance-by-adjusting-garbage-collector-settings.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Call to undefined function: imagecreatefromjpeg()</title>
		<link>http://www.ivankuznetsov.com/2010/10/call-to-undefined-function-imagecreatefromjpeg.html</link>
		<comments>http://www.ivankuznetsov.com/2010/10/call-to-undefined-function-imagecreatefromjpeg.html#comments</comments>
		<pubDate>Sun, 10 Oct 2010 08:34:23 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[gd]]></category>
		<category><![CDATA[imagecreatefromjpeg]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=299</guid>
		<description><![CDATA[While installing new Joomla modules I came across this PHP error (yep, still have to deal with PHP occasionally). I had PHP compiled from source on Ubuntu 10.04 as per earlier instructions. Quick check of phpinfo() indicated that while gd module was compiled in, it didn&#8217;t have JPEG support: GD Support enabled GD Version bundled [...]]]></description>
			<content:encoded><![CDATA[<p>While installing new Joomla modules I came across this PHP error (yep, still have to deal with PHP occasionally). I had PHP compiled from source on Ubuntu 10.04 as per <a href="http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html">earlier instructions</a>. Quick check of phpinfo() indicated that while gd module was compiled in, it didn&#8217;t have JPEG support:</p>
<pre>GD Support         enabled
GD Version         bundled (2.0.34 compatible)
GIF Read Support   enabled
GIF Create Support enabled
PNG Support        enabled
WBMP Support       enabled
XBM Support        enabled</pre>
<p>Making sure that JPEG libraries are installed</p>
<pre>sudo aptitude install libjpeg libjpeg-dev</pre>
<p>and reconfiguring PHP with &#8211;with-jpeg-dir flag (the rest of the compilation process remains the same as <a href="http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html">here</a>)</p>
<pre>./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib
--enable-mbstring --with-openssl --with-mysql --with-mysql-sock
--with-gd --without-sqlite --disable-pdo --with-jpeg-dir=/usr/lib</pre>
<p>and then restarting nginx</p>
<pre>sudo /etc/init.d/nginx restart</pre>
<p>helped to solve the problem.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F10%2Fcall-to-undefined-function-imagecreatefromjpeg.html&amp;title=Call%20to%20undefined%20function%3A%20imagecreatefromjpeg%28%29" id="wpa2a_8"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/10/call-to-undefined-function-imagecreatefromjpeg.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Rails applications using Nginx with Passenger on Ubuntu Server</title>
		<link>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html</link>
		<comments>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html#comments</comments>
		<pubDate>Fri, 14 May 2010 10:40:50 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[mod_rails]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=279</guid>
		<description><![CDATA[If you&#8217;re planning to run Rails applications on Nginx using Phusion Passenger, and do it on Ubuntu Linux, here&#8217;s what needs to be done. Even though there&#8217;s Ubuntu nginx package available (which works perfectly when you&#8217;re running PHP apps using FCGI), if you want to take into use Phusion Passenger, you&#8217;ll need to recompile Nginx [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ivankuznetsov.com/wp-content/uploads/enterprise_logo.png"><img class="alignleft size-full wp-image-281" title="enterprise_logo" src="http://www.ivankuznetsov.com/wp-content/uploads/enterprise_logo.png" alt="" width="261" height="68" /></a>If you&#8217;re planning to run <a href="http://rubyonrails.org/" target="_blank">Rails</a> applications on <a href="http://www.nginx.org" target="_blank">Nginx</a> using <a href="http://www.modrails.com/" target="_blank">Phusion Passenger</a>, and do it on <a href="http://www.ubuntu.com" target="_blank">Ubuntu</a> Linux, here&#8217;s what needs to be done.</p>
<p>Even though there&#8217;s Ubuntu nginx package available (which works perfectly when you&#8217;re running <a href="http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html">PHP apps using FCGI</a>), if you want to take into use Phusion Passenger, you&#8217;ll need to recompile Nginx from sources.</p>
<p>Instructions below were verified on Ubuntu 10.04 (Lucid Lynx) Server Edition.</p>
<p><span id="more-279"></span></p>
<p>If you already have Nginx ubuntu package installed, uninstall it (NOTE! purge will delete all configuration files &#8211; so if you changed them &#8211; make a backup for future reference):</p>
<pre>sudo aptitude purge nginx</pre>
<p>Assuming you already have Rails stack installed, install Passenger gem:</p>
<pre>sudo gem install passenger</pre>
<p>At the time of this writing the latest version of Passenger is 2.2.11</p>
<p>Let&#8217;s check dependencies that Ubuntu nginx package has and install them before compilation:</p>
<pre>aptitude show nginx | grep Depends</pre>
<div>You&#8217;ll see something like:</div>
<pre>Depends: libc6 (&gt;= 2.4), libpcre3 (&gt;= 7.7), libssl0.9.8 (&gt;= 0.9.8k-1), zlib1g</pre>
<div>Install build dependencies and start nginx module installation (it will offer you to recompile nginx)</div>
<pre>sudo apt-get install libc6 libpcre3 libssl0.9.8 zlib1g
sudo /usr/local/bin/passenger-install-nginx-module</pre>
<div>Choose option 1 (Yes: download, compile and install Nginx for me) unless you need special configuration parameters or need features not enabled by default (like SSL).</div>
<div>Further instructions assume that you also chose default installation directory /opt/nginx.</div>
<div>If you&#8217;ve purchased Passenger Enterprise Edition, don&#8217;t forget to register it:</div>
<pre>sudo /usr/local/bin/passenger-make-enterprisey</pre>
<div>Now add nginx init script (I just copied this from Ubuntu default nginx package):</div>
<pre>sudo vim /etc/init.d/nginx</pre>
<div>with the following content:</div>
<pre>#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/nginx/sbin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

. /lib/lsb/init-functions

test_nginx_config() {
  if nginx -t $DAEMON_OPTS
  then
    return 0
  else
    return $?
  fi
}

case "$1" in
  start)
        echo -n "Starting $DESC: "
        test_nginx_config
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON || true
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON || true
        sleep 1
        test_nginx_config
        start-stop-daemon --start --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
        echo "$NAME."
        ;;
  reload)
        echo -n "Reloading $DESC configuration: "
        test_nginx_config
        start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON || true
        echo "$NAME."
        ;;
  configtest)
        echo -n "Testing $DESC configuration: "
        if test_nginx_config
        then
          echo "$NAME."
        else
          exit $?
        fi
        ;;
  status)
        status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx &amp;&amp; exit 0 || exit $?
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" &gt;&amp;2
        exit 1
        ;;
esac

exit 0</pre>
<div>Now make this script executable add it to default run levels:</div>
<pre>sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults</pre>
<div>Edit  nginx.conf to look like this:</div>
<pre>user www-data;
worker_processes  4;

error_log  /opt/nginx/logs/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  8192;
    use epoll;
}

http {
    passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11;
    passenger_ruby /usr/local/bin/ruby;

    include       /opt/nginx/conf/mime.types;

    # set a default type for the rare situation that
    # nothing matches from the mimie-type include
    default_type application/octet-stream;

    # This log format is compatible with any tool like awstats
    # that can parse standard apache logs.
    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"' ;

    access_log  /opt/nginx/logs/access.log;

    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  0;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    include /opt/nginx/conf/sites-enabled/*;
}</pre>
<div>Now create virtual hosts structure (so that it looks like the structure created by Ubuntu original nginx package):</div>
<div>
<pre>sudo mkdir /opt/nginx/conf/sites-available
sudo mkdir /opt/nginx/conf/sites-enabled</pre>
</div>
<div>Now it is time to configure your first rails site. Create virtual host configuration in sites-available.</div>
<pre>sudo vim /opt/nginx/conf/sites-available/mysite.com</pre>
<div>Content can be something like:</div>
<pre>server {
        listen   80;
        server_name  www.mysite.com;

        access_log  /home/user/logs/www.mysite.com/access.log;
        root   /home/user/www.mysite.com/public;

        # serve static content directly
        location ~* \.(ico|jpg|gif|png|css|js|swf|html)$ {
          if (-f $request_filename) {
            expires max;
            break;
          }
        }

        passenger_enabled on;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
}</pre>
<div>Make a symlink in sites-enabled directory and restart nginx.</div>
<pre>sudo ln -s /opt/nginx/conf/sites-available/mysite.com /opt/nginx/conf/sites-enabled/mysite.com
sudo /etc/init.d/nginx restart</pre>
<div>Now open the browser and check that your site is working.</div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F05%2Frunning-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html&amp;title=Running%20Rails%20applications%20using%20Nginx%20with%20Passenger%20on%20Ubuntu%20Server" id="wpa2a_10"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/05/running-rails-applications-using-nginx-with-passenger-on-ubuntu-server.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Moving Joomla, WordPress and other PHP/FastCGI apps to Nginx</title>
		<link>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html</link>
		<comments>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html#comments</comments>
		<pubDate>Fri, 14 May 2010 07:01:50 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[fast-cgi]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=272</guid>
		<description><![CDATA[Have you moved your site from Apache to Nginx and now your FastCGI (php-cgi/spawn-fcgi) processes die/hang/crash periodically and your users see &#8220;HTTP 502 Bad gateway&#8221; or &#8220;HTTP 504 Gateway timeout&#8221; instead of a website? I have faced this problem and found a relatively simple and robust solution. Here&#8217;s how I did it on Ubuntu 9.10 (Karmic [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ivankuznetsov.com/wp-content/uploads/nginx-logo.png"><img class="alignleft size-full wp-image-273" title="nginx-logo" src="http://www.ivankuznetsov.com/wp-content/uploads/nginx-logo.png" alt="" width="350" height="90" /></a>Have you moved your site from <a href="http://apache.org/" target="_blank">Apache</a> to <a href="http://nginx.org/" target="_blank">Nginx</a> and now your FastCGI (php-cgi/spawn-fcgi) processes die/hang/crash periodically and your users see &#8220;HTTP 502 Bad gateway&#8221; or &#8220;HTTP 504 Gateway timeout&#8221; instead of a website?</p>
<p>I have faced this problem and found a relatively simple and robust solution. Here&#8217;s how I did it on Ubuntu 9.10 (Karmic Koala) and 10.04 (Lucid Lynx) server edition.</p>
<p><span id="more-272"></span>Solution was to replace default FastCGI implementation with <a href="http://php-fpm.org/" target="_blank">PHP-FPM</a> (FastCGI Process Manager). PHP-FPM is not supported in PHP out of the box &#8211; so if you use PHP 5.2.*, you&#8217;ll need to apply a patch and recompile PHP, and if you&#8217;re using PHP 5.3.* (at least in 5.3.2 PHP-FPM is not yet in the core) &#8211; you&#8217;ll need to check out PHP-FPM from PHP SVN.</p>
<p>Let&#8217;s start with uninstalling default Ubuntu php packages:</p>
<pre>sudo apt-get remove php5*</pre>
<p>Now we need to install dependencies. Note, that Ubuntu comes with a new autoconf tool version, which is <a href="https://bugs.launchpad.net/ubuntu/+source/php5/+bug/411890" target="_blank">not compatible</a> with PHP, that&#8217;s why for successful compilation you need to temporarily install autoconf2.13 package.</p>
<pre>sudo apt-get install libcurl4-openssl-dev libmcrypt-dev libxml2-dev libpng-dev 
autoconf2.13 libevent-dev libltdl-dev</pre>
<p>Download latest stable PHP 5.2.13, Suhosin patch, PHP-FPM patch</p>
<pre>cd ~/tmp
wget <a href="http://pl2.php.net/get/php-5.2.13.tar.gz/from/pl.php.net/mirror">http://pl2.php.net/get/php-5.2.13.tar.gz/from/pl.php.net/mirror</a>
wget <a href="http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz">http://download.suhosin.org/suhosin-patch-5.2.13-0.9.7.patch.gz</a>
wget <a href="http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz">http://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz</a>
tar xvzf php-5.2.13.tar.gz
gunzip suhosin-patch-5.2.13-0.9.7.patch.gz
gunzip php-5.2.13-fpm-0.5.13.diff.gz
cd php-5.2.13
patch -p 1 -i ../php-5.2.13-fpm-0.5.13.diff
patch -p 1 -i ../suhosin-patch-5.2.13-0.9.7.patch
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo
make
make test
sudo make install</pre>
<p>Alternatively you can download latest stable PHP 5.3.2, Suhosin patch, apply PHP-FPM patch. Note, that not all PHP based projects and plugins work correctly with new PHP 5.3 &#8211; it is not backwards compatible with PHP 5.2. I had troubles at least with some Joomla plugins and ZenCart.</p>
<pre>cd ~/tmp
<a href="http://fi.php.net/get/php-5.3.2.tar.gz/from/this/mirror">http://fi.php.net/get/php-5.3.2.tar.gz/from/this/mirror</a>
wget <a href="http://download.suhosin.org/suhosin-patch-5.3.2-0.9.9.1.patch.gz">http://download.suhosin.org/suhosin-patch-5.3.2-0.9.9.1.patch.gz</a>
tar xvzf php-5.3.2.tar.gz
gunzip suhosin-patch-5.3.2-0.9.9.1.patch.gz
cd php-5.3.2
patch -p 1 -i ../suhosin-patch-5.3.2-0.9.9.1.patch
svn co <a href="http://svn.php.net/repository/php/php-src/trunk/sapi/fpm">http://svn.php.net/repository/php/php-src/trunk/sapi/fpm</a> sapi/fpm
./buildconf --force
./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-openssl
--with-mysql --with-mysql-sock --with-gd --without-sqlite --disable-pdo --disable-reflection
make
make test
sudo make install</pre>
<p>Uninstall autoconf2.13 after compilation.</p>
<pre>sudo apt-get remove autoconf2.13</pre>
<p>Change user and group of php-fpm processes to user and group of your choice (e.g. www-data and www-data) &#8211; lines 63 and 66</p>
<pre>sudo vim /usr/local/etc/php-fpm.conf</pre>
<p>Edit PHP settings</p>
<pre>sudo vim /etc/php5/cgi/php.ini (in Ubuntu 9.xx)</pre>
<pre>sudo vim /etc/php5/apache2/php.ini (in Ubuntu 10.04)</pre>
<p>Set:</p>
<pre>max_execution_time = 30
memory_limit = 128M
error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off
log_errors = On
error_log = /var/log/php.log
register_globals = Off</pre>
<p>Now if you haven&#8217;t done so yet, install Nginx. Ubuntu 10.04 comes with the latest stable Nginx 0.7.65, so just do:</p>
<pre>sudo apt-get install nginx</pre>
<p>Now you can congifure your sites, e.g. for WordPress Nginx configuration can look like this:</p>
<pre>server {
        listen   80;
        server_name  blog.mysite.com;

        access_log  /home/user/logs/blog.mysite.com/access.log;

        location / {
          root   /home/user/blog.mysite.com;
          index  index.php index.html index.htm;

          # this serves static files that exist without running other rewrite tests
          if (-f $request_filename) {
              expires 30d;
              break;
          }

          # this sends all non-existing file or directory requests to index.php
          if (!-e $request_filename) {
              rewrite ^(.+)$ /index.php?q=$1 last;
          }

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
          include /etc/nginx/fastcgi_params;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          fastcgi_param  SCRIPT_FILENAME  /home/user/blog.mysite.com/$fastcgi_script_name;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
          deny  all;
        }
}</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F05%2Fmoving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html&amp;title=Moving%20Joomla%2C%20WordPress%20and%20other%20PHP%2FFastCGI%20apps%20to%20Nginx" id="wpa2a_12"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/05/moving-joomla-wordpress-and-other-phpfastcgi-apps-to-nginx.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Setting up your own git server on Ubuntu</title>
		<link>http://www.ivankuznetsov.com/2010/05/setting-up-your-own-git-server-on-ubuntu.html</link>
		<comments>http://www.ivankuznetsov.com/2010/05/setting-up-your-own-git-server-on-ubuntu.html#comments</comments>
		<pubDate>Thu, 13 May 2010 12:39:00 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[gitosis]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=262</guid>
		<description><![CDATA[This will create a new user &#8216;gitosis&#8217; and prepare a structure for repositories in /srv/gitosis. Now let&#8217;s initialize a gitosis-admin repo &#8211; it is used for managing repositories and access Of course there&#8217;s always an option to use github. And if you&#8217;re working on an open source project, or want to concentrate on coding and [...]]]></description>
			<content:encoded><![CDATA[<p>This will create a new user &#8216;gitosis&#8217; and prepare a structure for repositories in /srv/gitosis. Now let&#8217;s initialize a gitosis-admin repo &#8211; it is used for managing repositories and access<img class="alignleft size-full wp-image-261" title="git-logo" src="http://www.ivankuznetsov.com/wp-content/uploads/git-logo.png" alt="" width="97" height="188" /></p>
<p>Of course there&#8217;s always an option to use <a href="http://www.github.com" target="_blank">github</a>. And if you&#8217;re working on an open source project, or want to concentrate on coding and not system administration, github is a lot better option than setting up and managing your own git server (I&#8217;ve been so impressed by <a href="http://twitter.com/defunkt" target="_blank">@defunkt</a>&#8216;s presentation on <a href="http://www.frozenrails.eu" target="_blank">#frozenrails</a>, that started recommending github to everyone <img src='http://www.ivankuznetsov.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But if you already pay for a virtual machine somewhere (like <a href="http://www.linode.com" target="_blank">Linode</a>), then setting up your own git server might be a viable option, especially that it is sooo easy.</p>
<p>The following instructions have been verified on Ubuntu 10.04 Lucid Lynx, but should work at least on Ubuntu 9.04 and 9.10 just as well.</p>
<p><span id="more-262"></span></p>
<p>Let&#8217;s start with installing gitosis itself. Issue the following command on the server:</p>
<pre>sudo apt-get install gitosis</pre>
<p>This will create a new user &#8216;gitosis&#8217; and prepare a structure for repositories in /srv/gitosis. Now let&#8217;s initialize a gitosis-admin repo &#8211; it is used for managing repositories and access rights.</p>
<pre>sudo -H -u gitosis gitosis-init &lt; ~/tmp/my_public.key</pre>
<p>You need to have a public key for accessing it. If you don&#8217;t have one yet, you can use</p>
<pre><code>ssh-keygen -t rsa</code></pre>
<p>command on your local machine to generate public/private key pair. Copy public key to the server before initializing gitosis-admin repository.</p>
<p>Now with gitosis-admin repo initialized on the server &#8211; let&#8217;s clone it to the local computer.</p>
<pre>git clone gitosis@myserver.com:gitosis-admin.git</pre>
<p>If you see an error like:</p>
<pre>Permission denied (publickey).
fatal: The remote end hung up unexpectedly</pre>
<p>That is most likely because you restricted access to you server via ssh to only certain users, and gitosis is not one of them. Edit /etc/ssh/sshd_config, find AllowUsers line and add gitosis to the list.</p>
<p>Now that you have successfully cloned gitosis-admin repo to your local computer, you can add  new users and new repositories.</p>
<p>To add new repository, edit gitosis.conf and add lines like:</p>
<pre>[group myrepo]
writable = myrepo
members = user@computer</pre>
<p>After that commit and push the changes to gitosis-admin project:</p>
<pre>git commit -a -m "Added myrepo repository"</pre>
<p>Now you can clone this new repository to your local machine (note .git added to the name of the repository):</p>
<pre>git clone gitosis@mygitserver.com:myrepo.git</pre>
<p>To allow new user to access your repository, get this user&#8217;s public key, copy it to gitosis-admin/keydir as newuser@computer.pub, then edit gitosis.conf and add newuser@computer (without .pub) to the list of members:</p>
<pre>[group myrepo]
writable = myrepo
members = user@computer newuser@computer</pre>
<p>Now add new files and commit and push changes to git server (make sure you really add all files and don&#8217;t forget to push &#8211; these are quite common mistakes when adding new users).</p>
<pre>git add .
git commit -m "Added user newuser"
git push</pre>
<p>With a freshly cloned empty repository you&#8217;ll need to add you first files, do a commit and push origin master:</p>
<pre>vim README.txt
git commit -a -m "Added readme"
git push origin master</pre>
<p>Now you can git pull and git push as much as you like.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F05%2Fsetting-up-your-own-git-server-on-ubuntu.html&amp;title=Setting%20up%20your%20own%20git%20server%20on%20Ubuntu" id="wpa2a_14"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/05/setting-up-your-own-git-server-on-ubuntu.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>No space left on device &#8211; running out of Inodes</title>
		<link>http://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html</link>
		<comments>http://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html#comments</comments>
		<pubDate>Wed, 10 Feb 2010 09:12:56 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[file system]]></category>
		<category><![CDATA[Inode]]></category>
		<category><![CDATA[no space left]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=238</guid>
		<description><![CDATA[One of our development servers went down today. Problems started with deployment script that claimed that claimed &#8220;No space left on device&#8221;, although partition was not nearly full. If you ever run into such trouble &#8211; most likely you have too many small or 0-sized files on your disk, and while you have enough disk [...]]]></description>
			<content:encoded><![CDATA[<p>One of our development servers went down today. Problems started with deployment script that claimed that claimed &#8220;No space left on device&#8221;, although partition was not nearly full. If you ever run into such trouble &#8211; most likely you have too many small or 0-sized files on your disk, and while you have enough disk space, you have exhausted all available <a href="http://www.linfo.org/inode.html" target="_blank">Inodes</a>. Below is the solution for this problem.</p>
<p><span id="more-238"></span></p>
<p>1. check available disk space to ensure that you still have some</p>
<pre style="padding-left: 30px;">$ df

<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">Filesystem           1K-blocks      Used Available Use% Mounted on</span>
/dev/xvda             33030016  10407780  22622236  32% /
tmpfs                   368748         0    368748   0% /lib/init/rw
varrun                  368748        56    368692   1% /var/run
varlock                 368748         0    368748   0% /var/lock
udev                    368748       108    368640   1% /dev
tmpfs                   368748         0    368748   0% /dev/shm</pre>
<p>2. check available Inodes</p>
<pre style="padding-left: 30px;">$ df -i

<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;">Filesystem            Inodes   IUsed   IFree IUse% Mounted on</span>
/dev/xvda            2080768 2080768       0  100% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm</pre>
<div>If you have IUse% at 100 or near, then huge number of small files is the reason for &#8220;No space left on device&#8221; errors.</div>
<p>3. find those little bastards</p>
<pre style="padding-left: 30px;">$ for i in /*; do echo $i; find $i |wc -l; done</pre>
<p>This command will list directories and number of files in them. Once you see a directory with unusually high number of files (or command just hangs over calculation for a long time), repeat the command for that directory to see where exactly the small files are.</p>
<pre style="padding-left: 30px;">$ for i in /home/*; do echo $i; find $i |wc -l; done</pre>
<p>4. once you found the suspect &#8211; just delete the files</p>
<pre style="padding-left: 30px;">$ sudo rm -rf /home/bad_user/directory_with_lots_of_empty_files</pre>
<p>You&#8217;re done. Check the results with df -i command again. You should see something like this:</p>
<pre style="padding-left: 30px;">Filesystem            Inodes   IUsed   IFree IUse% Mounted on

/dev/xvda            2080768  284431 1796337   14% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm</pre>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2010%2F02%2Fno-space-left-on-device-running-out-of-inodes.html&amp;title=No%20space%20left%20on%20device%20%26%238211%3B%20running%20out%20of%20Inodes" id="wpa2a_16"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Upgrading iPhone firmware using VMWare and Ubuntu 9.04</title>
		<link>http://www.ivankuznetsov.com/2009/10/upgrading-iphone-firmware-using-vmware-and-ubuntu-9-04.html</link>
		<comments>http://www.ivankuznetsov.com/2009/10/upgrading-iphone-firmware-using-vmware-and-ubuntu-9-04.html#comments</comments>
		<pubDate>Wed, 14 Oct 2009 07:35:10 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=210</guid>
		<description><![CDATA[This was the second time I upgrade firmware on my iPhone, and second time I ran into the same problem.  In the middle of the update iTunes reports &#8220;Unknown error&#8221; and iPhone dies (well, goes into recovery mode, but it is not much help). If that happened to you, don&#8217;t panic! To make this geeky [...]]]></description>
			<content:encoded><![CDATA[<p>This was the second time I upgrade firmware on my iPhone, and second time I ran into the same problem.  In the middle of the update iTunes reports &#8220;Unknown error&#8221; and iPhone dies (well, goes into recovery mode, but it is not much help). If that happened to you, don&#8217;t panic! To make this geeky combination (Ubuntu 9.04, VMware, iTunes and iPhone software update) work, there&#8217;s a little trick you need to do.<span id="more-210"></span>My setup:</p>
<p>- iPhone 3G 8Gb Sonera<br />
- Ubuntu Linux 9.04 (Jaunty) on Lenovo T61 laptop, kernel 2.6.28-15<br />
- VMware player 2.5.3<br />
- guest OS: WinXP Home SP3 with iTunes 9.0.1.8</p>
<p>goal: upgrading firmware to 3.1.2</p>
<p>I used instructions on <a href="http://freshfoo.com/blog/iphone_upgrade_with_vmware" target="_blank">Menno Smits&#8217; blog</a>. Here&#8217;s the summary:</p>
<p>1. Create a file /etc/modprobe.d/blacklist-usb</p>
<blockquote><p>sudo vim /etc/modprobe.d/blacklist-usb</p></blockquote>
<p>2. Add usb modules not to be loaded into that file</p>
<blockquote><p>blacklist snd_usb_audio<br />
blacklist usbhid</p></blockquote>
<p>I didn&#8217;t list ehci_hcd, and it still worked. By the way, USB HID stands for USB Human Interface Device, and blacklisting it might disable your USB mouse and keyboard as well. See a link in the end of the post how to work around it.</p>
<p>3. Unload blacklisted modules manually, in case if they have been loaded already</p>
<blockquote><p>sudo /sbin/modprobe -r snd_usb_audio<br />
sudo /sbin/modprobe -r usbhid</p></blockquote>
<p>4. Reload kernel event manager for the changes to take effect</p>
<blockquote><p>sudo /etc/init.t/udev reload</p></blockquote>
<p>5. Restart VMware and make sure you also restart Windows in VMware (it took me seveal attempts to figure that this was the problem)</p>
<p>6. Now start iPhone software update in iTunes or &#8220;restore and update&#8221;, if you already tried without disabling usbhid and got your iPhone into recovery mode.</p>
<p>7. After update is complete, remove the blacklist file and restart kernel event manager again</p>
<blockquote><p>sudo rm /etc/modprobe.d/blacklist-usb<br />
sudo /etc/init.t/udev reload</p></blockquote>
<p>If iTunes in WMware do not see iPhone, make sure that it is connected in VMware removable devices menu. Note that during firmware update iPhone might get disconnected &#8211; just connect it again using VMware removable devices menu.</p>
<p>I tried to verify suggestion from <a href="http://teknofire.net/articles/2009/01/08/using-linux-and-vmware-to-update-iphone-firmware/" target="_blank">Will</a> to disable only iPhone in ubuntu, using its USB ID, but don&#8217;t actually know if it worked, because I didn&#8217;t restart Windows in WMware and restore and update failed. Here&#8217;s what I did:</p>
<p>- connected iPhone and checked its USB ID:</p>
<blockquote><p>$ lsusb</p>
<p>Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br />
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 001 Device 024: ID 05ac:1292 Apple, Inc.<br />
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub<br />
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub<br />
Bus 003 Device 004: ID 0a5c:2110 Broadcom Corp. Bluetooth Controller<br />
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub</p></blockquote>
<p>- created a file /etc/modprobe.d/usbhid</p>
<blockquote><p>sudo vim /etc/modprobe.d/usbhid</p></blockquote>
<p>with the following content</p>
<blockquote><p>options usbhid quirks=0×05ac:0×1292:0×04</p></blockquote>
<p>where 0&#215;1292 is the USB ID displayed by lsusb command, and 0&#215;04 is the instruction to ignore device with specified USB ID.</p>
<p>- did everything as isteps 1-7 except that I didn&#8217;t blacklist usbhid and didn&#8217;t unload it manually.</p>
<p>It would be interesting to know if anyone succeeds with iPhone firmware update on Ubuntu without blacklisting usbhid module completely.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2009%2F10%2Fupgrading-iphone-firmware-using-vmware-and-ubuntu-9-04.html&amp;title=Upgrading%20iPhone%20firmware%20using%20VMWare%20and%20Ubuntu%209.04" id="wpa2a_18"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2009/10/upgrading-iphone-firmware-using-vmware-and-ubuntu-9-04.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Setting up Ruby, Rails, Git and Redmine on Dreamhost</title>
		<link>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html</link>
		<comments>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html#comments</comments>
		<pubDate>Thu, 30 Jul 2009 14:58:27 +0000</pubDate>
		<dc:creator>Ivan Kuznetsov</dc:creator>
				<category><![CDATA[Dreamhost]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web/Tech]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.ivankuznetsov.com/?p=195</guid>
		<description><![CDATA[The task is to have: - Redmine installation on redmine.mydomain.com - Several Git repositories on git.mydomain.com with different access rights to each one This proved to be a non-trivial task. There is a number of tutorials on the net, but none of them described the full solution. So after getting it all to work, I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-196" title="Git, RedMine, Ruby, Rails on Dreamhost" src="http://www.ivankuznetsov.com/wp-content/uploads/git.png" alt="Git, RedMine, Ruby, Rails on Dreamhost" width="200" height="150" />The task is to have:<br />
- Redmine installation on redmine.mydomain.com<br />
- Several Git repositories on git.mydomain.com with different access rights to each one</p>
<p>This proved to be a non-trivial task. There is a number of tutorials on the net, but none of them described the full solution. So after getting it all to work, I decided to share all the tips and tricks. Feel free to comment, if you will find problems with the following set of instructions.<br />
<span id="more-195"></span>SSH to redmine.mydomain.com as a user that will be running Redmine (in the following examples it will be &#8216;redmine_user&#8217;).<br />
First, you need to compile openssl &#8211; it will be required for curl, git and redmine.</p>
<pre>mkdir ~/tmp
cd ~/tmp
wget http://www.openssl.org/source/openssl-0.9.8k.tar.gz
tar xzvf openssl-0.9.8k.tar.gz
cd openssl-0.9.8k
./config shared zlib --prefix=$HOME/.packages
make
make install</pre>
<p>Let&#8217;s tell the world that we keep binaries and libraries also in the local directory. Edit ~/.bashrc (it is used by all non-login shells):</p>
<pre>export TZ='Europe/Helsinki'
export PATH="$HOME/.packages/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/.packages/lib"
export GEM_HOME="$HOME/.gems"
export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
export PATH="$HOME/.packages/bin:$HOME/.gems/bin:$PATH"
export RUBYLIB="$HOME/.packages/lib:$RUBYLIB"
export LD_LIBRARY_PATH="$HOME/.packages/lib"

# this ensures our gem install processes don't get killed by the DreamHost police
alias gem="nice -n19 ~/.packages/bin/gem"</pre>
<p>(You can skip TZ &#8211; it is just usefule to have correct time set for your environment. Use tzselect to find out correct TZ string for your region)</p>
<p>And edit ~/.bash_profile (it is used by login shells):</p>
<pre>umask 002
PS1='[\h:$PWD]$ '
alias ll="ls -l"
EDITOR="/usr/bin/vim"
. .bashrc</pre>
<p>Now let&#8217;s apply the changes in active shell:</p>
<pre>cd ~ : . .bash_profile</pre>
<p>Then you need to compile curl, to be able to compile git with curl and execute clone commands on your server.</p>
<pre>cd ~/tmp
wget http://curl.haxx.se/download/curl-7.19.5.tar.gz
tar xzvf curl-7.19.5.tar.gz
cd curl-7.19.5
./configure --prefix=$HOME/.packages --with-ssl=$HOME/.packages
make
make install</pre>
<p>Now get and compile Git. If you are not using Dreamhost PS, you might want to compile it with NO_MMPAP=1, to reduce<br />
probability of git process getting killed by Dreamhost police robots due to extensive memory</p>
<pre>cd ~/tmp
wget http://www.kernel.org/pub/software/scm/git/git-1.6.4.tar.gz
tar xzvf git-1.6.4.tar.gz
cd git-1.6.4
./configure --prefix=$HOME/.packages --with-curl=$HOME/.packages
make
make install</pre>
<p>Let&#8217;s start with ruby and rails related stuff. First readline library is needed, for script/console to work.</p>
<pre>cd ~/tmp
wget http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
tar xzvf readline-5.2.tar.gz
cd readline-5.2
./configure --prefix=$HOME/.packages
make
make install</pre>
<p>Install ruby:</p>
<pre>cd ~/tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p72.tar.gz
tar zxvf ruby-1.8.7-p72.tar.gz
cd ruby-1.8.7-p72
./configure --prefix=$HOME/.packages --with-openssl-dir=$HOME/.packages --with-readline-dir=$HOME/.packages
make
make install</pre>
<p>Install rubygems:</p>
<pre>cd ~/tmp
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar zxvf rubygems-1.3.5.tgz
cd rubygems-1.3.5
ruby setup.rb config --prefix=$HOME/.packages
ruby setup.rb setup
ruby setup.rb install</pre>
<p>Now you can install all required gems and freeze them if necessary.</p>
<p><strong>Installing RedMine</strong></p>
<p>Refer to <a href="http://wiki.dreamhost.com/Redmine" target="_blank">http://wiki.dreamhost.com/Redmine</a> for details.</p>
<p>But there&#8217;s one trick &#8211; if you want RedMine to use just compiled version of Git &#8211; edit in lib/redmine/scm/adapters/git_adapter.rb:</p>
<pre># Git executable name
GIT_BIN = "/home/username/.packages/bin/git"</pre>
<p>If this is not done, default Dreamhost git will be used (which is too old at the moment 1.4.4.4) and Git repository browsing will not work in RedMine<br />
(see <a href="http://groups.google.com/group/phusion-passenger/browse_thread/thread/5080d7c7cfbcf20e" target="_blank">http://groups.google.com/group/phusion-passenger/browse_thread/thread/5080d7c7cfbcf20e</a>).</p>
<p><strong>Setting up Git repository</strong></p>
<p>Refer to <a href="http://wiki.dreamhost.com/Git" target="_blank">http://wiki.dreamhost.com/Git</a> for details.</p>
<p>Couple of tricks here. There are bugs in WebDAV functionality in Ubuntu &#8211; so if you&#8217;re using it &#8211; launch Nautilus, use &#8220;File-&gt;Connect to server&#8230;&#8221; menu from there (not from the system menu), don&#8217;t enter user name in the dialog &#8211; leave it empty and enter it when you&#8217;re requested username and password in the next dialog.</p>
<p>When setting up WebDAV access rights, give access to user &#8220;redmine&#8221;.</p>
<p><strong>Setting Git repository copy for Redmine</strong></p>
<p>Create ~/.netrc for your redmine user on Dreamhost</p>
<p>Insert the following line in that file</p>
<pre>machine git.mydomain.com login redmine password [redmine_password]</pre>
<p>where redmine_password is the password you gave to user redmine in the previous step.<br />
.netrc will ensure that password is not asked when git is accessing the repository.<br />
You don&#8217;t need to bother about creating .netrc if you have a public repository (or at least available for cloning without password).</p>
<p><strong>Create a local copy of the repository</strong></p>
<p>For RedMine to be able to display Git repository, it needs to have a local clone of the repository.</p>
<pre>mkdir ~/git_project_clones
cd git_project_clones
git clone http://git.mydomain.com/repository_name</pre>
<p>Now you should have a local copy that can be used from RedMine.<br />
All you have left to do is to set up regular pulls from the master repository to this local copy. Use command</p>
<pre>crontab -e</pre>
<p>Add the following line to pull latest change into local copy every 5 minutes:</p>
<pre>*/5 * * * * cd /home/redmine_user/git_project_clones/repository_name &amp;&amp; /home/redmine_user/.packages/bin/git pull</pre>
<p>Make sure that you specify full path to git &#8211; otherwise it will execute Dreamhost default git 1.4.4.4 and command will fail with &#8220;refusing to create funny ref &#8216;remotes/origin/*&#8217; locally&#8221; error.</p>
<p>Save and exit cron editor.</p>
<p>(You might also want to check Redmine own wiki: <a href="http://www.redmine.org/wiki/redmine/HowTo_keep_in_sync_your_git_repository_for_redmine" target="_blank">http://www.redmine.org/wiki/redmine/HowTo_keep_in_sync_your_git_repository_for_redmine</a>)</p>
<p>Set repository in the settings of your project in RedMine: /home/redmine_user/git_project_clones/repository_name/.git</p>
<p>Now you need to manually update Git repository changesets in RedMine:</p>
<pre>cd ~/mydomain.com
script/runner "Repository.fetch_changesets" -e production</pre>
<p>And set a hook to your repository to do this every time repository is updated &#8211; edit ~/git_project_clones/repository_name/.git/hooks/post-update file and add the following command ther:</p>
<pre>cd /home/redmine_user/mydomain.com &amp;&amp; script/runner "Repository.fetch_changesets" -e production</pre>
<p>When writing this blogpost I found a lot of useful information on Dreamhost own wiki as well on these blog posts:<br />
<a href="http://www.wavethenavel.com/2008/09/08/bootstrapping-a-dreamhost-account-for-rails-and-git/" target="_blank"> http://www.wavethenavel.com/2008/09/08/bootstrapping-a-dreamhost-account-for-rails-and-git/</a><br />
<a href="http://juliobiason.net/2008/05/19/git-repositories-on-dreamhost-via-ssh/" target="_blank"> http://juliobiason.net/2008/05/19/git-repositories-on-dreamhost-via-ssh/</a><br />
<a href="http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/" target="_blank"> http://www.simonecarletti.com/blog/2009/07/configuring-git-repository-with-redmine/</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.ivankuznetsov.com%2F2009%2F07%2Fsetting-up-ruby-rails-git-and-redmine-on-dreamhost.html&amp;title=Setting%20up%20Ruby%2C%20Rails%2C%20Git%20and%20Redmine%20on%20Dreamhost" id="wpa2a_20"><img src="http://www.ivankuznetsov.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.ivankuznetsov.com/2009/07/setting-up-ruby-rails-git-and-redmine-on-dreamhost.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

