Deploying a Rails application on OpenSolaris with passenger aka modrails
2009-01-29 11:09:47 +0000
Two technologies I wanted to play around with for some time are OpenSolaris and passenger. OpenSolaris because of ZFS, Zones, SMF and the latest addition IPS and passenger because it seems to be the new default Rails deployment model and is really easy to configure.
So I deceided to combine those to and get started. Here’s what I did. Maybe it’s useful for someone who’s trying to do the same.
I grabbed the OpenSolaris 2008.11 Virtualbox image from virtualboximages.com and booted it in VirtualBox.
I wanted to make sure to have the latest updates so I updated the image (all commands are executed as root):
# pfexec pkg image-update
A reboot later I installed the necessary parts for a Rails environment:
# pfexec pkg install SUNWruby18
# pfexec pkg install gcc-dev
SUNWruby18 installes ruby 1.8.6p287 which is exactly what I needed.
The mysql installation was a bit harder:
# pfexec pkg install SUNWmysql5
# /usr/mysql/5.0/bin/mysql_db_install
# chown -R mysql:mysql /var/mysql/5.0/data
I needed to manually chown the data dir. Otherwise mysql wouldn’t start.
You can confirm that your mysql is running via:
# svcs -l mysql
The logfile gives further information if something goes wrong.
To access mysql try:
# /usr/mysql/5.0/bin/mysql
The “5.0” in the path is important because there’s also a mysql version 4 installed. This will be of interest when installing the mysql ruby gem. The command to correctly install the gem is:
# pfexec gem install mysql -- --with-mysql-lib=/usr/mysql/5.0/lib/mysql --with-mysql-include=/usr/mysql/5.0/include
Thanks to Amanda Waite for this hint.
The next installation step is Apache:
# pfexec pkg install SUNWapch22
Make sure it starts via svcadm:
# svcadm enable apache22
Check that it runs:
# svcs -l apache22
(or just type http://localhost in your browser)
I needed memcached, so I installed it:
# pfexec pkg install SUNWmemcached
It didn’t start right away, though. There are some changes you have to apply to run memcached in solaris
# svccfg
svc:> select memcached
svc:/application/database/memcached> setprop memcached/options=("-u" "nobody" "-m" "2048")
svc:/application/database/memcached> quit
# svcadm refresh memcached
Of course we need rails:
pfexec gem install rails
The current stable version of passenger doesn’t support Solaris but the egde version does. So I downloaded the passenger edge Version off github.
It didn’t compile right away. There are some compiler flags that aren’t supported in Solaris so I used these changes to make passenger compile.
Commandwise this looked like this: I unpacked the tarball into /opt/passenger and then did a
# cd /opt/passenger
# vi lib/passenger/platform_info.rb # see above
# bin/passenger-install-apache2-module
# chown -R webservd /opt/passenger
Add the mentioned config snippet to /etc/apache2/httpd.conf and restart apache
# svcadmin restart apache2
Now were all set to create a new rails app. I created a seperate ZFS partition to serve the apps. Just because it’s so easy to do with ZFS and it gives you more control on how much space is used by your apps etc.
# zfs create rpool/apps
Now it’s time for the demo app:
# cd /rpool/apps
# rails demo
# chown -R webservd demo
I added the DocumentRoot of the app to the apacheconfig (DocumentRoot /rpool/apps/demo/public
) and restarted apache again (svcadm restart apache2
– you know the drill by now).
And that’s it. A http://localhost gave me the demo welcome page. Nice.
Later I wanted do deploy a rails app via capistrano so I needed git. There isn’t a IPS package for git yet, so I decided to take the standard compile route. I downloaded git and compiled it like this:
# ./configure --prefix=/opt/git
# make install
# ln -s /opt/git/bin/git /usr/bin/git
I used the symlink because capistrano wasn’t able to find git otherwise – setting scm_command didn’t work.
If anyone tries this recipe and it works or it doesn’t work… just let me know. Have fun with OpenSolaris. It’s worth checking out.
Related Posts
- Stop writing tutorials - start writing Vagrantfiles or Dockerfiles - Make use of modern tools to make tutorials understandable as well as executable
- The missing piece: Operating Systems for web scale Cloud Apps - Operating systems that are optimised for cloud applications regarding configuration support and the distributed nature of apps are not there yet.
- There will be no reliable cloud (part 3) - How I stopped worrying and love the cloud