Tag Archives: linux

Catching Mono

When I was up in Bentonville, AR speaking at the Northwest Arkansas Code Camp, I came across an issue of ASP.NET Pro magazine with the title “The LAMA Stack” (short for Linux, Apache, MySQL, and ASP.NET).  The article inside turned out not to be that interesting, but the idea of using ASP.NET with an otherwise completely open-source stack certainly is.  

One of the things that is said to deter many startups or other small shops from using the Microsoft platform is the licensing cost of its products, particularly SQL Server.  But since Mono allows us to run .NET code on Linux, all of those costs can be eliminated.  Also, since the ASP.NET MVC framework was released as MS-PL (Microsoft’s most permissive open-source license), the Mono team was able to quickly integrate that into their framework as well.  

Since I want to start my own business one day, it ocurred to me that this could be a great way to leverage my existing skills, but use a modern web framework (MVC) and not have to put up a huge upfront investment.  And yes, I know about BizSpark, the program that gives startups free Microsoft software, but that deal “expires” after 3 years.  And if your business isn’t exactly booming at that point, then you may be stuck with an application that you can’t afford the licenses for.

So I decided to start experimenting with Mono to see if it was easy enough to work with that it would even be a viable option for me.  I’m not the most Linux-savvy guy in the world (as you may already be aware from reading some of my previous posts), and there was a distinct possibility that it would simply be too much of a headache for it to be worth it.  

I started out with the  VMWare image that’s available on the Mono project site (www.mono-project.com), and tried some basic “Hello, World” stuff, and that worked just fine.  Even getting an app running under Apache rather than the MonoDevelop IDE was really easy with the AutoConfiguration feature they’ve implemented.  The problem started when I tried to run an MVC app under Apache.  Because AutoConfiguration depends on the ASP.NET file extensions (“.aspx” et al.) to work, and MVC apps avoid those extensions, they can’t be used together, so I had to delve into defining an Apache virtual host for the MVC app.  Thankfully, the Mono team has provided a great tool for generating most of the boilerplate configuration for a Mono ASP.NET app on the project site (http://go-mono.com/config-mod-mono/).  

The next problem was that the version of Mono that supports MVC (v. 2.4) wasn’t available yet on the Linux distribution that I run, Ubuntu, which only has a package published for version 2.2.  That meant that I would need to compile Mono and several other tools from source, which is a somewhat daunting proposition for someone not very experienced with compilation on a Linux system.  I found a great resource for this, though, on the blog of a BlogEngine.NET team member named Russell (couldn’t find his last name) here: http://blog.ruski.co.za/page/Install-Mono-on-Ubuntu.aspx.  This post gives step-by-step instructions on getting Mono 2.4 running on Ubuntu, and without it, I would probably still be banging my head against the wall.

After much trial and error, I finally achieved my desired result.  I was able to run an ASP.NET application that was created and compiled in Visual Studio on Windows, copied over to a Linux machine and executed under Mono.  It wasn’t the most frictionless experience in the world, by any means, but after having done it once, I think subsequent apps will be easy enough to set up.  I’ll be doing the setup process at least one more time in the near future; I’d like to get Mono apps running on the servers we have set up for the new open-source shared interest group that I’ve recently joined with several other Praeses employees, which we’ve decided to call Samurai Delicatessen 😉 .  If I can manage to do the setup remotely over SSH, I think I can safely say it’s a stack that I’ll be able to handle using in the future.

Adventures with Forks, Boxes, and Ibexes

As I’ve posted before, I’ve been trying to help my pastor with a church management system written in Rails, but I’ve been hitting some roadblocks.  First, I tried developing on my Mac Mini, since Macs are what all the cool kids use to develop for Rails.  Well, that Mini ended up being a media machine, and developing using a television as a monitor was not very pleasant. It’s not an HDTV, and so only capable of 800×600, but even at that resolution, the screen is practically unreadable. 

The most convenient thing for me to do would be to develop on my laptop, since I can take it with me and work with Lowell (my pastor) up at the church on the system when I have problems.  So, I started trying to get the app set up on my Windows machine.  This actually worked fine for a while, but then Lowell ended up adding a couple of gems called “starling” and “workling” that basically create a task queue that you can farm out long-running tasks to.  It works great on Lowell’s Mac and in the production environment.  However, I soon discovered that starling uses “fork()” to achieve its ends, which meant a no-go for me on my Windows machine.

Since I can’t exactly install OSX on my laptop, the only option left was Linux.  As I’ve written about before, at one point I had Ubuntu installed on a partition on my laptop, so I’d been down that road before.  However, I had actually recently removed the Linux install, since I really wasn’t doing anything with it, so I had to go through the install process again (which is actually not all that bad on Ubuntu, for what it’s worth).  I installed Ubuntu version 8.10 (Intrepid Ibex) on a 15 Gb partition and began the environment setup process.

The very next day at work, a coworker happened to mention a virtualization tool he was using called VirtualBox.  I can’t believe I hadn’t heard about this thing before.  I knew about Virtual PC, which Microsoft now gives away for free, but that obviously only allows Windows guest OSes.  VMWare does have a free VM “player” that supports different kinds of guests that they give away, but as far as I know the tools you have to use to create a VM cost money. VirtualBox, developed by Sun, is completely free and allows for a whole slew of both host and guest OSes.  Anywho, I gave it a try, and I was very impressed.  It’s quite performant, and has support for just about everything I think I’d want (networking, USB devices, etc).  Another nice feature is that the virtual disk file can be set up to grow dynamically so that the VM is only taking up the space it needs; no more, no less.

It then became obvious that the 15 Gb partition I was using for my Ubuntu install was kind of a waste of space.  So I started the process of removing the partition I had added just days before.  I want to record what I did to achieve this, mostly as a record for myself in case I need to do it again later.  I used a free tool called GParted, which comes as a bootable CD image, to delete the partition Ubuntu was installed on and resize the main partition to take up the newly freed space.  After that comes the part that I usually forget, which is fix the master boot record.  When you install Ubuntu, you get this thing called GRUB, which is a boot loader that will let you choose which OS to boot up when you turn on your machine.  When you delete the partition with Linux on it, GRUB freaks out and won’t load up an OS.  To fix this, you need your Windows install CD.  Boot from the CD, then (depending on your version of Windows) either start a Recovery Console (XP), or choose “Repair Computer” and then open a console (Vista).  On XP, type “fixmbr” (no quotes), and on Vista, type “bootrec /FixMbr” (again, no quotes).  This will repair your master boot record, and you should be all set after a restart.

Since I’ve been having all this fun the past couple of evenings, I have not gotten as much sleep as I need.  I’m greatly looking forward to the two holidays off work I’ve got coming, as I’m sure you all are.  I hope everyone has a happy Thanksgiving!