From 2710d631aa4ecff45bf39374c5dd30de41d5cc23 Mon Sep 17 00:00:00 2001 From: Evan Weaver Date: Sat, 22 Nov 2008 12:47:59 -0800 Subject: Removed examples and debug.rb. --- examples/builder.rb | 29 --- examples/camping/README | 3 - examples/camping/blog.rb | 294 ----------------------- examples/camping/tepee.rb | 149 ------------ examples/httpd.conf | 474 ------------------------------------- examples/mime.yaml | 3 - examples/mongrel.conf | 9 - examples/mongrel_simple_ctrl.rb | 92 ------- examples/mongrel_simple_service.rb | 116 --------- examples/monitrc | 57 ----- examples/random_thrash.rb | 19 -- examples/simpletest.rb | 52 ---- examples/webrick_compare.rb | 20 -- 13 files changed, 1317 deletions(-) delete mode 100644 examples/builder.rb delete mode 100644 examples/camping/README delete mode 100755 examples/camping/blog.rb delete mode 100644 examples/camping/tepee.rb delete mode 100644 examples/httpd.conf delete mode 100644 examples/mime.yaml delete mode 100644 examples/mongrel.conf delete mode 100644 examples/mongrel_simple_ctrl.rb delete mode 100644 examples/mongrel_simple_service.rb delete mode 100644 examples/monitrc delete mode 100644 examples/random_thrash.rb delete mode 100644 examples/simpletest.rb delete mode 100644 examples/webrick_compare.rb (limited to 'examples') diff --git a/examples/builder.rb b/examples/builder.rb deleted file mode 100644 index 5f0803a..0000000 --- a/examples/builder.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'mongrel' - -class TestPlugin < GemPlugin::Plugin "/handlers" - include Mongrel::HttpHandlerPlugin - - def process(request, response) - STDERR.puts "My options are: #{options.inspect}" - STDERR.puts "Request Was:" - STDERR.puts request.params.to_yaml - end -end - -config = Mongrel::Configurator.new :host => "127.0.0.1" do - load_plugins :includes => ["mongrel"], :excludes => ["rails"] - daemonize :cwd => Dir.pwd, :log_file => "mongrel.log", :pid_file => "mongrel.pid" - - listener :port => 3000 do - uri "/app", :handler => plugin("/handlers/testplugin", :test => "that") - uri "/app", :handler => Mongrel::DirHandler.new(".") - load_plugins :includes => ["mongrel", "rails"] - end - - trap("INT") { stop } - run -end - -config.join - - diff --git a/examples/camping/README b/examples/camping/README deleted file mode 100644 index 73ae9a0..0000000 --- a/examples/camping/README +++ /dev/null @@ -1,3 +0,0 @@ -To get these examples running, install Camping. - -Instructions here: http://code.whytheluckystiff.net/camping/ diff --git a/examples/camping/blog.rb b/examples/camping/blog.rb deleted file mode 100755 index 81a87da..0000000 --- a/examples/camping/blog.rb +++ /dev/null @@ -1,294 +0,0 @@ -#!/usr/bin/env ruby - -$:.unshift File.dirname(__FILE__) + "/../../lib" -require 'rubygems' -require_gem 'camping', '>=1.4' -require 'camping/session' - -Camping.goes :Blog - -module Blog - include Camping::Session -end - -module Blog::Models - def self.schema(&block) - @@schema = block if block_given? - @@schema - end - - class Post < Base; belongs_to :user; end - class Comment < Base; belongs_to :user; end - class User < Base; end -end - -Blog::Models.schema do - create_table :blog_posts, :force => true do |t| - t.column :id, :integer, :null => false - t.column :user_id, :integer, :null => false - t.column :title, :string, :limit => 255 - t.column :body, :text - end - create_table :blog_users, :force => true do |t| - t.column :id, :integer, :null => false - t.column :username, :string - t.column :password, :string - end - create_table :blog_comments, :force => true do |t| - t.column :id, :integer, :null => false - t.column :post_id, :integer, :null => false - t.column :username, :string - t.column :body, :text - end - execute "INSERT INTO blog_users (username, password) VALUES ('admin', 'camping')" -end - -module Blog::Controllers - class Index < R '/' - def get - @posts = Post.find :all - render :index - end - end - - class Add - def get - unless @state.user_id.blank? - @user = User.find @state.user_id - @post = Post.new - end - render :add - end - def post - post = Post.create :title => input.post_title, :body => input.post_body, - :user_id => @state.user_id - redirect View, post - end - end - - class Info < R '/info/(\d+)', '/info/(\w+)/(\d+)', '/info', '/info/(\d+)/(\d+)/(\d+)/([\w-]+)' - def get(*args) - div do - code args.inspect; br; br - code ENV.inspect; br - code "Link: #{R(Info, 1, 2)}" - end - end - end - - class View < R '/view/(\d+)' - def get post_id - @post = Post.find post_id - @comments = Models::Comment.find :all, :conditions => ['post_id = ?', post_id] - render :view - end - end - - class Edit < R '/edit/(\d+)', '/edit' - def get post_id - unless @state.user_id.blank? - @user = User.find @state.user_id - end - @post = Post.find post_id - render :edit - end - - def post - @post = Post.find input.post_id - @post.update_attributes :title => input.post_title, :body => input.post_body - redirect View, @post - end - end - - class Comment - def post - Models::Comment.create(:username => input.post_username, - :body => input.post_body, :post_id => input.post_id) - redirect View, input.post_id - end - end - - class Login - def post - @user = User.find :first, :conditions => ['username = ? AND password = ?', input.username, input.password] - - if @user - @login = 'login success !' - @state.user_id = @user.id - else - @login = 'wrong user name or password' - end - render :login - end - end - - class Logout - def get - @state.user_id = nil - render :logout - end - end - - class Style < R '/styles.css' - def get - @headers["Content-Type"] = "text/css; charset=utf-8" - @body = %{ - body { - font-family: Utopia, Georga, serif; - } - h1.header { - background-color: #fef; - margin: 0; padding: 10px; - } - div.content { - padding: 10px; - } - } - end - end -end - -module Blog::Views - - def layout - html do - head do - title 'blog' - link :rel => 'stylesheet', :type => 'text/css', - :href => '/styles.css', :media => 'screen' - end - body do - h1.header { a 'blog', :href => R(Index) } - div.content do - self << yield - end - end - end - end - - def index - if @posts.empty? - p 'No posts found.' - p { a 'Add', :href => R(Add) } - else - for post in @posts - _post(post) - end - end - end - - def login - p { b @login } - p { a 'Continue', :href => R(Add) } - end - - def logout - p "You have been logged out." - p { a 'Continue', :href => R(Index) } - end - - def add - if @user - _form(post, :action => R(Add)) - else - _login - end - end - - def edit - if @user - _form(post, :action => R(Edit)) - else - _login - end - end - - def view - _post(post) - - p "Comment for this post:" - for c in @comments - h1 c.username - p c.body - end - - form :action => R(Comment), :method => 'post' do - label 'Name', :for => 'post_username'; br - input :name => 'post_username', :type => 'text'; br - label 'Comment', :for => 'post_body'; br - textarea :name => 'post_body' do; end; br - input :type => 'hidden', :name => 'post_id', :value => post.id - input :type => 'submit' - end - end - - # partials - def _login - form :action => R(Login), :method => 'post' do - label 'Username', :for => 'username'; br - input :name => 'username', :type => 'text'; br - - label 'Password', :for => 'password'; br - input :name => 'password', :type => 'text'; br - - input :type => 'submit', :name => 'login', :value => 'Login' - end - end - - def _post(post) - h1 post.title - p post.body - p do - a "Edit", :href => R(Edit, post) - a "View", :href => R(View, post) - end - end - - def _form(post, opts) - p do - text "You are logged in as #{@user.username} | " - a 'Logout', :href => R(Logout) - end - form({:method => 'post'}.merge(opts)) do - label 'Title', :for => 'post_title'; br - input :name => 'post_title', :type => 'text', - :value => post.title; br - - label 'Body', :for => 'post_body'; br - textarea post.body, :name => 'post_body'; br - - input :type => 'hidden', :name => 'post_id', :value => post.id - input :type => 'submit' - end - end -end - -def Blog.create - Camping::Models::Session.create_schema - unless Blog::Models::Post.table_exists? - ActiveRecord::Schema.define(&Blog::Models.schema) - end -end - -if __FILE__ == $0 - require 'mongrel/camping' - - Blog::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog.db' - Blog::Models::Base.logger = Logger.new('camping.log') - Blog::Models::Base.threaded_connections=false - Blog.create - - # Use the Configurator as an example rather than Mongrel::Camping.start - config = Mongrel::Configurator.new :host => "0.0.0.0" do - listener :port => 3002 do - uri "/blog", :handler => Mongrel::Camping::CampingHandler.new(Blog) - uri "/favicon", :handler => Mongrel::Error404Handler.new("") - trap("INT") { stop } - run - end - end - - puts "** Blog example is running at http://localhost:3002/blog" - puts "** Default username is `admin', password is `camping'" - config.join -end diff --git a/examples/camping/tepee.rb b/examples/camping/tepee.rb deleted file mode 100644 index 199be37..0000000 --- a/examples/camping/tepee.rb +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/ruby -$:.unshift File.dirname(__FILE__) + "/../../lib" -%w(rubygems redcloth camping acts_as_versioned).each { |lib| require lib } - -Camping.goes :Tepee - -module Tepee::Models - def self.schema(&block) - @@schema = block if block_given? - @@schema - end - - class Page < Base - PAGE_LINK = /\[\[([^\]|]*)[|]?([^\]]*)\]\]/ - validates_uniqueness_of :title - before_save { |r| r.title = r.title.underscore } - acts_as_versioned - end -end - -Tepee::Models.schema do - create_table :tepee_pages, :force => true do |t| - t.column :title, :string, :limit => 255 - t.column :body, :text - end - Tepee::Models::Page.create_versioned_table -end - -module Tepee::Controllers - class Index < R '/' - def get - redirect Show, 'home_page' - end - end - - class List < R '/list' - def get - @pages = Page.find :all, :order => 'title' - render :list - end - end - - class Show < R '/s/(\w+)', '/s/(\w+)/(\d+)' - def get page_name, version = nil - redirect(Edit, page_name, 1) and return unless @page = Page.find_by_title(page_name) - @version = (version.nil? or version == @page.version.to_s) ? @page : @page.versions.find_by_version(version) - render :show - end - end - - class Edit < R '/e/(\w+)/(\d+)', '/e/(\w+)' - def get page_name, version = nil - @page = Page.find_or_create_by_title(page_name) - @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s - render :edit - end - - def post page_name - Page.find_or_create_by_title(page_name).update_attributes :body => input.post_body and redirect Show, page_name - end - end -end - -module Tepee::Views - def layout - html do - head do - title 'test' - end - body do - p do - small do - span "welcome to " ; a 'tepee', :href => "http://code.whytheluckystiff.net/svn/camping/trunk/examples/tepee/" - span '. go ' ; a 'home', :href => R(Show, 'home_page') - span '. list all ' ; a 'pages', :href => R(List) - end - end - div.content do - self << yield - end - end - end - end - - def show - h1 @page.title - div { _markup @version.body } - p do - a 'edit', :href => R(Edit, @version.title, @version.version) - a 'back', :href => R(Show, @version.title, @version.version-1) unless @version.version == 1 - a 'next', :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version - a 'current', :href => R(Show, @version.title) unless @version.version == @page.version - end - end - - def edit - form :method => 'post', :action => R(Edit, @page.title) do - p do - label 'Body' ; br - textarea @page.body, :name => 'post_body', :rows => 50, :cols => 100 - end - - p do - input :type => 'submit' - a 'cancel', :href => R(Show, @page.title, @page.version) - end - end - end - - def list - h1 'all pages' - ul { @pages.each { |p| li { a p.title, :href => R(Show, p.title) } } } - end - - def _markup body - return '' if body.blank? - body.gsub!(Tepee::Models::Page::PAGE_LINK) do - page = title = $1 - title = $2 unless $2.empty? - page = page.gsub /\W/, '_' - if Tepee::Models::Page.find(:all, :select => 'title').collect { |p| p.title }.include?(page) - %Q{#{title}} - else - %Q{#{title}?} - end - end - RedCloth.new(body, [ :hard_breaks ]).to_html - end -end - -def Tepee.create - unless Tepee::Models::Page.table_exists? - ActiveRecord::Schema.define(&Tepee::Models.schema) - Tepee::Models::Page.reset_column_information - end -end - -if __FILE__ == $0 - require 'mongrel/camping' - - Tepee::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'tepee.db' - Tepee::Models::Base.logger = Logger.new('camping.log') - Tepee::Models::Base.threaded_connections=false - Tepee.create - - server = Mongrel::Camping::start("0.0.0.0",3000,"/tepee",Tepee) - puts "** Tepee example is running at http://localhost:3000/tepee" - server.acceptor.join -end diff --git a/examples/httpd.conf b/examples/httpd.conf deleted file mode 100644 index 778124a..0000000 --- a/examples/httpd.conf +++ /dev/null @@ -1,474 +0,0 @@ -# -# This is the main Apache HTTP server configuration file. It contains the -# configuration directives that give the server its instructions. -# See for detailed information. -# In particular, see -# -# for a discussion of each configuration directive. -# -# Do NOT simply read the instructions in here without understanding -# what they do. They're here only as hints or reminders. If you are unsure -# consult the online docs. You have been warned. -# -# Configuration and logfile names: If the filenames you specify for many -# of the server's control files begin with "/" (or "drive:/" for Win32), the -# server will use that explicit path. If the filenames do *not* begin -# with "/", the value of ServerRoot is prepended -- so "logs/foo.log" -# with ServerRoot set to "/usr/local/apache2" will be interpreted by the -# server as "/usr/local/apache2/logs/foo.log". - -# -# ServerRoot: The top of the directory tree under which the server's -# configuration, error, and log files are kept. -# -# Do not add a slash at the end of the directory path. If you point -# ServerRoot at a non-local disk, be sure to point the LockFile directive -# at a local disk. If you wish to share the same ServerRoot for multiple -# httpd daemons, you will need to change at least LockFile and PidFile. -# -ServerRoot "/usr/local/apache2" - -# -# Listen: Allows you to bind Apache to specific IP addresses and/or -# ports, instead of the default. See also the -# directive. -# -# Change this to Listen on specific IP addresses as shown below to -# prevent Apache from glomming onto all bound IP addresses. -# -#Listen 12.34.56.78:80 -Listen 8088 - -# -# Dynamic Shared Object (DSO) Support -# -# To be able to use the functionality of a module which was built as a DSO you -# have to place corresponding `LoadModule' lines at this location so the -# directives contained in it are actually available _before_ they are used. -# Statically compiled modules (those listed by `httpd -l') do not need -# to be loaded here. -# -# Example: -# LoadModule foo_module modules/mod_foo.so -# - -LoadModule deflate_module modules/mod_deflate.so -LoadModule expires_module modules/mod_expires.so -LoadModule headers_module modules/mod_headers.so -LoadModule mime_magic_module modules/mod_mime_magic.so -LoadModule proxy_module modules/mod_proxy.so -LoadModule proxy_balancer_module modules/mod_proxy_balancer.so -LoadModule proxy_http_module modules/mod_proxy_http.so -LoadModule rewrite_module modules/mod_rewrite.so -LoadModule version_module modules/mod_version.so -LoadModule vhost_alias_module modules/mod_vhost_alias.so - - -# -# If you wish httpd to run as a different user or group, you must run -# httpd as root initially and it will switch. -# -# User/Group: The name (or #number) of the user/group to run httpd as. -# It is usually good practice to create a dedicated user and group for -# running httpd, as with most system services. -# -User www-data -Group www-data - - -# 'Main' server configuration -# -# The directives in this section set up the values used by the 'main' -# server, which responds to any requests that aren't handled by a -# definition. These values also provide defaults for -# any containers you may define later in the file. -# -# All of these directives may appear inside containers, -# in which case these default settings will be overridden for the -# virtual host being defined. -# - -# -# ServerAdmin: Your address, where problems with the server should be -# e-mailed. This address appears on some server-generated pages, such -# as error documents. e.g. admin@your-domain.com -# -ServerAdmin admin@SERVER - -# -# ServerName gives the name and port that the server uses to identify itself. -# This can often be determined automatically, but we recommend you specify -# it explicitly to prevent problems during startup. -# -# If your host doesn't have a registered DNS name, enter its IP address here. -# -ServerName SERVER:8088 - -# -# DocumentRoot: The directory out of which you will serve your -# documents. By default, all requests are taken from this directory, but -# symbolic links and aliases may be used to point to other locations. -# -DocumentRoot "/usr/local/apache2/htdocs" - -# -# Each directory to which Apache has access can be configured with respect -# to which services and features are allowed and/or disabled in that -# directory (and its subdirectories). -# -# First, we configure the "default" to be a very restrictive set of -# features. -# - - Options FollowSymLinks - AllowOverride None - Order deny,allow - Deny from all - - -# -# Note that from this point forward you must specifically allow -# particular features to be enabled - so if something's not working as -# you might expect, make sure that you have specifically enabled it -# below. -# - -# -# This should be changed to whatever you set DocumentRoot to. -# - - # - # Possible values for the Options directive are "None", "All", - # or any combination of: - # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews - # - # Note that "MultiViews" must be named *explicitly* --- "Options All" - # doesn't give it to you. - # - # The Options directive is both complicated and important. Please see - # http://httpd.apache.org/docs/2.2/mod/core.html#options - # for more information. - # - Options Indexes FollowSymLinks - - # - # AllowOverride controls what directives may be placed in .htaccess files. - # It can be "All", "None", or any combination of the keywords: - # Options FileInfo AuthConfig Limit - # - AllowOverride None - - # - # Controls who can get stuff from this server. - # - Order allow,deny - Allow from all - - - -# -# DirectoryIndex: sets the file that Apache will serve if a directory -# is requested. -# - - DirectoryIndex index.html - - -# -# The following lines prevent .htaccess and .htpasswd files from being -# viewed by Web clients. -# - - Order allow,deny - Deny from all - Satisfy All - - -# -# ErrorLog: The location of the error log file. -# If you do not specify an ErrorLog directive within a -# container, error messages relating to that virtual host will be -# logged here. If you *do* define an error logfile for a -# container, that host's errors will be logged there and not here. -# -ErrorLog logs/error_log - -# -# LogLevel: Control the number of messages logged to the error_log. -# Possible values include: debug, info, notice, warn, error, crit, -# alert, emerg. -# -LogLevel warn - - - # - # The following directives define some format nicknames for use with - # a CustomLog directive (see below). - # - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined - LogFormat "%h %l %u %t \"%r\" %>s %b" common - - - # You need to enable mod_logio.c to use %I and %O - LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio - - - # - # The location and format of the access logfile (Common Logfile Format). - # If you do not define any access logfiles within a - # container, they will be logged here. Contrariwise, if you *do* - # define per- access logfiles, transactions will be - # logged therein and *not* in this file. - # - CustomLog logs/access_log common - - # - # If you prefer a logfile with access, agent, and referer information - # (Combined Logfile Format) you can use the following directive. - # - #CustomLog logs/access_log combined - - - - # - # Redirect: Allows you to tell clients about documents that used to - # exist in your server's namespace, but do not anymore. The client - # will make a new request for the document at its new location. - # Example: - # Redirect permanent /foo http://www.example.com/bar - - # - # Alias: Maps web paths into filesystem paths and is used to - # access content that does not live under the DocumentRoot. - # Example: - # Alias /webpath /full/filesystem/path - # - # If you include a trailing / on /webpath then the server will - # require it to be present in the URL. You will also likely - # need to provide a section to allow access to - # the filesystem path. - - # - # ScriptAlias: This controls which directories contain server scripts. - # ScriptAliases are essentially the same as Aliases, except that - # documents in the target directory are treated as applications and - # run by the server when requested rather than as documents sent to the - # client. The same rules about trailing "/" apply to ScriptAlias - # directives as to Alias. - # - ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" - - - - - # - # ScriptSock: On threaded servers, designate the path to the UNIX - # socket used to communicate with the CGI daemon of mod_cgid. - # - #Scriptsock logs/cgisock - - -# -# "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased -# CGI directory exists, if you have that configured. -# - - AllowOverride None - Options None - Order allow,deny - Allow from all - - -# -# DefaultType: the default MIME type the server will use for a document -# if it cannot otherwise determine one, such as from filename extensions. -# If your server contains mostly text or HTML documents, "text/plain" is -# a good value. If most of your content is binary, such as applications -# or images, you may want to use "application/octet-stream" instead to -# keep browsers from trying to display binary files as though they are -# text. -# -DefaultType text/plain - - - # - # TypesConfig points to the file containing the list of mappings from - # filename extension to MIME-type. - # - TypesConfig conf/mime.types - - # - # AddType allows you to add to or override the MIME configuration - # file specified in TypesConfig for specific file types. - # - #AddType application/x-gzip .tgz - # - # AddEncoding allows you to have certain browsers uncompress - # information on the fly. Note: Not all browsers support this. - # - #AddEncoding x-compress .Z - #AddEncoding x-gzip .gz .tgz - # - # If the AddEncoding directives above are commented-out, then you - # probably should define those extensions to indicate media types: - # - AddType application/x-compress .Z - AddType application/x-gzip .gz .tgz - - # - # AddHandler allows you to map certain file extensions to "handlers": - # actions unrelated to filetype. These can be either built into the server - # or added with the Action directive (see below) - # - # To use CGI scripts outside of ScriptAliased directories: - # (You will also need to add "ExecCGI" to the "Options" directive.) - # - #AddHandler cgi-script .cgi - - # For type maps (negotiated resources): - #AddHandler type-map var - - # - # Filters allow you to process content before it is sent to the client. - # - # To parse .shtml files for server-side includes (SSI): - # (You will also need to add "Includes" to the "Options" directive.) - # - #AddType text/html .shtml - #AddOutputFilter INCLUDES .shtml - - -# -# The mod_mime_magic module allows the server to use various hints from the -# contents of the file itself to determine its type. The MIMEMagicFile -# directive tells the module where the hint definitions are located. -# -#MIMEMagicFile conf/magic - -# -# Customizable error responses come in three flavors: -# 1) plain text 2) local redirects 3) external redirects -# -# Some examples: -#ErrorDocument 500 "The server made a boo boo." -#ErrorDocument 404 /missing.html -#ErrorDocument 404 "/cgi-bin/missing_handler.pl" -#ErrorDocument 402 http://www.example.com/subscription_info.html -# - -# -# EnableMMAP and EnableSendfile: On systems that support it, -# memory-mapping or the sendfile syscall is used to deliver -# files. This usually improves server performance, but must -# be turned off when serving from networked-mounted -# filesystems or if support for these functions is otherwise -# broken on your system. -# -#EnableMMAP off -EnableSendfile on - -# Supplemental configuration -# -# The configuration files in the conf/extra/ directory can be -# included to add extra features or to modify the default configuration of -# the server, or you may simply copy their contents here and change as -# necessary. - -# Server-pool management (MPM specific) -#Include conf/extra/httpd-mpm.conf - -# Multi-language error messages -#Include conf/extra/httpd-multilang-errordoc.conf - -# Fancy directory listings -#Include conf/extra/httpd-autoindex.conf - -# Language settings -#Include conf/extra/httpd-languages.conf - -# User home directories -#Include conf/extra/httpd-userdir.conf - -# Real-time info on requests and configuration -#Include conf/extra/httpd-info.conf - -# Virtual hosts -#Include conf/extra/httpd-vhosts.conf - -# Local access to the Apache HTTP Server Manual -#Include conf/extra/httpd-manual.conf - -# Distributed authoring and versioning (WebDAV) -#Include conf/extra/httpd-dav.conf - -# Various default settings -#Include conf/extra/httpd-default.conf - -# Secure (SSL/TLS) connections -#Include conf/extra/httpd-ssl.conf -# -# Note: The following must must be present to support -# starting without SSL on platforms with no /dev/random equivalent -# but a statically compiled-in mod_ssl. -# - -SSLRandomSeed startup builtin -SSLRandomSeed connect builtin - - - - ServerName SERVER - DocumentRoot /var/rails/MYAPP/public - - - Options FollowSymLinks - AllowOverride None - Order allow,deny - Allow from all - - - # Configure mongrel_cluster - - BalancerMember http://127.0.0.1:8000 - BalancerMember http://127.0.0.1:8001 - - - RewriteEngine On - - # Uncomment for rewrite debugging - #RewriteLog logs/your_app_rewrite_log - #RewriteLogLevel 9 - - # Check for maintenance file and redirect all requests - RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f - RewriteCond %{SCRIPT_FILENAME} !maintenance.html - RewriteRule ^.*$ /system/maintenance.html [L] - - # Rewrite index to check for static - RewriteRule ^/$ /index.html [QSA] - - # Rewrite to check for Rails cached page - RewriteRule ^([^.]+)$ $1.html [QSA] - - # Redirect all non-static requests to cluster - RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f - RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] - - # Deflate - AddOutputFilterByType DEFLATE text/html text/plain text/xml - BrowserMatch ^Mozilla/4 gzip-only-text/html - BrowserMatch ^Mozilla/4\.0[678] no-gzip - BrowserMatch \bMSIE !no-gzip !gzip-only-text/html - - # Uncomment for deflate debugging - #DeflateFilterNote Input input_info - #DeflateFilterNote Output output_info - #DeflateFilterNote Ratio ratio_info - #LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate - #CustomLog logs/your_app_deflate_log deflate - - ErrorLog logs/your_app_error_log - CustomLog logs/your_access_log combined - - - diff --git a/examples/mime.yaml b/examples/mime.yaml deleted file mode 100644 index 6e7bb04..0000000 --- a/examples/mime.yaml +++ /dev/null @@ -1,3 +0,0 @@ ---- -.jpeg: image/jpeg -.png: image/test diff --git a/examples/mongrel.conf b/examples/mongrel.conf deleted file mode 100644 index 5c77707..0000000 --- a/examples/mongrel.conf +++ /dev/null @@ -1,9 +0,0 @@ ---- -:environment: production -:daemon: "true" -:host: 0.0.0.0 -:log_file: log/mongrel.log -:docroot: public -:debug: "false" -:port: 3000 -:pid_file: log/mongrel.pid diff --git a/examples/mongrel_simple_ctrl.rb b/examples/mongrel_simple_ctrl.rb deleted file mode 100644 index 4663d1c..0000000 --- a/examples/mongrel_simple_ctrl.rb +++ /dev/null @@ -1,92 +0,0 @@ -############################################### -# mongrel_simple_ctrl.rb -# -# Control script for the Mongrel server -############################################### -require "optparse" -require "win32/service" -include Win32 - -# I start the service name with an 'A' so that it appears at the top -SERVICE_NAME = "MongrelSvc" -SERVICE_DISPLAYNAME = "Mongrel HTTP Server" -SCRIPT_ROOT = File.join(File.dirname(__FILE__), '.') -SCRIPT_NAME = "mongrel_simple_service.rb" -SERVICE_SCRIPT = File.expand_path(SCRIPT_ROOT + '/' + SCRIPT_NAME) - -OPTIONS = {} - -ARGV.options do |opts| - opts.on("-d", "--delete", "Delete the service"){ OPTIONS[:delete] = true } - opts.on("-u", "--uninstall","Delete the service"){ OPTIONS[:uninstall] = true } - opts.on("-s", "--start", "Start the service"){ OPTIONS[:start] = true } - opts.on("-x", "--stop", "Stop the service"){ OPTIONS[:stop] = true } - opts.on("-i", "--install","Install the service"){ OPTIONS[:install] = true } - - opts.on("-h", "--help", "Show this help message."){ puts opts; exit } - - opts.parse! -end - -# Install the service -if OPTIONS[:install] - require 'rbconfig' - - svc = Service.new - svc.create_service{ |s| - s.service_name = SERVICE_NAME - s.display_name = SERVICE_DISPLAYNAME - s.binary_path_name = Config::CONFIG['bindir'] + '/ruby ' + SERVICE_SCRIPT - s.dependencies = [] - } - svc.close - puts "#{SERVICE_DISPLAYNAME} service installed" -end - -# Start the service -if OPTIONS[:start] - Service.start(SERVICE_NAME) - started = false - while started == false - s = Service.status(SERVICE_NAME) - started = true if s.current_state == "running" - break if started == true - puts "One moment, " + s.current_state - sleep 1 - end - puts "#{SERVICE_DISPLAYNAME} service started" -end - -# Stop the service -if OPTIONS[:stop] - Service.stop(SERVICE_NAME) - stopped = false - while stopped == false - s = Service.status(SERVICE_NAME) - stopped = true if s.current_state == "stopped" - break if stopped == true - puts "One moment, " + s.current_state - sleep 1 - end - puts "#{SERVICE_DISPLAYNAME} service stopped" -end - -# Delete the service. Stop it first. -if OPTIONS[:delete] || OPTIONS[:uninstall] - begin - Service.stop(SERVICE_NAME) - rescue - end - begin - Service.delete(SERVICE_NAME) - rescue - end - puts "#{SERVICE_DISPLAYNAME} service deleted" -end -# END mongrel_rails_ctrl.rb - - - - - - diff --git a/examples/mongrel_simple_service.rb b/examples/mongrel_simple_service.rb deleted file mode 100644 index 3f9bc2c..0000000 --- a/examples/mongrel_simple_service.rb +++ /dev/null @@ -1,116 +0,0 @@ -# This script emualtes script/server behavior but running webrick http server -require 'rubygems' - -require 'mongrel' -require 'yaml' -require 'zlib' - -require 'win32/service' - -DEBUG_LOG_FILE = File.expand_path(File.dirname(__FILE__) + '/debug.log') - -class SimpleHandler < Mongrel::HttpHandler - def process(request, response) - response.start do |head,out| - head["Content-Type"] = "text/html" - results = "Your request:
#{request.params.to_yaml}
View the files." - if request.params["HTTP_ACCEPT_ENCODING"] == "gzip,deflate" - head["Content-Encoding"] = "deflate" - # send it back deflated - out << Zlib::Deflate.deflate(results) - else - # no gzip supported, send it back normal - out << results - end - end - end -end - -class MongrelDaemon < Win32::Daemon - def initialize(options) - @options = options - end - - def service_init - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_init entered") } - - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("Mongrel running on #{@options[:ip]}:#{@options[:port]} with docroot #{@options[:server_root]}") } - - @simple = SimpleHandler.new - @files = Mongrel::DirHandler.new(@options[:server_root]) - - @http_server = Mongrel::HttpServer.new(@options[:ip], @options[:port]) - @http_server.register("/", @simple) - @http_server.register("/files", @files) - - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_init left") } - end - - def service_stop - File.open(DEBUG_LOG_FILE,"a+"){ |f| - f.puts "stop signal received: " + Time.now.to_s - f.puts "sending stop to mongrel threads: " + Time.now.to_s - } - #@http_server.stop - end - - def service_pause - File.open(DEBUG_LOG_FILE,"a+"){ |f| - f.puts "pause signal received: " + Time.now.to_s - } - end - - def service_resume - File.open(DEBUG_LOG_FILE,"a+"){ |f| - f.puts "continue/resume signal received: " + Time.now.to_s - } - end - - def service_main - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_main entered") } - - begin - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - http_server.run") } - @http_server.run - - # No runner thread was needed after all! - #@runner = Thread.new do - # @http_server.acceptor.join - #end - #File.open("d:\\test.log","a+") { |f| f.puts("#{Time.now} - runner.run") } - #@runner.run - - # here is where magic happens! - # if put blocking code here, the thread never left service_main, and the rb_func_call in service.c - # never exit, even if the stop signal is received. - # - # to probe my theory, just comment the while loop and remove the '1' from sleep function - # service start ok, but fail to stop. - # - # Even if no functional code is in service_main (because we have other working threads), - # we must monitor the state of the service to exit when the STOP event is received. - # - # Note: maybe not loop in 1 second intervals? - while state == RUNNING - sleep 1 - end - - rescue StandardError, Exception, interrupt => err - File.open(DEBUG_LOG_FILE,"a+"){ |f| f.puts("#{Time.now} - Error: #{err}") } - File.open(DEBUG_LOG_FILE,"a+"){ |f| f.puts("BACKTRACE: " + err.backtrace.join("\n")) } - - end - - File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_main left") } - end - -end - -OPTIONS = { - :port => 3000, - :ip => "0.0.0.0", - :server_root => File.expand_path(File.dirname(__FILE__)), -} - -web_server = MongrelDaemon.new(OPTIONS) -web_server.mainloop diff --git a/examples/monitrc b/examples/monitrc deleted file mode 100644 index 9964ae9..0000000 --- a/examples/monitrc +++ /dev/null @@ -1,57 +0,0 @@ -set daemon 60 -set logfile syslog facility log_daemon -set mailserver localhost -set mail-format { from: monit@localhost } -set alert root@localhost - -check process sshd with pidfile /var/run/sshd.pid - start program "/etc/init.d/ssh start" - stop program "/etc/init.d/ssh stop" - if failed port 22 protocol ssh then restart - if 5 restarts within 5 cycles then timeout - -check process mysql with pidfile /var/run/mysqld/mysqld.pid - group database - start program = "/etc/init.d/mysql start" - stop program = "/etc/init.d/mysql stop" - if failed host 127.0.0.1 port 3306 then restart - if 5 restarts within 5 cycles then timeout - -check process httpd with pidfile /usr/local/apache2/logs/httpd.pid - group www-data - start program "/usr/local/apache2/bin/apachectl start" - stop program "/usr/local/apache2/bin/apachectl stop" - if failed host localhost port 80 protocol http - and request "/" then alert - if cpu is greater than 60% for 2 cycles then alert - if cpu > 80% for 5 cycles then restart - if children > 250 then restart - if loadavg(5min) greater than 10 for 8 cycles then alert - if 3 restarts within 5 cycles then timeout - -check process mongrel_8000 with pidfile /var/rails/MYAPP/log/mongrel.8000.pid - group root - if failed host 127.0.0.1 port 8000 protocol http - and request "/" then alert - if cpu is greater than 60% for 2 cycles then alert - if cpu > 80% for 5 cycles then restart - if loadavg(5min) greater than 10 for 8 cycles then restart - if 3 restarts within 5 cycles then timeout - -check process mongrel_8001 with pidfile /var/rails/MYAPP/log/mongrel.8001.pid - group root - if failed host 127.0.0.1 port 8001 protocol http - and request "/" then alert - if cpu is greater than 60% for 2 cycles then alert - if cpu > 80% for 5 cycles then alert - if loadavg(5min) greater than 10 for 8 cycles then alert - if 3 restarts within 5 cycles then timeout - -check process postfix with pidfile /var/spool/postfix/pid/master.pid - group mail - start program = "/etc/init.d/postfix start" - stop program = "/etc/init.d/postfix stop" - if failed port 25 protocol smtp then restart - if 5 restarts within 5 cycles then timeout - - diff --git a/examples/random_thrash.rb b/examples/random_thrash.rb deleted file mode 100644 index fe9311c..0000000 --- a/examples/random_thrash.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'socket' -devrand = open("/dev/random","r") - -loop do - s = TCPSocket.new(ARGV[0],ARGV[1]) - s.write("GET / HTTP/1.1\r\n") - total = 0 - begin - loop do - r = devrand.read(10) - n = s.write(r) - total += n - end - rescue Object - STDERR.puts "#$!: #{total}" - end - s.close - sleep 1 -end diff --git a/examples/simpletest.rb b/examples/simpletest.rb deleted file mode 100644 index b82e2c6..0000000 --- a/examples/simpletest.rb +++ /dev/null @@ -1,52 +0,0 @@ -$LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib") -require 'mongrel' -require 'yaml' - -class SimpleHandler < Mongrel::HttpHandler - def process(request, response) - response.start do |head,out| - head["Content-Type"] = "text/html" - results = "Your request:
#{request.params.to_yaml}
View the files." - out << results - end - end -end - -class DumbHandler < Mongrel::HttpHandler - def process(request, response) - response.start do |head,out| - head["Content-Type"] = "text/html" - out.write("test") - end - end -end - - -if ARGV.length != 3 - STDERR.puts "usage: simpletest.rb " - exit(1) -end - -stats = Mongrel::StatisticsFilter.new(:sample_rate => 1) - -config = Mongrel::Configurator.new :host => ARGV[0], :port => ARGV[1] do - listener do - uri "/", :handler => SimpleHandler.new - uri "/", :handler => Mongrel::DeflateFilter.new - uri "/", :handler => stats - uri "/dumb", :handler => DumbHandler.new - uri "/dumb", :handler => Mongrel::DeflateFilter.new - uri "/dumb", :handler => stats - uri "/files", :handler => Mongrel::DirHandler.new(ARGV[2]) - uri "/files", :handler => stats - uri "/status", :handler => Mongrel::StatusHandler.new(:stats_filter => stats) - redirect "/redir1", "/" - redirect "/to", /to/, 'w' - end - - trap("INT") { stop } - run -end - -puts "Mongrel running on #{ARGV[0]}:#{ARGV[1]} with docroot #{ARGV[2]}" -config.join diff --git a/examples/webrick_compare.rb b/examples/webrick_compare.rb deleted file mode 100644 index 15199b0..0000000 --- a/examples/webrick_compare.rb +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/local/bin/ruby -require 'webrick' -include WEBrick - -s = HTTPServer.new( :Port => 4000 ) - -# HTTPServer#mount(path, servletclass) -# When a request referring "/hello" is received, -# the HTTPServer get an instance of servletclass -# and then call a method named do_"a HTTP method". - -class HelloServlet < HTTPServlet::AbstractServlet - def do_GET(req, res) - res.body = "hello!" - res['Content-Type'] = "text/html" - end -end -s.mount("/test", HelloServlet) - -s.start \ No newline at end of file -- cgit v1.2.3-24-ge0c7