Entries Tagged 'Ruby' ↓

Asset directories and capistrano

I have this public/images/cars directory but it gets overwritten everytime I use “cap deploy”. So in order to have my images/cars directory saved every time, I used this addon for capistrano:

set :assets, ['images/cars']

namespace :deploy do
  task :after_deploy do
    copy_assets
  end
end

namespace :deploy do
  desc "Link in the production database.yml"
  task :copy_assets do
  self.assets ||= []
    assets.each do |asset|
      run "cp -r #{previous_release}/public/#{asset} #{release_path}/public/#{asset}"
    end
  end
end

Worked like a charm for me!

Deploying, merb, capistrano & passenger

First of all I did a:

capify .

And used this deploy.rb

Then to setup the current, releases, etc. directories:

cap deploy:setup

Then, when I tried to login via ssh with shared key: nothing!
After some searching I found out that capistrano messed up the permissions on the .ssh directory :(

To fix it:

chmod 755 $HOME
chmod 755 $HOME/.ssh
chmod 644 $HOME/.ssh/authorized_keys

Installing merb on phusion passenger


I’ve created a little merb app for a customer. The reason I chose merb because I really like the :provides-api. The app had to generate a lot of xml, so using Merb was really nice.

But the installation on the server was a little troublesome. I had to install some gems (which I of course forgot to do) and I had to figure out how the file permissions had to be.

First step: installing software

aptitude install build-essential ruby1.8-dev libxml2-dev libmysql++-dev
gem install merb datamapper do_mysql merb_datamapper --include-dependencies --no-ri --no-rdoc
gem update --include-dependencies
passenger-install-apache2-module

Step two: project’s dependency packages

aptitude install libmagick9-dev libtidy-0.99-0
gem install orderedhash shared-mime-info rmagick tidy

But the big problem here was libtidy! All the packages keep segfaulting. So I had to use the Gutsy or Feisty package (don’t remember which one exactly. One of the two :) ).

Step three: config.ru

Because I wanted to run Merb on apache2 with Phusion passenger I had to create a config.ru file. The contents of the file can be found on the merbivore wiki.

Last step: Adjusting permissions

I was ready to start merb, but when I tried to start it, it kept complaining about permission errors. So after a little fiddling I chmod’ed the whole shebang to 750. I think it will be solved if I install suexec on the server.

Just some stuff

Just some quick links!

This links describes how to manage multiple databases with Capistrano. That’s not why I picked it though. I liked it because it shows the “<<: *” syntax of yaml.

And a repository of Ubuntu Hardy Heron debs for mod_rails/Phusion passenger. At this time I installed mod_rails via rubygems. But if the guys at brighbox make the package so it builds/installs the Apache module automatically (without human intervention and pressing Y two times) I will install that one. Much, much nicer to use with Puppet.

Installed passenger a.k.a. mod_rails


Today I’ve installed Phusion passenger on one of our servers. I wanted Redmine for one of our projects so this seemede a nice opportunity to install it.

Installation was a breeze. For mod_rails as well Redmine.

So I was thinking: we have mod_rails installed, we could offer some rails hosting to attract new customers.

But I see three bears on the road with using mod_rails in a shared hosting environment.

1. Same user

Every mod_rails site runs on the same user :( I’ve spent hours on configuring fastcgi and suexec. But now every hosting custommer’s scripts run under their own user. Would be nice if mod_rails supported something like that.

2. Memory

I couldn’t find an option to limit the memory usage per mod_rails site. And I know how memory hungry rails can be :(

3. Aliases

Mod_rails doesn’t support host aliases. This is overcomable but feels like a hack. Wouldn’t it be nice if mod_rails supported aliases :) Pleeeeeeaaaaase?

Maybe I haven’t read the documentation to well and are my points useless :) In that case: please let me know!

Installing ruby 1.8.7 (and guessnet) on Hardy

There were some vulnerabilities in Ruby which are supposedly fixed in ruby 1.8.7. Because of that and because it’s always nice to have the latest, I installed ruby from Ubuntu Intrepid on Hardy Herron.

And while I was doing that I also decided to install guessnet from Intrepid. So I don’t have to compile guessnet anymore.

It involves two steps:

  1. Updating you apt sources
  2. Making sure only ruby and guessnet are going to be installed from the new sources. Not all the packages!

1. Updating your sources

Create /etc/apt/sources.list.d/intrepid.list and copy the following code into it:

deb http://nl.archive.ubuntu.com/ubuntu/ intrepid main restricted multiverse
deb-src http://nl.archive.ubuntu.com/ubuntu/ intrepid main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://nl.archive.ubuntu.com/ubuntu/ intrepid-updates main restricted multiverse
deb-src http://nl.archive.ubuntu.com/ubuntu/ intrepid-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://nl.archive.ubuntu.com/ubuntu/ intrepid universe
deb-src http://nl.archive.ubuntu.com/ubuntu/ intrepid universe
deb http://nl.archive.ubuntu.com/ubuntu/ intrepid-updates universe
deb-src http://nl.archive.ubuntu.com/ubuntu/ intrepid-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://nl.archive.ubuntu.com/ubuntu/ intrepid-backports main restricted universe multiverse
# deb-src http://nl.archive.ubuntu.com/ubuntu/ intrepid-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository. This software is not part of Ubuntu, but is
## offered by Canonical and the respective vendors as a service to Ubuntu
## users.
deb http://archive.canonical.com/ubuntu intrepid partner
# deb-src http://archive.canonical.com/ubuntu intrepid partner

deb http://security.ubuntu.com/ubuntu intrepid-security main restricted multiverse
deb-src http://security.ubuntu.com/ubuntu intrepid-security main restricted
deb http://security.ubuntu.com/ubuntu intrepid-security universe
deb-src http://security.ubuntu.com/ubuntu intrepid-security universe

2. Apt preferences

If /etc/apt/preferences does not exist, touch it!

Then copy this code into it:

Package: *
Pin: release v=8.10
Pin-Priority: -1
Package: ruby
Pin: release v=8.10
Pin-Priority: 500

Package: ruby1.8
Pin: release v=8.10
Pin-Priority: 500

Package: libruby
Pin: release v=8.10
Pin-Priority: 500

Package: libruby1.8
Pin: release v=8.10
Pin-Priority: 500

Package: rdoc
Pin: release v=8.10
Pin-Priority: 500

Package: rdoc1.8
Pin: release v=8.10
Pin-Priority: 500

Package: ri
Pin: release v=8.10
Pin-Priority: 500

Package: ri1.8
Pin: release v=8.10
Pin-Priority: 500

Package: irb
Pin: release v=8.10
Pin-Priority: 500

Package: irb1.8
Pin: release v=8.10
Pin-Priority: 500

Package: libopenssl-ruby
Pin: release v=8.10
Pin-Priority: 500

Package: libreadline-ruby
Pin: release v=8.10
Pin-Priority: 500

Package: libreadline-ruby1.8
Pin: release v=8.10
Pin-Priority: 500

Package: ruby-dev
Pin: release v=8.10
Pin-Priority: 500

Package: ruby1.8-dev
Pin: release v=8.10
Pin-Priority: 500
Package: guessnet
Pin: release v=8.10
Pin-Priority: 501

That’s all! “Aptitude update” & “aptitude install ruby guessnet” and you are good to go.

I tried using the “Package” keyword with wildcards, but that’s a no-go :(

Puppet troubles

I’ve installed puppet recently and I’m know trying to understand how it works and make use of it :)

If that’s not difficult enough, I encountered this weird behaviour that the –noop argument didn’t do anything. After an hour of searching I realized it was my own stupid fault!

I had to puppet configuration files: /etc/puppet/puppetd.conf (old way) and /etc/puppet/puppet.conf (new way). I browsed throught the source code and it looks like puppet first checks the old file, if it is found it parses that one. If it’s not found, the new file is parsed. I don’t know why, but if the old file is used, the –noop argument isn’t parsed by puppet. So removing /etc/puppet/puppetd.conf was all I had to do. Pffff….

But why did I create the puppetd.conf file? Because I’v read the “Pulling strings with puppet”-book. And althought it’s fairly new, puppet is advancing at a very high rate. So the book is becoming out-of-date already.

Released callbacks 0.0.1

Hi all! I’ve released my first project on rubyforge. The sourcecode is on github though. For theĀ  simple reason that my git repository on rubyforge doesn’t work (yet). I hope they will fix it soon.

I’ve setup the project with the wonderful bones of Tim Pease.

I’ve got some reasonable documentation about it, a kick-ass website (stolen from Dr. Nic’s newgem) and some nice unit tests. I’m now integrating the gem in one of my own projects. If that’s succesfull I’m gonna release a version 0.1. The version after 0.1 will have new features.

The website ws generated with webby. A really nice way to create static websites in ruby. Maybe I’ll dedicate a post/tutorial to webby.

So please look at the website, install the gem and give me some feedback. It will be very appreciated!

Interactive/inline editor in irb

I saw the MountainWest Ruby conference video: code generation: safety scissors of metaprogramming. And the speaker (Giles Bowkett) used vi from inside irb. And I’ve never liked Vi, but using an editor from within irb is nice! Especially if you’re testing a big chunk of code.

So I began crawling the Internet for how he did this and I found the utility_belt gem. The utility belt contains the file I needed. So I installed the gem, edited my .irbrc and now I can use nano/gedit (or any other editor) from withing IRB!

These were the steps:

gem install utility_belt

My .irbrc:

require 'utility_belt/interactive_editor'
module InteractiveEditing
def nano
edit_interactively(:nano)
end
end

Now to use nano in irb, just type: nano

And the bonus: a nice screencast that shows this feature in action. I tried to edit it with pitivi. But that really sucked. After I finally found it out how I could cut pieces I tried to save it and the whole program crashed. “apt-get remove pitivi”!

Up to date on GIT

GithubI’ve been using GIT now some weeks (for my ultra-secret ruby project) and I must say it’s nice. Nothing more than nice. Just like svn was nice to use (compared to old-school full backups). When I first saw the GIT commands I was dazzling with confusion. But after two days you get the hang of it. I haven’t done anything special like branching so I can’t tell you about the advanced features. But the base is solid.

Ow, and github is really nice. I read somewhere that rubyforge now has git support too. Gonna check that out. But beating github will be difficult. Well, at least for now when Github is still free of charge!