Skip to content

Instantly share code, notes, and snippets.

@koseki
Created September 14, 2009 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koseki/186628 to your computer and use it in GitHub Desktop.
Save koseki/186628 to your computer and use it in GitHub Desktop.
Apache Module Test Env Setup Script (for EC2 ami-e048af89)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /root.php
#! /bin/sh
# ----------------------------------------------------------------
# Amazon EC2 ami-e048af89 (debian 6.0 squeeze)
# ----------------------------------------------------------------
# install git and rake.
apt-get update
apt-get -y install libidn11-dev
apt-get -y install git-core
apt-get -y install rubygems
gem install rake
ln -s /var/lib/gems/1.8/bin/rake /usr/local/bin/rake
# checkout source and execute rake.
cd /usr/local/src
git clone git://gist.github.com/186628.git modtest
cd modtest
rake
xxx/index.html
DocumentRoot /usr/local/src/modtest/htdocs
DirectoryIndex index.php index.html
RewriteEngine On
RewriteLog logs/error_log
RewriteLogLevel 9
<Directory "/usr/local/src/modtest/htdocs">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
DocumentRoot /usr/local/src/modtest/htdocs
DirectoryIndex index.php index.html
RewriteEngine On
RewriteLog logs/error_log
RewriteLogLevel 9
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule . /root.php
<Directory "/usr/local/src/modtest/htdocs">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
task :default => [
:install_env, :install_apache,
:patch_moddir, :install_moddir,
:patch_httpdconf, :link_directory_conf,
:start
]
desc "テスト環境を整えます。"
task :install_env do
sh <<'EOSH'
apt-get update
apt-get -y install less
apt-get -y install zlib1g-dev
apt-get -y install zip
apt-get -y install emacs22
EOSH
end
desc "apacheをコンパイルしてインストールします。"
task :install_apache do
sh <<'EOSH'
cd /usr/local/src
wget http://apache.mirror.facebook.net/httpd/httpd-2.2.13.tar.gz
tar xzf httpd-2.2.13.tar.gz
cd httpd-2.2.13
./configure --enable-mods-shared=all
make
make install
EOSH
end
desc "mod_dirをコンパイルします。"
task :build_moddir do
sh <<'EOSH'
cd /usr/local/src/httpd-2.2.13/modules/mappers
/usr/local/apache2/bin/apxs -c mod_dir.c
EOSH
end
desc "mod_dirをコンパイルしてインストールします。"
task :install_moddir do
sh <<'EOSH'
cd /usr/local/src/httpd-2.2.13/modules/mappers
/usr/local/apache2/bin/apxs -i -c mod_dir.c
EOSH
end
desc "mod_dirの状態を調べます。"
task :check_moddir do
sh <<'EOSH'
echo "--- INSTALLED ---"
ls -l /usr/local/apache2/modules/mod_dir.so
md5sum /usr/local/apache2/modules/mod_dir.so
echo "--- SOURCE ---"
ls -l /usr/local/src/httpd-2.2.13/modules/mappers/.libs/mod_dir.so
md5sum /usr/local/src/httpd-2.2.13/modules/mappers/.libs/mod_dir.so
EOSH
end
desc "mod_dir.cにログ出力を追加するパッチをあてます。"
task :patch_moddir do
sh <<'EOSH'
cd /usr/local/src/httpd-2.2.13/modules/mappers
cat <<EOF | patch
--- mod_dir.c.org 2009-09-16 07:54:06.000000000 +0900
+++ mod_dir.c 2009-09-19 13:25:15.000000000 +0900
@@ -180,8 +180,16 @@
name_ptr = apr_pstrcat(r->pool, name_ptr, "?", r->args, NULL);
}
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-0 r->uri %s / r->filename %s", r->uri, r->filename);
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-0 name_ptr %s", name_ptr);
+
rr = ap_sub_req_lookup_uri(name_ptr, r, NULL);
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-1 rr->uri %s / rr->filename %s", rr->uri, rr->filename);
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-1 handler %s", rr->handler);
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-1 filetype %d", rr->finfo.filetype);
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-1 APR_REG %d", APR_REG);
+
/* The sub request lookup is very liberal, and the core map_to_storage
* handler will almost always result in HTTP_OK as /foo/index.html
* may be /foo with PATH_INFO="/index.html", or even / with
@@ -195,6 +203,7 @@
if (rr->status == HTTP_OK
&& ( (rr->handler && !strcmp(rr->handler, "proxy-server"))
|| rr->finfo.filetype == APR_REG)) {
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-2 fast_redirect");
ap_internal_fast_redirect(rr, r);
return OK;
}
@@ -229,6 +238,7 @@
error_notfound = rr->status;
}
+ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "XXX dir-3 destroy_sub_req");
ap_destroy_sub_req(rr);
}
EOF
EOSH
end
desc "httpd.confにパッチをあてます。"
task :patch_httpdconf do
sh <<'EOSH'
cd /usr/local/apache2/conf
cat <<EOF | patch
--- httpd.conf.org 2009-09-20 17:13:50.000000000 +0000
+++ httpd.conf 2009-09-20 17:36:23.000000000 +0000
@@ -151,7 +151,7 @@
# 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"
+# DocumentRoot "/usr/local/apache2/htdocs"
#
# Each directory to which Apache has access can be configured with respect
@@ -212,9 +212,9 @@
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
-<IfModule dir_module>
- DirectoryIndex index.html
-</IfModule>
+# <IfModule dir_module>
+# DirectoryIndex index.html
+# </IfModule>
#
# The following lines prevent .htaccess and .htpasswd files from being
@@ -457,3 +457,5 @@
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
+
+Include /usr/local/src/modtest/conf/modtest.conf
EOF
EOSH
end
desc "ログを表示します。"
task :log do
sh %{tail -f /usr/local/apache2/logs/error_log}
end
task :link_server_conf do
src = '/usr/local/src/modtest/conf/modtest-server.conf'
dst = '/usr/local/src/modtest/conf/modtest.conf'
rm_f dst
symlink src, dst
end
task :link_directory_conf do
src = '/usr/local/src/modtest/conf/modtest-directory.conf'
dst = '/usr/local/src/modtest/conf/modtest.conf'
rm_f dst
symlink src, dst
end
desc "Apacheを起動します。"
task :start do
sh %{/usr/local/apache2/bin/apachectl start}
end
desc "Apacheを停止します。"
task :stop do
sh %{/usr/local/apache2/bin/apachectl stop}
end
desc "Apacheを再起動します。"
task :restart do
sh %{/usr/local/apache2/bin/apachectl restart}
end
desc "リライト設定をサーバに切り替えます。"
task :server_conf => [:link_server_conf, :restart]
desc "リライト設定をディレクトリに切り替えます。"
task :directory_conf => [:link_directory_conf, :restart]
desc "xxx/index.htmlを不可視にします。"
task :hide_index do
src = '/usr/local/src/modtest/htdocs/xxx/index.html'
dst = '/usr/local/src/modtest/htdocs/xxx/index.html.org'
mv src, dst
end
desc "xxx/index.htmlを可視にします。"
task :show_index do
src = '/usr/local/src/modtest/htdocs/xxx/index.html.org'
dst = '/usr/local/src/modtest/htdocs/xxx/index.html'
mv src, dst
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment