Use the Force, Unixuser42!

DISCLAIMER: Don’t get confused by the title. This post won’t teach you any advanced UNIX trickery stuff. If you’re expectation is such, you’ll be pissed after reading the article. You’ve been warned!

I had quite a laugh watching the Volkswagen Superbowl commercial, where this kid dressed up in Darth Vader Ccostume trying to control everything using the Force.

Then I got a (lame)idea! What if the powerful ‘sudo’ command in UNIX, which enables you to perform task as the superuser, was replaced by ‘force’! So you can type things like “force halt” in the terminal and shutdown the system. The Star Wars fan inside me got excited, and the Unix fan set out on a (very short)path to figure out how to achieve that.

The obvious way to do this is create to an alias for command ‘sudo’ and set it to ‘force’. Here’s how this can be done:

  1. Fire up your terminal program
  2. Move to your $HOME directory: cd ~/
  3. Open the .bash_profile file: vi .bash_profile (I’m on OS X. On other systems, like Ubuntu, this file will be .bashrc)
  4. Add this line to the end of the file and save: alias force=’sudo’
  5. Reload .bash_profile: source .bash_profile
  6. Try it: force reboot (System will reboot after authentication)

Don’t worry about ‘sudo’, you’ll still be able to use it. You didn’t exactly ‘replace’ sudo, you just gave it another name.

Also, it’s good idea to check if your system somehow already not using the ‘force’ command. (Type force in the shell to see whether it responds ‘command not found’ message.)

Installing Go on Ubuntu

When Google announced their newly developed system programming language Go, I decided to give it a try on my Ubuntu machine, the Mac would have to wait. The installation was supposed to be a walk in the park, but it wasn’t. I realized I didn’t have some other essential tools installed, and encountered one problem after another, frantically googling for solutions. So in this post I’ll detail the step by step process to install and run Go on your Ubuntu machine.

Step 1: Setting Up Environment Variables

Prior to installation you need to have these environment variables set up:

$GOROOT – The root of the Go tree. Typically this is $HOME/go but it can be any directory.

$GOOS – Name of the target operating system. Since this is Ubuntu the value would be ‘linux’

$GOARCH – Name of the target compilation architecture.  If you’re on a 32 bit x86 machine this would be ‘386’. Check out this section in Go online docs for other options.

$GOBIN – The location where binaries will be installed. You can set this to $HOME/bin or whatever path of your choice. Then you have to add this to your $PATH so that newly built Go-specific command such as the compiler can be found during the build.

Fire up the terminal and type the following command

sudo vi /etc/profile

This’ll open up the system-wide bash profile file in vi editor. You need to add the following lines at the end of the file.

export GOROOT=$HOME/go
export GOOS=linux
export GOARCH=386
export GOBIN=$HOME/bin

Now add $GOBIN to your $PATH. Open .bashrc in your $HOME directory

sudo vi $HOME/.bashrc

and add the line

export PATH=${PATH}:$GOBIN

Restart the machine for these changes to take effect.
Reload the files for the changes to take effect(thanks peter vahlu)

source /etc/profile
source ~/.bashrc

Step 2: Install Mercurial and clone Go repository

Google uses Mercurial to store Go source code, so you have to install it and fetch the repository.

Since 1.0, Mercurial has been installable by easy-install. So you need to get the python setuptools, header files and other essential  tools installed  first.

sudo apt-get install python-setuptools python-dev build-essential

Now install Mecurial

sudo easy_install -U mercurial

This part was quite confusing. Mercurial was throwing up some errors when I tried to clone Go’s repo.

*** failed to import extension hgext.hbisect: No module named hbisect

The extension bisect is a built-in command since version 1.0 and so should not be used. If you get this error, open the configuration file(/etc/mercurial/hgrc.d/hgext) and remove/comment out the line hbisect=

Make sure the $GOROOT directory does not exist or is empty. Then check out the repository:

hg clone -r release https://go.googlecode.com/hg/ $GOROOT

Step 3: Build Go from source

The Go tool chain is written in C. To build it, you need to have GCC, the standard C libraries, the parser generator Bison, make and the text editor ed installed.

sudo apt-get install bison gcc libc6-dev ed make

Next, build Go from source

cd $GOROOT/src

./all.bash

If all.bash runs without trouble, it’ll finish by printing

--- cd ../test

N known bugs; 0 unexpected bugs

Where N is the number of bugs, changes from release to release.

You now have GO installed on your Ubuntu. Happy coding!

Further Reading

  1. The installation page at Go website.
  2. Article on installing Mercurial on Ubuntu and dealing with its tantrums.

Deploying Rails Application on Apache with Phusion Passenger

facebookdc

This morning I put on my system admin hat at work once again. The challenge was to setup a Rails development environment on our production server at the cloud and then deploy a Rails application on Apache.

This article is not really a tutorial, although it’s posted under How-to category. It’s more like a log of my actions in carrying out this task; the problems I faced and what I did to get around them, so that I can trace them back if I ever partake a similar task in future.

Rails have several deployment options and Phusion Passenger a.k.a. Mod Rails is the principle of them. It supports both Apache and the lightweight Nginx Server. Check out there documentation page.

Here’s how it went

Logged into the remote server(CentOS 5.0) using ssh

Installed Rails

gem install -v=2.2.2 rails

Installed MySQL gem

gem install mysql — –with-mysql-include=/usr/include/mysql –with-mysql-lib=/usr/lib/mysql/

Installed Phusion Passenger

gem install passenger


Warning received. Required Software missing

Apache 2 development headers… not found

Installed Apache 2 Development Headers

yum install httpd-devel

Installed Apache module for Passenger

passenger-install-apache2-module

Configured Apache 2 to load the mod_passenger module by adding these lines in /etc/httpd/conf/httpd.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/bin/ruby

Uploaded a sample Rails App(myrailsapp) to /home

Added following lines in /etc/httpd/conf/httpd.conf to create a new virtual host

<VirtualHost *:80>
ServerName rails.myserver.com
DocumentRoot /home/myrailsapp/public
RailsEnv    development
</VirtualHost>

Restart Apache

service httpd restart

Went to http://rails.myserver.com.

Standard Error page for Phusion Passenger displayed. Instructed to consult Apache error log

Checked out the Apache Error Log

cat /etc/httpd/logs/error_log

The last error was

Rails requires RubyGems >= 1.3.1 (you have 1.2.0). Please `gem update –system` and try again.

Updated RubyGems

gem install rubygems-update
update_rubygems

Restarted Apache and went to http://rails.myserver.com again. The following error was showing on the page

no such file to load — sqlite3

Reason: SQLite3-Ruby Gem missing. Tried to install it

gem install sqlite3-ruby

Failed. The system doesn’t have SQLite3 installed

checking for sqlite3.h… no

Installed SQLite3 by building in from source

wget http://www.sqlite.org/sqlite-amalgamation-3.6.17.tar.gz
tar xvzf sqlite-amalgamation-3.6.17.tar.gz
cd sqlite-3.6.17
./configure
make
make install

Installed SQLite3-Ruby Gem

gem install sqlite3-ruby

Restarted Apache and visited http://rails.myserver.com

SUCCESS!

Accessing Linux file system from Windows

In a dual-boot system(one which has both Windows and Linux installed), Linux is smart enough to provide you access to Windows VFAT/NTFS partitions. But same is not the case for Windows.

Ext2 IFS is a free software(not open source) that allows you to do that. It installs a pure kernel mode file system driver Ext2fs.sys, which actually extends the Windows operating system to include the Ext2 file system. You can download it from http://www.fs-driver.org. The linux file system will appear as a new disk partition in windows.

If you install this software, I would recommend you to make the linux the drive read-only. Windows is susceptible to Virus/Worm/Trojan attacks. I didn’t want malicious files to spread in my Ubuntu partition.