Deploy Ruby on Rails applications using Rake

So you are a Rails developer (or just starting to test Rails), and you would like to find an easy way to deploy a new version of your web application to your production machine, just uploading the files you have changed, and not the entire project.

Rake is Ruby's version of Make, and uses Rakefiles (clever, huh?). You can use Ruby to make your own Makefiles. We can then use Rake to deploy our application.

You will need the rsync client (you don't need the server) installed in your destination server. Otherwise, the process will fail.

Create a new file, named deploy.rake in lib/tasks/, containing the following code:

task :deploy => :environment do
  puts "Deploying to server"
  system("rsync -rltvz -e ssh app public root@server:/var/www/webapp/")
  system("ssh root@server chown -R www-data:www-data /var/www/webapp/")
  system("ssh root@server /etc/init.d/apache2 reload")
end


This will sync both app/ and public/ directories (the application itself, images and stylesheets), but you can add as much directories as you need. The second line changes the permissions to the user that runs the web server, and the third, as you may see, reloads Apache to force the server to refresh the controllers.

And what if you have several servers where to deploy? We can use some Ruby style loops:

task :deploy => :environment do
  servers = %w{server1.domain server2.domain server3.domain}
  servers.each do |server|
    puts "Deploying app to #{server}"
    system("rsync -rltvz -e ssh app public root@#{server}:/var/www/webapp/")
    system("ssh root@#{server} chown -R www-data:www-data /var/www/webapp/")
    system("ssh root@server /etc/init.d/apache2 reload")
  end
end


Now, in your main application directory, just run rake deploy and the remote host will be synced with your local application.

Still, if you don't have already enabled key authentication for your ssh account, you will be asked for a password each time you deploy your application.

If you want to do this process without having to enter your password, you can generate your own authentication key:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/daniel/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/daniel/.ssh/id_rsa.
Your public key has been saved in /home/daniel/.ssh/id_rsa.pub.
The key fingerprint is:
e3:c6:4d:88:c0:75:7b:2a:65:52:91:19:b4:99:e1:8f daniel@client

If you don't specify a password, you won't need to enter it to unlock the private key. It is safe to leave it blank, but don't let anyone get to your id_rsa private key, or they will be able to log in to your servers.

The public key is contained in .ssh/id_rsa.pub. This is the key you have to upload to your servers.

$ scp .ssh/id_rsa.pub root@server:
root@server's password:
id_rsa.pub                                                           100%  233     0.2KB/s   00:00   

Log in now to your server as the user you want to have authorized, and copy the public key to the authorized_keys file:
# cat id_rsa.pub >> .ssh/authorized_keys



 

iPhone Launch minus two days

Only two days remain for the official launch of the iPhone. Lucky Americans will be able to buy it on Friday, and we Europeans will have to wait a couple of months, or get a flight to NYC.

Everyone is talking about the iPhone. On the Internet and in the streets. People either hate it or love it, but they talk about it anyway. And there is no such thing as bad publicity. Even when John "Insane" Dvorak talks about the iPhone, comparing it to Hitler's invasion of Poland, the iPhone expectation seems to increase.

Since its introduction in January, there hasn't been a month where we haven't talked about the iPhone. Whether were new features, praises or criticisms, every iPhone movement was always commented on blogs, traditional newspapers and TV.

The iPhone is probably the most awaited and sought-after product in history. I can't recall any other product that has had such a superb marketing campaign.

For instance, I own a Nokia 8800, probably one of the nicest but least featured phones out there, and I've never owned a multimedia or internet-enabled phone, except for a couple of Blackberries, which I eventually stopped using because receiving mails instantly finally bothered me.

Additionally, I find phones like the Nokia NSeries completely useless. I mean, I don't need a 5-megapixel camera in a phone, the internet capabilities of those phones are pointless, and the software is rubbish.

But the iPhone is different. A full featured internet device, with an amazing software and interface I want to get my hands on as soon as possible. And it has an Apple logo!

So two days before the introduction of the iPhone, reviews are starting to come in. One of the best ones so far has been the one by David Pogue, from the New York Times.


America's favourite scotsman (excepting Sean Connery, I guess), Craig Ferguson, interviewed Henry Winkler about the iPhone. The following excerpt of the conversation summarizes the publicity the iPhone has had over the months.

Craig: Is the iPhone as great as they say?
Henry Winkler: I have a beautiful wife, I have amazing children, I have health. I would sell everything for that iPhone.
Craig: That's quite an endorsement. Have you tested an iPhone.
Henry: No, I have seen a picture of it, though. It looks amazing!



 

Testing Nexenta (GNUSolaris, Elatte) in Parallels

Nexenta is a GNU/Solaris distribution, built on top of the OpenSolaris kernel, licensed by Sun. The distribution is based in Debian, and already worked quite well when I tested it more than a year ago, using the LiveCD. It has improved since, and now has ZFS support, so I decided to give it another try.

The installation does not work using an ISO image in Parallels. It will crash after the Loading Nexenta message, restarting the installation constantly.



I recorded it to a rewritable DVD and voilà!




The installation is similar to a non-graphical Linux one, like Debian. If you don't want any special partition layout, you can pretty much let it install by default.





You can play with the extremely difficult bundled Tetris while the installation finishes. Note the message at the right: Won't give you this one. Damn!




After installation, the X Window System starts but the resolution is somehow wrong, and you can't see a thing. And you can't change to non-graphical interface either.

I solved this by doing a nmap sweep of the network assigned by Parallels. In my case:

$ nmap -v -v 10.211.55.0/24

Discovered 2 hosts. One is the Mac host, and the other is Nexenta.


Scanning 2 hosts [1697 ports/host]
Host 10.211.55.2 appears to be up ... good.
Host 10.211.55.4 appears to be up ... good.

Luckily Nexenta enabled sshd by default. And a Samba server?

Interesting ports on 10.211.55.4:
Not shown: 1690 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
111/tcp open rpcbind
139/tcp open netbios-ssn
445/tcp open microsoft-ds
587/tcp open submission
4045/tcp open lockd

Log in using the user created during the installation.

$ ssh daniel@10.211.55.4

daniel@solaris:~$ uname -a
SunOS solaris 5.11 NexentaOS_20070402 i86pc i386 i86pc Solaris

Edit /etc/X11/xorg.conf to fix the X Window Server:

Remove wacom drivers (those in InputDevice). And be sure to remove the includes at the bottom (ServerLayout).

For the mouse to work, remove the Protocol line, and the CorePointer option, if present. Leave it this way:

Section "InputDevice"
Identifier "Configured Mouse"
Driver "mouse"
Option "Device" "/dev/mouse"
EndSection

Vesa works nicely in Parallels. Leave Monitor default.

Section "Device"
Identifier "Generic Video Card"
Driver "vesa"
BusID "PCI:0:2:0"
EndSection

Screen looks like this:

Section "Screen"
Identifier "Default Screen"
Device "Generic Video Card"
Monitor "Generic Monitor"
DefaultDepth 16
SubSection "Display"
Depth 16
Modes "1024x768" "800x600" "640x480"
EndSubSection
SubSection "Display"
Depth 24
Modes "1024x768" "800x600" "640x480"
EndSubSection
EndSection

This is what ServerLayout should contain:

 
Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen"
InputDevice "Generic Keyboard"
InputDevice "Configured Mouse"
EndSection


Kill gdm to restart:

root@solaris:/etc/X11# ps -Af |grep gdmgreeter

    root  3256   673   0 23:32:47 pts/1        0:00 grep gdmgreeter
    gdm  3246  3236   2 23:32:00 ?            0:02 /usr/lib/gdm/gdmgreeter

root@solaris:/etc/X11# kill -9 3246

And we are in.




ZFS. Yay!

root@solaris:/export/home/daniel# zfs list
NAME USED AVAIL REFER MOUNTPOINT
home 36.3M 22.4G 36.2M /export/home
root@solaris:/export/home/daniel# df -h
Filesystem size used avail capacity Mounted on
/dev/dsk/c0d0s0 7.9G 1.8G 6.0G 24% /
/devices 0K 0K 0K 0% /devices
/dev 0K 0K 0K 0% /dev
ctfs 0K 0K 0K 0% /system/contract
proc 0K 0K 0K 0% /proc
mnttab 0K 0K 0K 0% /etc/mnttab
swap 409M 588K 408M 1% /etc/svc/volatile
objfs 0K 0K 0K 0% /system/object
/usr/lib/libc/libc_hwcap1.so.1
7.9G 1.8G 6.0G 24% /lib/libc.so.1
fd 0K 0K 0K 0% /dev/fd
swap 408M 12K 408M 1% /tmp
swap 408M 164K 408M 1% /var/run
home 22G 36M 22G 1% /export/home



 

Analysing the Spanish Congress IT budget

The Spanish Congress of the Deputies (ES: Congreso de los Diputados) approved a budget for the design of a new web site and the renewal of the computers in the building. The total cost is 14.304.113 €, between 2006 and 2007. The official document can be found here (in Spanish): BOE n.278

Yes, that's 14 million, divided into four sections:
  • Computer systems and other services: 4.264.840 €
  • General-purpose computers: 3.613.848 €
  • Technical assistance and maintenance: 1.017.750 €
  • Consulting: 5.407.675 €
While the third and fourth section are difficult to calculate (maintenance and consulting), the first two should be easy. Let's see what are they spending our money in.

Part One. 4.264.840 €

Five servers: One database server, two application servers, one web server, and one development server, all of them complying the following specs: 4xPower-5 (up to 12) CPUs, 16GB of RAM (up to 32), 4 hot-swappable 73GB disks, with RAID support, including an AIX license.

Let's see, a database server, a web server, and two application servers, for a site with a 90987 Alexa rank.

That's nice. They should be able to use the spare cycles on those machines to fold proteins or something. I know sites with 4 or 5 times more hits hosted on shared servers for 10€/month.

Firewall: Two Dual Intel Xeon 3GHz, 2GB of RAM, RAID 36GB, 4 Gigabit Ethernet interfaces.

Nice Firewall indeed. Let's use it for SETI@home this time.

SAN: 48TB, up to 80TB. 2 Fibre-Channel switches with 32 ports each.

SMS Server: Same as above, Windows 2003 Server + SMS + SQL Server.

Licenses: Windows 2003 Server, Oracle 10g, SQL Server.

Streaming Servers:
Intel 3GHz, 2 GB RAM, Disks: 2x36 GB, 50x300 GB
Intel 3GHz, 2 GB RAM, Disks: 2x36 GB, 50x250 GB

Tape Server: 35 TB (up to ~100TB)

Streaming WS: 14 x Intel Xeon 2,8 GHz, 512 Mb RAM, 73 Gb disk, Windows XP.

And what does all this computing power give them? According to the following article (in Spanish, but you can see the screenshots): ¿Qué pasa con la web del Congreso de los Diputados?, the site even has the default Oracle pages left on. They must have thought: well, we already have a Dual Intel Xeon firewall. We are secured.

Not only that, but this is a screenshot of the web right now. Besides the poor cross-navigator design, they don't even check the SQL queries are correct before submitting them to the database, leaving the Oracle error lying around the right side of the page.




Apparently the site was designed by Telefonica, the spanish ex-monopoly for telecommunications, and they feature the site as a successful case (in Spanish). They should feature Terra as a success too.

Part Two: 3.613.848 €

After seeing the computing power they use to power their web servers, they must have bought  a 17-inch MacBookPro and a 24-inch iMac for each deputy, right? Not really. Isn't it better to buy the cheapest computers, and get the rest of the money for themselves?

This is a relatively easy section to calculate, so let's see how much we would have to spend to buy the following components:
  • Workstations: 620 x Pentium-4, 1GB of RAM, 60GB disk, Win XP, MS Office, with 17-inch screens.
  • Printers: 400 x BW Laser printers. 75 x Color Laser printers.
  • Scanners: 50 x Automatic feeder scanners.
  • Laptops: 30 x Pentium-M 2GHz, 1GB of RAM, 60GB disk, 15-inch monitor
  • PDA's: 400 x PocketPC
  • Network: 40 x Switches, Routers, etc.
The workstations should cost at most 1000€, with a total sum of 620000€.
The printers should cost about 1500€ the BW ones, and 2500€ the Color ones, with a total sum of 787500€.
The scanners, let's say, a very expensive one, may go around 1000€, with a total of 50000€.
The laptops should cost no more than 1000€, making it 30000€.
The PDA's should go about 500€, totalling 200000€.

Without counting the undefined "40 network elements", this makes 1687500€, 1926348€ less than the total sum, which means, even if the network elements cost 500000€, the socialists are getting for themselves just in this section, about 1.5 million.



 

My 9 must-have applications for Mac

Lately, particularly since the introduction of the Intel-based iMacs and MacBooks, lots of friends and colleagues have bought their first Mac, most of them coming from Windows, and some of them, from Linux.

Being the long-time Mac user (since the days of Puma) I am, teasing them with Exposé and Keynote transitions when Redmond hadn't still turned on the Photocopiers, I usually get questions about the applications I use for Mac, and whether there exists a Mac app equivalent to a certain Win app.

So, here is my must-have applications list for Mac:

1. TextMate: The best editor EVER. Really. Whether it's Rails, LaTeX or a shell script, TextMate is for you. It's €39, but well worth it.

2. VLC: A multi-format video player. For Mac, Linux, and Windows. But in the Mac is even nicer, and you can even use your Apple Remote to control it.

3. CocoaMySQL: A graphical MySQL client, with Mac looks. Perfect for development.

4. Camino: Although I prefer Safari, Camino is useful if you need a Firefox-based browser for web development testing. It's much lighter and faster than its bulky cousin. It doesn't support Extensions, though.

5. iTerm: While we wait for Leopard, iTerm is a Terminal replacement, with tabs.

6. The Unarchiver: An all-format decompressor (including Zip, RAR, StuffIt, gzip and bzip, among others). It automatically decompresses a file with a double click, integrating seamlessly with the Finder, without annoying windows popping out, and it's faster than pricey StuffIt. You install it, and forget about it.

7. Transmit: A FTP/SFTP/WebDAV client, with a nice interface, developed by the Panic blokes. Worth the $29.95 if you use FTP a lot.

8. Visor: A scrolling Terminal (Quake-alike, they say) a key combination away. I find it useful, for instance, to leave a mongrel running there, without closing it accidentally.

9. Transmission: A GUI BitTorrent client. It's up to you if you download the last 24 episode or a Linux ISO ;)

And, of course, the rest of the applications that already come bundled with MacOS: Mail, iChat (using Google Talk), iTunes, Keynote (not bundled, but quite cheap, and comes with Pages, too).                        



 

News from the Apple WWDC 2007

I have been following this afternoon Steve Jobs' Keynote at the Moscone Center in San Francisco on MacRumors and Engadget. They did a pretty good job reporting almost immediately with both text and images of the keynote.

Steve informed us about several new Leopard features, none of which is the inclusion of ZFS as the default filesystem. Yes, i know... damn!

One of the first features is an enhanced Dock, with something called Stacks, which will hold whatever files you want, enabling easy access to them. Nice. There's a screencast at the Leopard site.



The Finder has been upgraded too, and it sports an iTunes-like interface, even with CoverFlow. Even more, you can press space on almost any file and it will automatically preview, without opening any application.



Using iChat, we will be able to bring up a Keynote presentation, as well as those PhotoBooth-esque effects we had already seen. Phil Schiller said "I love my Mac!" with Steve Ballmer's head. He, he.

Steve also announced the official price of Leopard: "We've got a basic version that will cost $129, we've got a Premium Version which will cost $129. We've got a business version! $129. Ultimate version! We're throwing everything into it, it's $129. We think everyone's going to buy the ultimate version."

One of the big announcements of the Keynote, Safari 3 for Mac AND Windows. And it's already available. Grab your copy now for free in the Safari site.

I have already tested it, and has a couple of nice features I have discovered so far. For starters, if you have several opened tabs, and you accidentally close Safari, it will ask you whether you really want to close it.

Search no longer opens a new window where you type the text. Instead, a nice search bar scrolls down the tab bar, and the search text is highlighted on the page.



You can now also organise tabs, just clicking and dropping the tab where you want it. You can also open a new window dragging a tab outside Safari.

iPhone news: applications for iPhone will be web-based Ajax apps, so anyone able to develop web applications will be able to develop for the iPhone. They showed a LDAP-based directory application as an example.



 

Jericho: We have enough nuts, thank you

Remember when I told you that the Jericho cancellation by CBS (Nuts for Jericho) had united fans all over the world?

People were signing online petitions, calling the CBS offices and sending mail. They even were sending nuts, in a tribute to Jake Green's (one of the main characters) last words on the show.

Well, I guess all this support for the series (and the lack of space of the CBS headquarters to store a whopping 20 tons of nuts, I guess) made them think about renewing it.

And they have! With a message in the Jericho wiki, CBS announces they will be renewing Jericho as a 7-episode season for next year, with the possibility of renewing it for more seasons depending on ratings.

Even if you didn't see, or didn't like the show, I think it's nice to see how people can make themselves be listened.



 

iPhone, new MacBookPro and Bill and Steve together

First of all, the iPhone Ads. Nicely done, to the point. Probably better than a Hello, I am an iPhone. And I am a Motorola or something. The blokes at TUAW think the Mac ads should be that way, too, and I agree.

While the Mac vs PC ads are nice for people who already are Mac users, I am not sure how many people would feel the urge to change from a PC to a Mac after seeing one of these ads. Just show them  Exposé and some of the iLife/iWork tools maybe, like they do on the iPhone ads.

I am sure all of you Mac users have been in the situation when a PC user tells you: Hey! can you do that cube rotation thing?

Anyway, we now have an official launch date (at least for the US): June 29th.

There was a rumor about a new brushed metal iMac being launched. It was a fake, but a really nice one. Build it, Apple.

We have, however, an updated MacBook Pro, with a much awaited Santa Rosa processor, mercury-free LED displays, better graphics card, and comes standard with 2GB of RAM with support for up to 4GB of RAM.




They claim 6 hours of battery life for the 15" model, which is probably about an hour more than the last models.

That is quite a lot more than roughly 2 hours and 30 minutes I get with my 1-year-old MacBook Pro, with 271 load cycles and 79% remaining capacity, and not so bad as Lucian, whose 1 year and a couple of months MacBook Pro had its battery already replaced ( almost exploded at CERN ;) ), and the new one lasting less than an hour (with only 92 cycles).

And finally, a Steve Jobs and Bill Gates interview at D5 Conference. Together! Zusammen! I still haven't seen it, but I've been told it's interesting.



Here's the link: http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=256972720

You can download it either in an audio-only or a video format.



 

The True Story of the Statue of Liberty

We all know the Statue of Liberty was a gift from France to the US, as a commemoration for the centennial of the foundation of the country.



What is probably unknown to most people is the problems that Frédéric-Auguste Bartholdi, the man behind the idea, had to go through to finally ship and mount his statue in NYC.

It is a true story of willingness and persistence, worth the reading: Neatorama - The True Story of the Statue of Liberty



 

Microsoft Surface is like a giant iPhone

Microsoft Surface is a new concept table computer with a big multi-touch 30" screen, similar to the one in the iPhone, where you can resize photos with two fingers and that sort of things. Internally, however, it's much more complex. It uses cameras to sense objects, hand gestures and touch, and it's based on Vista, they say.



It also autodetects devices when you put them on top, showing its contents. The "file copy" thing is quite cool if you ask me, and the idea overall, well, I think it's brilliant.

Apparently they have been working in it since 2001, and they will start selling it now for a whopping $10000. You still can't buy it anyway, but you will be able to play with its dirty screen in some shops and several hotel chains.

Check out the official videos in their Surface site, and a Popular Mechanics video in Gizmodo.



 

Search



About

newton.gra2.com is a blog about technology, opinion and random thoughts written by Daniel Alvarez, a computer engineer currently living in Zurich, Switzerland.

Topics

News (20/0)
Manuals (24/0)
Security (7/0)
Music (3/0)
Weeklog (1/0)
Personal (34/0)
Photos (3/0)
Opinion (14/0)
Windows (5/0)

Blogroll

Pros i contres (Jordi)
Entrepa de fusta (Oriol)
Spaghetti Code (Isaac)
Made in net (Eric)
Nogare (Juan)
Blog de Isaac Jimenez
Web d'en Jaume Benet
Montcada Wireless (Fran)
Blog d'en Ricard Forniol
Angela Fabregues
in.solit.us

Libertad Digital
FOX News
The Wall Street Journal
The Washington Times
The Jerusalem Post

Michelle Malkin
Eurabian News
Nihil Obstat
Barcepundit
Expose the left
Davids Medienkritik
Johan Norberg
Ayaan Hirsi Ali

User Functions

:

:


Lost your password?

Latest posts

Stories

No new stories

Comments last 2 days

No new comments

Trackbacks last 2 days

No new trackback comments

Links last 2 weeks

No recent new links