Initial Ubuntu 8.04 Linux Setup 1

Posted by John Sun, 11 May 2008 20:53:00 GMT

After grabbing and installing Ubuntu 8.04 I then had to put together and setup the baby, luckily I wrote down most of everything I did in case I’d have to do it again and to help out you guys.

What follows are my findings and what I did to fix them. The machine I used is an HP Pavillion dv2000 model dv2742 special edition. It’s got a built-in intel graphics card, 3gb memory, sata 250gb drive, wifi, bluetooth and an intel dual core 2 processor.

I installed the o/s using the 64-bit edition of Ubuntu 8.04 Hardy Heron, all what you see below are workable settings which provided the right setup; hope they help your situation if you go down this route.

Update System

First port of call, check for any new updates post-install,

sudo aptitude update
sudo aptitude upgrade

Dependencies / Software / Setup

Next, install Ruby, FlashPlayer, GCC Compiler, MySQL, JAVA, SqlLite,

sudo aptitude install mysql-server flashplugin-nonfree ruby-full libsqlite3-dev build-essential libmysqlclient15-dev sun-java6-jdk

Volume Mixer,

sudo aptitude install gnome-alsamixer

ImageMagick,

sudo aptitude install imagemagick

Ruby Gem Handler

I could get GEM from the repositories but because with each new update it breaks away from the in-built Linux installer it’s best to install it from source,

wget http://rubyforge.org/frs/download.php/34638/rubygems-1.1.0.tgz 
tar xzvf rubygems-1.1.0.tgz
cd rubygems-1.1.0
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Had problems updating the GEM system initally, so logged in as root to finish it off,

su root 
sudo gem update --system

Now when you type gem –version you should see GEM ready to roll,

Gem Libraries

The slow bit, ran this as root just to make sure it worked,

gem install rails
gem install rake
gem install mongrel
gem install mongrel_cluster
gem install thin
gem install capistrano
gem install mysql
gem install termios
gem install sqlite3-ruby
gem install mini_magick

VLC + GIT

Next VLC to play videos,

sudo aptitude install vlc

Transmission for torrents, most important bit,

sudo aptitude install transmission

And GIT to handle code versioning,

sudo aptitude install git-core

Firefox + MS Fonts

Next I need Firebug for Firefox 3. Ubuntu 8.04 comes with Firefox 3 beta 5, the one available thru Tools / Add-ons won’t work with it; but thankfully it’s in the repositories

sudo aptitude install firebug

And you’ll probably need Microsoft Fonts later down the line,

sudo aptitude install msttcorefonts

Pimp GEDIT

The default Gnome Text Editor Isn’t bad but let’s add some extra’s to really kick it in gear,

sudo aptitude install gedit-plugins

And tweak it,

wget http://robzon.kapati.net/rails/rhtml.lang && sudo mv rhtml.lang /usr/share/gtksourceview-2.0/language-specs/
wget http://robzon.kapati.net/rails/rails.xml && sudo mv rails.xml /usr/share/mime/packages
sudo update-mime-database /usr/share/mime

Follow the guide here to get the TextMate look,

Now when you open rails source files they’ll actually look right, thanks Grigio.

PostGreSql + Thunderbird

Pretty easy to install the most powerful db system, and the better email handler

sudo aptitude install postgresql thunderbird

Wine for Windows

Thanks to Google for their support the Wine project is going great, to get Windows software running natively on your machine,

First add the key,

wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -

Then add the repository to your default repository list,

sudo wget http://wine.budgetdedicated.com/apt/sources.list.d/hardy.list -O /etc/apt/sources.list.d/winehq.list

And finally install it,

sudo apt-get install wine

Effects

To enable compiz effects make sure Appearance / Visual Effects is set to ‘Extra’, then install the Advanced Effects Manager,

sudo aptitude install compizconfig-settings-manager

This will give you access to the 3d cube, skydome effect and a host of other cool addons.

My desktop dpi is set to 100dpi, fonts set to ‘Bitstream Vera Sans Roman 8pt’, with ‘Bitstream Vera Sans Bold 8pt’ for Windows Title; and ‘Liberation Mono 8pt’ for fixed width font. Using subpixel smoothing for LCD.

Sound

For my laptop (hp pavillion dv2000 / dv2742se model), i had to use a different sound mixer to make sure the quickplay volume and mute buttons talked to the sound system.

So from the top menu bar, System / Preferences / Sounds, then set the Default Mixer Tracks hander device to: Conexant CX20561 (hermosa) (oss mixer).

Cleanup

To get any temp files carried on from the install, clean with,

sudo aptitude clean

Job done, however I had a problem with Hibernate & Suspend which was lucky fixed with some advice from here

Record Grouping

Posted by John Tue, 01 Apr 2008 22:05:00 GMT

Example to go thru your User model and return all the signups by month / year, doing conditionals on them and grouping,

@users = User.find(
  :all, 
  :select => "MONTH(created_at) as month, YEAR(created_at) as year, COUNT(*) AS records",
  :conditions => ["admin = 0'"], 
  :group => "year, month")

You can use this in your view like,

<% for @user in @users %>
  <%=@user.month%>
  <%=@user.year%>
  <%=@user.records%> signups
<% end %>

Ruby date_select conversion 2

Posted by John Wed, 19 Mar 2008 20:26:00 GMT

Had a bit of a pain with Ruby’s handling of Date/Time values coming from a Date_Select form element, managed to solve it though.

The problem was that in my form…

<%=date_select(:date,'',:start_year => 1950,:include_blank => false, :default => { :year => '1970' })%>

…the value I got back from the submitted field,

params[:date]

became…

'(3i)4(1i)1953(2i)5'

Bit of a mess, obviously I was expecting something a little more legible like 1953-5-4 (yyyy-mm-dd), so I bashed my head against a brick wall trying to work it out, I could have made my life easier with some select_date blocks but I’m a guy how likes to ask ‘why’ so I perceviered.

Turns out in my travels you can do this to break it into a usable DateTime object..

Time.mktime(params[:date]['(1i)'],params[:date]['(2i)'],params[:date]['(3i)'])

Which will return something much more legible…

Sun May 19 00:00:00 +0100 1968

Or whip it into a method to do exactly what you want…

def convert_date(obj)
  return "#{obj['(1i)']}-#{obj['(2i)']}-#{obj['(2i)']}"
end

<%=convert_date(params[:date])%>

But wait, it doesn’t end there, you could use Date.new or Date.civil to parse it into a real date object like…

def convert_date(obj)
  return Date.new(obj['(1i)'].to_i,obj['(2i)'].to_i,obj['(3i)'].to_i)    
end

Which will return…

1967-03-19

Much nicer, just remember to use .to_i otherwise you’ll get…

comparison of String with 0 failed

Enjoy!

Building a 1U Server, Part 3

Posted by John Mon, 17 Mar 2008 15:53:00 GMT

server

System Config

While the final bits arrive for my new server project I might as well put pen to paper on how the server’s O/S will be laid out.

The operating system I’m rooting for this time around will be Linux, purely for the flexibility and the stability; the hardware I’ll have to run thru it’s paces with a CPU testing tool to make sure i’ve not got a faulty chip along with some brute-force testing on the memory chips, it’s going in co-location so I might as well do it as I don’t want to drive down to the site everytime it falls over.

I’ll be using SSH obviously to connect to it along with a strong keychain to make my logging in easier and the connection encrypted.

I’ve got a strong iptables config so will put that into play with a custom port for SSH, not the usual port 22 which is standard; the more things you put in the way of potential hackers the better.

And no, I won’t be logging in as root, only if I absolutely have to.

System Layout

This is the tricky bit, working out how you’re going to lay the system out and run the various services; there really isn’t any good answer, no one solution will fit everything.

For me I’ve decided to use XEN virtualisation to segregate my services out so each one remains separate, not all my eggs in one basket.

So I plan to use XEN and ArchLinux to handle each server stack, e.g.

  • Database Server (MySQL / PostGreSql / Sqlite)
  • PHP Server (Lighttpd + PHP5)
  • Rails Server (Nginx, Thin, Ruby on Rails 2.0)
  • Caching Server (Memcache, or some kind of custom Content Delivery Network)

I haven’t nailed down the particular distro of Linux for the core o/s but will be using ArchLinux to handle the ‘baby’ boxes, the controlling ‘big-daddy’ may either be Fedora or again ArchLinux.

Now this may sound like overkill, but it does make sense, as it’ll allows me to custom-build each Server based on it’s proposed use and with ArchLinux I can make sure no extra baggage is added with unneccesary features and services; tuning it to the maximum performance.

It also allows me to do image backups in the future of each server so I can take snapshots of each one, in case I need to restore any at a certain point in time (say a bad update).

ArchLinux?

I’ve grown to enjoy ArchLinux, mainly for it’s neatness and light feature stack, but also because it has no set release number. Unlike other distro’s there is no frozen release 7 or 8, you go with the latest core files and that’s what you’ve got; taking the pressure out of always being on-top.

Also the package manager is a little more powerful and because you only install what you need you don’t end up with tons of extra software you never even use. Rolling in at a 160mb ISO build compared to 4.4GB for your average Ubuntu or Fedora you know you’re only getting the bare-bones.

As Judd Vinet, the founder of the Arch Linux project said: “It (Arch Linux) is what you make it.”

Don’t get me wrong, I’m not trying to bash any of the other distro’s but as you can imagine with this particular project I have to keep things lean so I can maximise power and alleviate future problems when trying to identify awol services.

Final Notes

It’s going to be a lot of work and probably a pain in the rear to put together but I’ve done this long enough with SliceHost and Virtual Hosting so I think I’ve cut my teeth long enough to do this for real.

Keep you posted how the build goes.

Rails Sessions

Posted by John Sun, 09 Mar 2008 22:29:00 GMT

rails is love

To make a truly intelligent web application your gonna sooner or later have to play around with Sessions, which is basically a Cookie’s big brother.

Store in DB

Now Rails initally will store all it’s session data in a text file within the /tmp/sessions directory of your rails app, which is usually ok, but if you’re gonna build a production-ready app you’re gonna want to up the ante somewhat and store them in your DB.

This is simply done by opening up your environment.rb file and un-commenting the following line…

(within /config/environment.rb)
config.action_controller.session_store = :active_record_store

Then in the command-line generate a RAKE DB migration for your Session objects (so they’re stored in your db from now on).

rake db:sessions:create
rake db:migrate

Bingo, you now have a table within your database hooked up and ready to store your session data perfectly.

Storing Session Objects

Now that you’ve got your DB storing your session data, why don’t we start creating some session objects.

This is done by…

session[:order] = 'ASC'

Here, we’ve simply created a new session object, storing in it a text value of ‘ASC’; cool eh?

We can then check to see if our session is empty via…

if session[:order].blank?
   ..do stuff..

So if our session object contains nothing we can initialise it correctly.

Common Gotcha

Now one of the good things with switching sessions over to your db is that it’ll secure your app a little bit better and your performance will improve.

Plus if your building your app on your dev machine, then transfer it to your live box, but can’t find a reason why your sessions don’t work there it’s usually down to file permissions for the session file; by switching sessions over to a db you remove any future problem of this.

Good eh,

Older posts: 1 2 3 ... 7