Permalink
Browse files

Initial check-in

  • Loading branch information...
purcell committed Oct 19, 2007
0 parents commit b558fdc9578bd38459d25187e3c65545b1308e7a
Showing with 148 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +13 −0 README
  3. +22 −0 Rakefile
  4. +56 −0 install.rb
  5. +29 −0 lib/commands/maintenance_server.rb
  6. +8 −0 uninstall.rb
@@ -0,0 +1,20 @@
+Copyright (c) 2007 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 README
@@ -0,0 +1,13 @@
+MaintenanceServer
+=================
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2007 [name of plugin creator], released under the MIT license
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the maintenance_server plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the maintenance_server plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'MaintenanceServer'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+
+require "#{File.dirname($0)}/../../../config/boot" unless defined?(RAILS_ROOT)
+
+def create_file(path, &block)
+ puts "Creating #{path}"
+ if File.exist?(path)
+ puts " - skipping: already exists"
+ else
+ File.open(path, 'w', &block)
+ puts " - done"
+ end
+end
+
+create_file("#{RAILS_ROOT}/script/maintenance_server") do |f|
+ f.write(<<-'end_script')
+#!/usr/bin/env ruby
+# Avoid booting the full Rails environment...
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.."
+require "#{RAILS_ROOT}/vendor/plugins/maintenance_server/lib/commands/maintenance_server"
+ end_script
+ File.chmod(0755, f.path)
+end
+
+create_file("#{RAILS_ROOT}/public/maintenance.html") do |f|
+ f.write(<<-end_html)
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <title>Site temporarily unavailable</title>
+ <style type="text/css">
+ #message {
+ background: white url(/images/logo.png) no-repeat top left;
+ font-size: 120%;
+ padding-top: 70px;
+ width: 700px;
+ margin: 50px;
+ }
+ </style>
+</head>
+<body>
+<div id="message">
+<h1>We'll be right back!</h1>
+<p>
+The site is temporarily unavailable while we make some improvements.
+</p>
+<p>
+This usually takes only a few moments, so please bear with us and try again soon.
+</p>
+<p>
+Best wishes from the team!
+</div>
+</body>
+</html>
+end_html
+end
@@ -0,0 +1,29 @@
+HTML_DIR = "#{RAILS_ROOT}/public"
+MAINTENANCE_PAGE = "#{HTML_DIR}/maintenance.html"
+BIND_INTERFACE = "127.0.0.1"
+unless (PORT = ARGV.first)
+ STDERR.write("usage: #{$0} port\n")
+ exit 1
+end
+
+require 'rubygems'
+require 'mongrel'
+
+class MaintenanceHandler < Mongrel::HttpHandler
+ def initialize(dir_handler)
+ @dir_handler = dir_handler
+ end
+
+ def process(request, response)
+ path = request.params['PATH_INFO']
+ return @dir_handler.process(request, response) if @dir_handler.can_serve(path)
+ response.start(503) do |head, out|
+ head["Content-Type"] = "text/html"
+ out.write(File.read(MAINTENANCE_PAGE))
+ end
+ end
+end
+
+h = Mongrel::HttpServer.new(BIND_INTERFACE, PORT)
+h.register("/", MaintenanceHandler.new(Mongrel::DirHandler.new(HTML_DIR, false)))
+h.run.join
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+require "#{File.dirname($0)}/../../../config/boot" unless defined?(RAILS_ROOT)
+
+for f in ["#{RAILS_ROOT}/script/maintenance_server", "#{RAILS_ROOT}/public/maintenance.html"]
+ puts "Removing #{f}"
+ File.unlink(f) if File.exist?(f)
+end

0 comments on commit b558fdc

Please sign in to comment.