Free to good home: rails-app-installer

Posted by Scott Laird Tue, 24 Jul 2007 14:20:00 GMT

I really should have done this nine months ago, but I just don’t have time to devote to my rails-app-installer project, and I’d love it if someone would volunteer to take it over.

This is the installer used in the Typo GEM; it’s designed to make it easy to turn any Rails app into an easily-installed GEM.

The code lives in Google Code; feel free to take a look around.

If you’re interested, then please either send me mail or let me know in person at OSCON this week.

Tags , , ,  | no comments

Easy Backups for Rails

Posted by Scott Laird Wed, 16 Aug 2006 04:36:14 GMT

I mentioned a few weeks ago that I was trying to add generic database backups to my installer, so I can do database backups before each upgrade. I got backups working a couple releases ago, and they’re useful enough that I’ve extracted them so everyone can use them.

The latest installer release includes a pair of command-line tools that make it easy to use the installer’s backup and restore code without using the rest of the installer. Run rails-backup and it’ll produce a .yml file containing all of your data. Then run rails-restore BACKUPFILENAME and it’ll restore the backup. The dump and restore formats are database-independent, so it should be possible to use these tools to migrate between database engines, but this hasn’t been heavily tested yet.

One warning about the restore–rails-restore doesn’t restore the schema, just the data. So you’ll need a way to build a database with the right schema revision. Look in the .yml file to see which schema version you need (search for schema_info), and then run rake migrate VERSION=xx to move your database to the right schema revision.

To use these, just install the rails-app-installer gem, and they should appear in your path automagically. Report bugs to the rails-app-installer bug tracker.

Tags , , ,  | 4 comments

Rails Application Installer 0.2.0

Posted by Scott Laird Wed, 16 Aug 2006 04:19:28 GMT

I just released version 0.2.0 of my rails-app-installer tool.

This is the installer that I created for Typo, extracted into its own package so other Rails apps can use it as well. The installer lets users install Typo with only two commands:

  $ sudo gem install typo
  $ typo install /some/path

With a little bit of work, you can get your app to be just as easy to install. New in 0.2.0 is a rails-app-installer-setup command that will do most of the work for you. Just cd to your project and run rails-app-installer-setup my-app, and it’ll create a bin/my-app installer for you, along with some config files and a lib/tasks/release.rake file that knows how to build a .gem for you. Just follow the directions that rails-app-installer-setup gives you and you’ll have a .gem in no time at all.

Changes for version 0.2.0:

  • Added a rails-app-installer-setup command to help set up new apps.
  • Made the installer fetch its default version of Rails from the application .gem dependency, instead of making developers repeat themselves.
  • Fixed a restore bug that kept IDs from being restored correctly.
  • Added a command-line backup and restore tool that can be used with any Rails app. I’ll talk about it more in another post.

At this point, it’s nearly complete. It needs better documentation, and I’d like to get a bit of feedback from other apps before I call it 1.0, but my to-do list is getting pretty short.

Tags , ,  | no comments

Rail Application Installer

Posted by Scott Laird Fri, 28 Jul 2006 17:53:08 GMT

I’ve mostly finished extracting Typo’s installer into its own Rails project and .gem. The installer makes it trivial to build an installable .gem for any Rails project, so the install process looks like this:

$ gem install my-project
$ my-project install /some/path

The installer source lives in Google Code. That includes a mailing list and bug tracker. I’ll upload my .gem to RubyForge later today, along with some documentation. For now, the rdoc is available.

Here’s what you’ll need to do to add the installer to your existing Rails app:

  1. Create a .gem that depends on rails-app-installer, rails, and all other .gems that you need to have installed.
  2. Add an executable entry to your gemspec. If your app is called my-app, then add executable = ['my-app'].
  3. Finally, create bin/my-app, using one of the examples in the rails-app-installer SVN tree as an example.

Here’s a short example bin/my-app:

  #!/usr/bin/env ruby

  require 'rubygems'
  require 'rails-installer'

  class AppInstaller < RailsInstaller
    application_name 'my_app'
    support_location 'my website'
    rails_version '1.1.4'
  end

  # Installer program
  directory = ARGV[1]

  app = AppInstaller.new(directory)
  app.message_proc = Proc.new do |msg|
    STDERR.puts " #{msg}"
  end
  app.execute_command(*ARGV)

That’s all that’s needed–as long as the installer gem is installed, this will give you a full installer that supports installs, upgrades, db backups and restores, and all of the other things that the Typo installer currently provides. Adding application-specific installer subcommands is easy. Here’s the sweep_cache implementation from Typo’s installer:

  class SweepCache < RailsInstaller::Command
    help "Sweep Typo's cache"

    def self.command(installer, *args)
      installer.sweep_cache
    end
  end

That’s all that’s needed to implement the typo sweep_cache /some/path installer command.

Update: The gem is out. gem install rails-app-installer.

Tags , , ,  | 1 comment

ActiveRecord to YAML serializer?

Posted by Scott Laird Tue, 25 Jul 2006 14:50:30 GMT

For the next version of my installer, I’d love a generic, DB-agnostic way to perform database backups under Rails. Ideally, I’d be able to serialize (and unserialize) an entire DB to YAML. That way the installer could easily perform backups for people before they upgrade, and the backups would be portable between databases. So someone could start out with SQLite and move to PostgreSQL or MySQL.

The problem is that I don’t actually want to have to write this myself, but I’m not having a lot of luck searching for one. It seems like a pretty obvious tool, though, so perhaps I’m just searching wrong. It shouldn’t be very hard to write the serializer, but the hard part will be getting the deserializer right–with Postgres, you’re going to have to play games to get the DB’s internal sequence numbers set right. Other databases will probably have similar (but different) issues.

Any pointers?

Tags , , ,  | 2 comments

Typo installer

Posted by Scott Laird Sun, 23 Jul 2006 23:09:56 GMT

As I mentioned in the Typo 4.0.0 announcement, Typo now includes a .gem-based installer that makes it easy to install Typo. Just install the Typo gem (gem install typo) and run the Typo installer (typo install /some/path) to create a new Typo blog in /some/path. The installer will install all of Typo’s files, create a working set of config files, create a SQLite database for you, and start the Mongrel web server on a random TCP port. It’ll also create a set of sample Apache and Lighttpd configuration files to show you how to tie Typo into your existing web server. One warning: this will only work right if you already have SQLite 3 and SWIG installed on your system. If they’re missing, then you’ll get weird warnings and errors. SWIG is particularly strange–if it’s missing, then you’ll get sporadic test failures when trying to use SQLite.

The same installer can also be used for upgrades–if you’ve installed one of the Typo 3.99.x pre-releases, then you can upgrade the same way you installed Typo in the first place–run gem install typo to grab a newer Typo gem, and then typo install /some/path to upgrade. Typo will recognize the existing install, back up the database, shut down the existing Mongrel server, install new files, upgrade the database, and restart Mongrel.

Once Typo is installed you can test it by connecting directly to Mongrel with your web browser; the installer will display the URL for you. Normally, for production use, you’d configure some sort of proxy or load balancer (like Apache’s mod_proxy) in front of Mongrel, so users talk to Apache and Apache talks to Mongrel. The installer creates a number of example configs in the installer/ directory. Once thing to be careful about–you’ll need to make sure that Mongrel and Typo are restarted when your web server reboots. You can start them by running typo start /some/path. You’ll need to talk to your system administrator or hosting provider to learn the best way to start Typo on boot.

Compared to the half-dozen mutually contradictory install guides that existed before, this is a big step forward. However, not everyone wants to (or can) run Typo under Mongrel with SQLite. Some hosting environments make HTTP proxying difficult, while others would rather use a “real” database. So, in the Rails spirt of convention over configuration, I built the installer to use Mongrel and SQLite by default, but you can configure it for your favorite database with a bit of extra work. There are a number of configuration settings that control the installer’s behavior. The typo config /some/path command will show existing variables. You can change them via typo config /some/path var=value.

As of Typo 4.0.0, the installer knows about 6 different configuration variables:

  • web-server: which web server technology Typo will use. It defaults to mongrel. Other options are mongrel_cluster and external. If you want to use FastCGI, then set web-server to external.
  • threads: if web-server is set to mongrel_cluster, then threads controls how many Mongrel back ends are used.
  • port-number: which TCP port Mongrel listens on. This defaults to a random number between 4000 and 5000. The mongrel_cluster server uses one TCP port per thread, starting with port-number and counting up.
  • url-prefix: if Mongrel 0.3.13.4 or higher is installed, then url-prefix can be used to move Typo into a subdirectory. If you want to run Typo on http://www.example.com/blog, then you’ll need to set url-prefix to /blog.
  • bind-address: which IP address Mongrel binds to.
  • database: which database server Typo will use. The default is sqlite. If you change this, then the installer won’t create a SQLite database for Typo or try to back the SQLite database up during upgrades.

So, if you want to use the Typo installer with FastCGI and Mysql, then you’ll want to do this:

  $ typo config /some/path web-server=external database=mysql

You’ll also need to edit database.yml and create your own database. There are schema files in db/schema.*.sql for several different databases. Pick the one that matches your database.

The typo command supports 7 sub-commands:

  • install [version] [config=value ...]. Installs or upgrades Typo. You can optionally specify which version to install, if you have multiple Typo .gems installed. You can also use the installer to install directly out of a Subversion checkout by specifying version cwd and running typo from inside of the Subversion directory.
  • start. Starts the Mongrel or mongrel_cluster webserver. If Mongrel has been disabled via web-server=external, then this command does nothing.
  • run. Just like starts, but runs Mongrel in the foreground when possible.
  • stop. Stops Mongrel. Like start, it is ignored if Mongrel has been disabled.
  • restart. Stops and restarts Mongrel.
  • config [name=[value] ...]. Without parameters, it shows Typo’s current configuration. With parameters, it sets the configuration parameters. If you specify name= without a value, then it clears the variable.
  • sweep_cache. Sweeps Typo’s cache. This can be useful for troubleshooting.

That should be all that you need to know to install Typo and keep it running. Any questions?

Tags , , ,  | 9 comments

Closer and closer to Typo 4.0, and a call for testers.

Posted by Scott Laird Mon, 10 Jul 2006 16:56:07 GMT

We made a lot of progress this weekend on Typo. We’re down to 9 open tickets, and several of those aren’t really code issues–things like “set up a Typo blog on http://typosphere.org” (which is mostly done, actually). There are a few bugs left, and one or two minor development points, but at this point the thing we really need most is some testing. If you use Typo, then I’d love it if you could either test the latest trunk or the latest .gem release (sudo gem install typo; typo install /some/path) and file bugs.

Tags , , ,  | 13 comments