Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit ce442b5662b50989a53fac8c125e64169085e822 Burke Libbey committed Aug 15, 2008
Showing with 116 additions and 0 deletions.
  1. +65 −0 generate-vhosts.rb
  2. +42 −0 types.yml
  3. +9 −0 vhosts.yml
@@ -0,0 +1,65 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'rubygems'
+rescue LoadError
+end
+require 'yaml'
+
+CONFIG_PATH = '/etc/httpd/conf'
+
+# No syntax checking whatsoever on the yaml files. You're on your own.
+
+class Vhost
+
+ def initialize(args)
+ # This might be dangerous? I'm pretty sure we can trust whoever's
+ # writing our vhost definitions :)
+ args.each do |k,v|
+ instance_variable_set "@#{k}", v
+ end
+ @type ||= 'standard'
+
+ # We need to wrap @location in slashes, but if it's root, that gives us
+ # // or ///, so we collapse multiple sequential slashes to a single /.
+ @location = "/#{@location}/"
+ @location.gsub!(/\/+/,'/')
+
+ @types = YAML.load(open("#{CONFIG_PATH}/types.yml"))
+ end
+
+ def to_s
+ if @types.has_key? @type
+ eval("return \"#{@types[@type]}\"")
+ end
+ end
+
+end
+
+
+output = ""
+
+# Default/catchall vhost.
+output << <<END
+<VirtualHost *>
+ DocumentRoot /srv/http/localhost/htdocs
+</VirtualHost>
+END
+
+hosts = YAML.load(open("#{CONFIG_PATH}/vhosts.yml"))
+
+begin
+ hosts.each do |k,v|
+ vhost = Vhost.new(v.merge({'domain' => k}))
+ output << vhost.to_s
+ end
+rescue
+ exit 1 # Just return an error. We don't care what it is.
+ # The initscript will smack somebody on the head and fail.
+end
+
+# Write the output file and commit it to git.
+File.open("#{CONFIG_PATH}/vhosts.gen/vhosts.gen.conf",'w') do |f|
+ f.puts output
+ `cd "#{CONFIG_PATH}/vhosts.gen"; git commit -a -m 'generated by generate-vhosts'`
+end
@@ -0,0 +1,42 @@
+---
+standard: |
+ <VirtualHost *>
+ ServerName #{@domain}
+ ServerAlias www.#{@domain}
+ DocumentRoot /srv/http#{@location}#{@domain}/htdocs
+ RewriteEngine on
+ RewriteCond %{HTTP_HOST} ^www\\.#{@domain.gsub('.','\.')}
+ RewriteRule (.*) http://#{@domain}$1 [R=301,L]
+ #{@custom}
+ </VirtualHost>
+
+alias: |
+ <VirtualHost *>
+ ServerName #{@domain}
+ ServerAlias www.#{@domain}
+ RedirectPermanent / http://#{@redirect}/
+ </VirtualHost>
+
+rails: |
+ <VirtualHost *>
+ ServerName #{@domain}
+ ServerAlias www.#{@domain}
+ DocumentRoot /srv/rails#{@location}#{@domain}/public
+ <Directory \"/srv/rails#{@location}#{@domain}/public\">
+ Options -Indexes FollowSymLinks
+ AllowOverride All
+ Order allow,deny
+ Allow from all
+ </Directory>
+ RailsEnv #{@railsenv}
+ RewriteEngine on
+ RewriteCond %{HTTP_HOST} ^www\\.#{@domain.gsub('.','\.')}
+ RewriteRule (.*) http://#{@domain}$1 [R=301,L]
+ #{@custom}
+ </VirtualHost>
+
+custom: |
+ <VirtualHost *>
+ ServerName #{@domain}
+ #{@custom}
+ </VirtualHost>
@@ -0,0 +1,9 @@
+---
+53cr.com:
+ location: 53cr
+redmine.53cr.com:
+ type: rails
+ railsenv: production
+chromium53.com:
+ type: alias
+ redirect: 53cr.com

0 comments on commit ce442b5

Please sign in to comment.