Today, I want to walk you through one of the ready-made appliance recipes that comes with Carpet. This article assumes you’ve read the getting started with Carpet guide.
Appliance recipes are plain Capistrano recipes which enable you to setup a complete server by just using one of the pre-defined ones like apache_lb, rails_22, memcached or mysql_master.
Building Appliances from Disk Images
And why would you use one of these magical recipes when you could re-use an existing Amazon EC2 or VMWare image? While it’s definitely handy to boot right into a ready-made server without waiting for the installation, disk images have lots of disadvantages, too:
- You never know, what’s really installed, do you? (root kits, anyone?)
- hardly any documentation of what is installed much less where
- you’ll never learn how to build such an image yourself
Building Appliances Using Recipes
If you’re using Carpet recipes instead of disk images, it’s like getting the source code of your server setup delivered along with a nice build environment. Instead of a black box, disk image you get a set of instructions on how to build the desired appliance.
If you wanted, you could execute all steps manually to learn how to do it yourself. But of course, Carpet provides you with the runtime environment to automatically build (and re-build) your systems based on those appliance recipes. Think Gentoo Linux vs. Red Hat or Debian.
The apache_lb recipe
Here is the apache_lb recipe as an example:
Capistrano::Configuration.instance(:must_exist).load do task :apache_lb do assure :service, "network/http:apache22", :package => "SUNWapch22" assure :package, "SUNWapch22m-dtrace" assure :file, "/etc/apache2/2.2/conf.d/vhost.conf", render(vhost_conf_erb, { :hostname => capture("hostname").strip, :mongrel_start_port => fetch(:mongrel_start_port, 8000), :web_servers => roles[:web].servers, :app_servers => roles[:app].servers, :apache_log_dir => "/var/apache2/2.2/logs", :apache_auth_user_file => "/etc/apache2/2.2/htpasswd" }) if exists?(:vhost_conf_erb) svc.refresh("network/http:apache22") pfexec("/usr/sbin/logadm -w apache -C 7 -z 0 -a '/usr/sbin/svcadm restart apache22' -p 1d /var/apache2/2.2/logs/*_log") end end
As you can see by the first two lines, a Carpet appliance is a standard Capistrano recipe. So it should be super simple to adapt an existing one or write your own 😉
First, the recipe assures that the apache web server is installed. If it does not find the apache service installed on the target box, it will try to install the given package (in this case SUNWapch22) automatically.
After reading and rendering the template for a vhost setup (provided by you in the variable vhost_conf_erb
) it will make sure that the apache service re-reads its configuration by refreshing the service.
Last, but not least, it will configure log file rotation using the Solaris specific logadm
tool.
Appliance Recipes Put You In The Driver’s Seat
Easy to understand recipes for server types (like an apache load balancer, a MySQL master or a Ruby on Rails app server) combined with Carpet as a runtime environment for building appliances put you back in the driver’s seat. You can understand exactly how your servers will look like and easily adapt the scripts to your own needs.
Give Carpet a try and write about what sucks or rocks about it here in the comments!