Last active
August 29, 2015 14:26
-
-
Save kazu69/fb321bd71b19878bd99d to your computer and use it in GitHub Desktop.
Docker + h2o + mruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MRuby::Build.new do |conf| | |
toolchain :gcc | |
enable_debug | |
conf.gembox 'full-core' | |
# | |
# Recommended for ngx_mruby | |
# | |
conf.gem :github => 'iij/mruby-io' | |
conf.gem :github => 'iij/mruby-env' | |
conf.gem :github => 'iij/mruby-dir' | |
conf.gem :github => 'iij/mruby-digest' | |
conf.gem :github => 'iij/mruby-process' | |
conf.gem :github => 'iij/mruby-pack' | |
conf.gem :github => 'iij/mruby-socket' | |
conf.gem :github => 'mattn/mruby-json' | |
conf.gem :github => 'mattn/mruby-onig-regexp' | |
conf.gem :github => 'matsumoto-r/mruby-redis' | |
conf.gem :github => 'matsumoto-r/mruby-vedis' | |
conf.gem :github => 'matsumoto-r/mruby-sleep' | |
conf.gem :github => 'matsumoto-r/mruby-userdata' | |
conf.gem :github => 'matsumoto-r/mruby-uname' | |
conf.gem :github => 'matsumoto-r/mruby-mutex' | |
conf.gem :github => 'matsumoto-r/mruby-cache' | |
# ngx_mruby extended class | |
conf.gem '../mrbgems/ngx_mruby_mrblib' | |
# use memcached | |
# conf.gem :github => 'matsumoto-r/mruby-memcached' | |
# build error on travis ci 2014/12/01, commented out mruby-file-stat | |
# conf.gem :github => 'ksss/mruby-file-stat' | |
# use markdown on ngx_mruby | |
# conf.gem :github => 'matsumoto-r/mruby-discount' | |
# use mysql on ngx_mruby | |
#conf.gem :github => 'mattn/mruby-mysql' | |
# have GeoIPCity.dat | |
# conf.gem :github => 'matsumoto-r/mruby-geoip' | |
# Linux only for ngx_mruby | |
# conf.gem :github => 'matsumoto-r/mruby-capability' | |
# conf.gem :github => 'matsumoto-r/mruby-cgroup' | |
## user-defined GEMs | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# build_config.rb | |
MRuby::Build.new do |conf| | |
# load specific toolchain settings | |
# Gets set by the VS command prompts. | |
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] | |
toolchain :visualcpp | |
else | |
toolchain :gcc | |
end | |
enable_debug | |
# Use mrbgems | |
# conf.gem 'examples/mrbgems/ruby_extension_example' | |
# conf.gem 'examples/mrbgems/c_extension_example' do |g| | |
# g.cc.flags << '-g' # append cflags in this gem | |
# end | |
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example' | |
# conf.gem :github => 'masuidrive/mrbgems-example', :checksum_hash => '76518e8aecd131d047378448ac8055fa29d974a9' | |
# conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v' | |
# include the default GEMs | |
conf.gembox 'default' | |
# C compiler settings | |
# conf.cc do |cc| | |
# cc.command = ENV['CC'] || 'gcc' | |
# cc.flags = [ENV['CFLAGS'] || %w()] | |
# cc.include_paths = ["#{root}/include"] | |
# cc.defines = %w(DISABLE_GEMS) | |
# cc.option_include_path = '-I%s' | |
# cc.option_define = '-D%s' | |
# cc.compile_options = "%{flags} -MMD -o %{outfile} -c %{infile}" | |
# end | |
# mrbc settings | |
# conf.mrbc do |mrbc| | |
# mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers | |
# end | |
# Linker settings | |
# conf.linker do |linker| | |
# linker.command = ENV['LD'] || 'gcc' | |
# linker.flags = [ENV['LDFLAGS'] || []] | |
# linker.flags_before_libraries = [] | |
# linker.libraries = %w() | |
# linker.flags_after_libraries = [] | |
# linker.library_paths = [] | |
# linker.option_library = '-l%s' | |
# linker.option_library_path = '-L%s' | |
# linker.link_options = "%{flags} -o %{outfile} %{objs} %{libs}" | |
# end | |
# Archiver settings | |
# conf.archiver do |archiver| | |
# archiver.command = ENV['AR'] || 'ar' | |
# archiver.archive_options = 'rs %{outfile} %{objs}' | |
# end | |
# Parser generator settings | |
# conf.yacc do |yacc| | |
# yacc.command = ENV['YACC'] || 'bison' | |
# yacc.compile_options = '-o %{outfile} %{infile}' | |
# end | |
# gperf settings | |
# conf.gperf do |gperf| | |
# gperf.command = 'gperf' | |
# gperf.compile_options = '-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" %{infile} > %{outfile}' | |
# end | |
# file extensions | |
# conf.exts do |exts| | |
# exts.object = '.o' | |
# exts.executable = '' # '.exe' if Windows | |
# exts.library = '.a' | |
# end | |
# file separetor | |
# conf.file_separator = '/' | |
# bintest | |
# conf.enable_bintest | |
end | |
MRuby::Build.new('host-debug') do |conf| | |
# load specific toolchain settings | |
# Gets set by the VS command prompts. | |
if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] | |
toolchain :visualcpp | |
else | |
toolchain :gcc | |
end | |
enable_debug | |
# include the default GEMs | |
conf.gembox 'full-core' | |
# C compiler settings | |
conf.cc.defines = %w(ENABLE_DEBUG) | |
# Generate mruby debugger command (require mruby-eval) | |
conf.gem :core => "mruby-bin-debugger" | |
# add mgems | |
conf.gem :github => 'iij/mruby-io' | |
conf.gem :github => 'iij/mruby-env' | |
conf.gem :github => 'iij/mruby-dir' | |
conf.gem :github => 'iij/mruby-digest' | |
conf.gem :github => 'iij/mruby-process' | |
conf.gem :github => 'iij/mruby-pack' | |
conf.gem :github => 'iij/mruby-socket' | |
conf.gem :github => 'mattn/mruby-json' | |
conf.gem :github => 'mattn/mruby-onig-regexp' | |
conf.gem :github => 'matsumoto-r/mruby-userdata' | |
conf.gem :github => 'matsumoto-r/mruby-uname' | |
conf.gem :github => 'matsumoto-r/mruby-mutex' | |
conf.gem :github => 'matsumoto-r/mruby-cache' | |
# bintest | |
# conf.enable_bintest | |
end | |
# Define cross build settings | |
# MRuby::CrossBuild.new('32bit') do |conf| | |
# toolchain :gcc | |
# | |
# conf.cc.flags << "-m32" | |
# conf.linker.flags << "-m32" | |
# | |
# conf.build_mrbtest_lib_only | |
# | |
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example' | |
# | |
# conf.test_runner.command = 'env' | |
# | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t= 43 [st= 4] HTTP2_SESSION_RECV_PUSH_PROMISE | |
--> :authority: localhost:8443 | |
:method: GET | |
:path: /normalize.css | |
:scheme: https | |
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 | |
accept-encoding: gzip, deflate, sdch | |
accept-language: ja,en-US;q=0.8,en;q=0.6 | |
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36 | |
--> id = 2 | |
--> promised_stream_id = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu | |
RUN apt-get update | |
RUN apt-get install -y software-properties-common python-software-properties | |
RUN add-apt-repository -y ppa:brightbox/ruby-ng | |
RUN apt-get -y update | |
RUN apt-get install -y git ruby2.2 rake curl wget gcc make bison libssl-dev libcurl4-openssl-dev libpcre3 libpcre3-dev | |
WORKDIR /usr/local/src/ | |
RUN git clone git://github.com/matsumoto-r/ngx_mruby.git | |
WORKDIR /usr/local/src/ngx_mruby | |
RUN cp -p build_config.rb build_config.rb.org | |
ADD build_config.rb /usr/local/src/ngx_mruby/build_config.rb | |
ENV NGINX_CONFIG_OPT_ENV --with-http_ssl_module --prefix=/usr/local/nginx | |
RUN sh build.sh | |
RUN make install | |
# https://raw.githubusercontent.com/JasonGiedymin/nginx-init-ubuntu/master/nginx | |
ADD initScript.sh /etc/init.d/ | |
RUN mv /etc/init.d/initScript.sh /etc/init.d/nginx | |
RUN chmod +x /etc/init.d/nginx | |
RUN update-rc.d nginx defaults | |
ADD conf/nginx.conf /usr/local/nginx/conf/nginx.conf | |
ADD hook /usr/local/nginx/hook | |
ADD html /usr/local/nginx/html | |
EXPOSE 80 443 | |
CMD service nginx start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nginxコンテナ作成 | |
# Dockerfileは nginx/Dockerfile にある | |
docker build -t nginx:proxy nginx/ | |
# nginxを起動 | |
# 今回はnginxのipが必要 | |
CID=$(docker run -d nginx:proxy) | |
# nginxのip | |
docker inspect --format '{{ .NetworkSettings.IPAddress }}' ${CID} | |
172.17.0.73 | |
# nginxのipをproxy先に追加してh2oをビルドする | |
# h2oコンテナ作成 | |
docker build -t h2o_mruby:build . | |
# imageの確認 | |
docker images | |
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE | |
h2o_mruby build 46882ad4f96f 46 minutes ago 795.3 MB | |
nginx proxy e3ae6cc26b5f 47 minutes ago 585.8 MB | |
ubuntu latest d2a0ecffe6fa 3 weeks ago 188.4 MB | |
# h2oを起動 | |
# nginxにリンク | |
docker run -p 80:80 -p 443:443 -link thirsty_galileo -d h2o_mruby:build | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu | |
RUN apt-get update | |
RUN apt-get install -y software-properties-common python-software-properties | |
RUN add-apt-repository -y ppa:brightbox/ruby-ng | |
RUN apt-get -y update | |
RUN apt-get install -y git ruby2.2 rake curl wget gcc make bison libssl-dev libcurl4-openssl-dev libpcre3 libpcre3-dev cmake build-essential libyaml-dev automake python-geoip | |
WORKDIR /usr/local/src/ | |
RUN git clone https://github.com/mruby/mruby.git | |
WORKDIR /usr/local/src/mruby | |
RUN mv build_config.rb build_config.rb.org | |
ADD conf/build_config.rb /usr/local/src/mruby/build_config.rb | |
RUN make | |
RUN cp build/host/lib/libmruby.a build/host/lib/libmruby_core.a /usr/lib/. | |
RUN cp -r include/* /usr/include/. | |
WORKDIR /usr/local/src/ | |
RUN git clone git://github.com/h2o/h2o.git | |
WORKDIR /usr/local/src/h2o/ | |
RUN cmake -DWITH_MRUBY=ON -DCMAKE_INSTALL_PREFIX=/usr/local . | |
RUN make | |
RUN make install | |
RUN mkdir -p /usr/local/h2o/conf | |
RUN cp examples/h2o/h2o.conf /usr/local/h2o/conf/ | |
WORKDIR /etc/h2o/ssl/ | |
RUN openssl genrsa -out server.key 2048 ; openssl req -new -key server.key -out server.csr -subj '/C=JP/ST=Tokyo/L=Tokyo/O=Example Ltd./OU=Web/CN=localhost' ; openssl x509 -in server.csr -days 3650 -req -signkey server.key > server.crt | |
ADD conf/h2o.conf /usr/local/h2o/conf/h2o.conf | |
ADD hook /usr/local/h2o/hook | |
ADD html /usr/local/h2o/html | |
EXPOSE 80 443 | |
CMD /usr/local/bin/h2o -c /usr/local/h2o/conf/h2o.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# conf/h2o.conf | |
listen: 80 | |
listen: | |
port: 443 | |
ssl: | |
certificate-file: /etc/h2o/ssl/server.crt | |
key-file: /etc/h2o/ssl/server.key | |
hosts: | |
"default": | |
paths: | |
/: | |
proxy.reverse.url: http://172.17.0.73/ | |
/hello: | |
file.dir: /usr/local/h2o/html | |
mruby.handler_path: /usr/local/h2o/hook/hello.rb | |
/remote_ip: | |
file.dir: /usr/local/h2o/html | |
mruby.handler_path: /usr/local/h2o/hook/remote_ip.rb | |
access-log: /dev/stdout | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook/hello | |
r = H2O::Request.new | |
ua = r.headers_in["User-Agent"].to_s | |
new_ua = r.headers_in["User-Agent"] = "new-#{ua}-h2o_mruby" | |
uri = r.uri | |
host = r.hostname | |
method = r.method | |
query = r.query | |
msg = "User-Agent:#{ua}\nNew User-Agent:#{new_ua}\npath:#{uri}\nhost:#{host}\nmethod:#{method}\nquery:#{query}\nremote_ip:#{H2O::Connection.new.remote_ip}" | |
r.log_error msg | |
H2O.return 200, "OK", msg + "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Response Headers | |
accept-ranges:bytes | |
content-type:text/html | |
date:Wed, 05 Aug 2015 15:56:47 GMT | |
etag:"55c0b275-f1" | |
last-modified:Tue, 04 Aug 2015 12:39:17 GMT | |
link:<normalize.css>; rel=preload; as=stylesheet | |
server:h2o/1.4.2 | |
status:200 | |
Request Headers | |
:authority:localhost:8443 | |
:method:GET | |
:path:/ | |
:scheme:https | |
accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 | |
accept-encoding:gzip, deflate, sdch | |
accept-language:ja,en-US;q=0.8,en;q=0.6 | |
cache-control:no-cache | |
cookie:username=****** | |
dnt:1 | |
https:1 | |
pragma:no-cache | |
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- hhtml/index.html --> | |
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello H20 with mruby</title> | |
<link rel="stylesheet" href="normalize.css"> | |
<script src="lodash.js"></script> | |
</head> | |
<body> | |
It's Works! | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: $remote_fs $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: nginx init.d dash script for Ubuntu or other *nix. | |
# Description: nginx init.d dash script for Ubuntu or other *nix. | |
### END INIT INFO | |
#------------------------------------------------------------------------------ | |
# nginx - this Debian Almquist shell (dash) script, starts and stops the nginx | |
# daemon for Ubuntu and other *nix releases. | |
# | |
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ | |
# proxy and IMAP/POP3 proxy server. This \ | |
# script will manage the initiation of the \ | |
# server and it's process state. | |
# | |
# processname: nginx | |
# config: /usr/local/nginx/conf/nginx.conf | |
# pidfile: /usr/local/nginx/logs/nginx.pid | |
# Provides: nginx | |
# | |
# Author: Jason Giedymin | |
# <jason.giedymin AT gmail.com>. | |
# | |
# Version: 3.9.0 12-MAY-2015 jason.giedymin AT gmail.com | |
# Notes: nginx init.d dash script for Ubuntu. | |
# Tested with: Ubuntu 14.10, nginx-1.7.9 | |
# | |
# This script's project home is: | |
# http://github.com/JasonGiedymin/nginx-init-ubuntu | |
# | |
#------------------------------------------------------------------------------ | |
# MIT X11 License | |
#------------------------------------------------------------------------------ | |
# | |
# Copyright (c) 2008-2013 Jason Giedymin, http://jasongiedymin.com | |
# | |
# 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. | |
#------------------------------------------------------------------------------ | |
#------------------------------------------------------------------------------ | |
# Functions | |
#------------------------------------------------------------------------------ | |
LSB_FUNC=/lib/lsb/init-functions | |
# Test that init functions exists | |
test -r $LSB_FUNC || { | |
echo "$0: Cannot find $LSB_FUNC! Script exiting." 1>&2 | |
exit 5 | |
} | |
. $LSB_FUNC | |
#------------------------------------------------------------------------------ | |
# Consts | |
#------------------------------------------------------------------------------ | |
# Include nginx defaults if available | |
if [ -f /etc/default/nginx ]; then | |
. /etc/default/nginx | |
fi | |
# Minimize path | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
PS=${PS:-"nginx"} # process name | |
DESCRIPTION=${DESCRIPTION:-"Nginx Server..."} # process description | |
NGINXPATH=${NGINXPATH:-/usr/local/nginx} # root path where installed | |
DAEMON=${DAEMON:-$NGINXPATH/sbin/nginx} # path to daemon binary | |
NGINX_CONF_FILE=${NGINX_CONF_FILE:-$NGINXPATH/conf/nginx.conf} # config file path | |
PIDNAME=${PIDNAME:-"nginx"} # lets you do $PS-slave | |
PIDFILE=${PIDFILE:-$PIDNAME.pid} # pid file | |
PIDSPATH=${PIDSPATH:-$NGINXPATH/logs} # default pid location, you should change it | |
RUNAS=${RUNAS:-root} # user to run as | |
SCRIPT_OK=0 # ala error codes | |
SCRIPT_ERROR=1 # ala error codes | |
TRUE=1 # boolean | |
FALSE=0 # boolean | |
#------------------------------------------------------------------------------ | |
# Simple Tests | |
#------------------------------------------------------------------------------ | |
# Test if nginx is a file and executable | |
test -x $DAEMON || { | |
echo "$0: You don't have permissions to execute nginx." 1>&2 | |
exit 4 | |
} | |
# You can also set your conditions like so: | |
# set exit condition | |
# set -e | |
#------------------------------------------------------------------------------ | |
# Functions | |
#------------------------------------------------------------------------------ | |
setFilePerms(){ | |
if [ -f $PIDSPATH/$PIDFILE ]; then | |
chmod 400 $PIDSPATH/$PIDFILE | |
fi | |
} | |
configtest() { | |
$DAEMON -t -c $NGINX_CONF_FILE | |
} | |
getPSCount() { | |
return `pgrep -f $PS | wc -l` | |
} | |
isRunning() { | |
if [ $1 ]; then | |
pidof_daemon $1 | |
PID=$? | |
if [ $PID -gt 0 ]; then | |
return 1 | |
else | |
return 0 | |
fi | |
else | |
pidof_daemon | |
PID=$? | |
if [ $PID -gt 0 ]; then | |
return 1 | |
else | |
return 0 | |
fi | |
fi | |
} | |
#courtesy of php-fpm | |
wait_for_pid () { | |
try=0 | |
while test $try -lt 35 ; do | |
case "$1" in | |
'created') | |
if [ -f "$2" ]; then | |
try='' | |
break | |
fi | |
;; | |
'removed') | |
if [ ! -f "$2" ]; then | |
try='' | |
break | |
fi | |
;; | |
esac | |
try=`expr $try + 1` | |
sleep 1 | |
done | |
} | |
status(){ | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
log_warning_msg "$DESCRIPTION found running with processes: `pidof $PS`" | |
rc=0 | |
else | |
log_warning_msg "$DESCRIPTION is NOT running." | |
rc=3 | |
fi | |
return | |
} | |
removePIDFile(){ | |
if [ $1 ]; then | |
if [ -f $1 ]; then | |
rm -f $1 | |
fi | |
else | |
#Do default removal | |
if [ -f $PIDSPATH/$PIDFILE ]; then | |
rm -f $PIDSPATH/$PIDFILE | |
fi | |
fi | |
} | |
start() { | |
log_daemon_msg "Starting $DESCRIPTION" | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
log_end_msg $SCRIPT_ERROR | |
rc=0 | |
else | |
start-stop-daemon --start --quiet --chuid \ | |
$RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON \ | |
-- -c $NGINX_CONF_FILE | |
status=$? | |
setFilePerms | |
if [ "${status}" -eq 0 ]; then | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
else | |
log_end_msg $SCRIPT_ERROR | |
rc=7 | |
fi | |
fi | |
return | |
} | |
stop() { | |
log_daemon_msg "Stopping $DESCRIPTION" | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE | |
wait_for_pid 'removed' $PIDSPATH/$PIDFILE | |
if [ -n "$try" ]; then | |
log_end_msg $SCRIPT_ERROR | |
rc=0 # lsb states 1, but under status it is 2 (which is more prescriptive). Deferring to standard. | |
else | |
removePIDFile | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
fi | |
else | |
log_end_msg $SCRIPT_ERROR | |
rc=7 | |
fi | |
return | |
} | |
reload() { | |
configtest || return $? | |
log_daemon_msg "Reloading (via HUP) $DESCRIPTION" | |
isRunning | |
if [ $? -eq $TRUE ]; then | |
kill -HUP `cat $PIDSPATH/$PIDFILE` | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
else | |
log_end_msg $SCRIPT_ERROR | |
rc=7 | |
fi | |
return | |
} | |
quietupgrade() { | |
log_daemon_msg "Peforming Quiet Upgrade $DESCRIPTION" | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
kill -USR2 `cat $PIDSPATH/$PIDFILE` | |
kill -WINCH `cat $PIDSPATH/$PIDFILE.oldbin` | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin` | |
wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin | |
removePIDFile $PIDSPATH/$PIDFILE.oldbin | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
else | |
log_end_msg $SCRIPT_ERROR | |
log_daemon_msg "ERROR! Reverting back to original $DESCRIPTION" | |
kill -HUP `cat $PIDSPATH/$PIDFILE` | |
kill -TERM `cat $PIDSPATH/$PIDFILE.oldbin` | |
kill -QUIT `cat $PIDSPATH/$PIDFILE.oldbin` | |
wait_for_pid 'removed' $PIDSPATH/$PIDFILE.oldbin | |
removePIDFile $PIDSPATH/$PIDFILE.oldbin | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
fi | |
else | |
log_end_msg $SCRIPT_ERROR | |
rc=7 | |
fi | |
return | |
} | |
terminate() { | |
log_daemon_msg "Force terminating (via KILL) $DESCRIPTION" | |
PIDS=`pidof $PS` || true | |
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE` | |
for i in $PIDS; do | |
if [ "$i" = "$PIDS2" ]; then | |
kill $i | |
wait_for_pid 'removed' $PIDSPATH/$PIDFILE | |
removePIDFile | |
fi | |
done | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
} | |
destroy() { | |
log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION" | |
killall $PS -q >> /dev/null 2>&1 | |
log_end_msg $SCRIPT_OK | |
rc=0 | |
} | |
pidof_daemon() { | |
PIDS=`pidof $PS` || true | |
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE` | |
for i in $PIDS; do | |
if [ "$i" = "$PIDS2" ]; then | |
return 1 | |
fi | |
done | |
return 0 | |
} | |
action="$1" | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|force-reload) | |
stop | |
# if [ $rc -ne 0 ]; then | |
# script_exit | |
# fi | |
sleep 1 | |
start | |
;; | |
reload) | |
$1 | |
;; | |
status) | |
status | |
;; | |
configtest) | |
$1 | |
;; | |
quietupgrade) | |
$1 | |
;; | |
terminate) | |
$1 | |
;; | |
destroy) | |
$1 | |
;; | |
*) | |
FULLPATH=/etc/init.d/$PS | |
echo "Usage: $FULLPATH {start|stop|restart|force-reload|reload|status|configtest|quietupgrade|terminate|destroy}" | |
echo " The 'destroy' command should only be used as a last resort." | |
exit 3 | |
;; | |
esac | |
exit $rc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook/modify_header.rb | |
r = Nginx::Request.new | |
if r.headers_in["Accept"].include? 'text/html' | |
r.headers_out["Link"] = "<normalize.css>; rel=preload; as=stylesheet" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#user nobody; | |
worker_processes 1; | |
daemon off; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
#log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
# '$status $body_bytes_sent "$http_referer" ' | |
# '"$http_user_agent" "$http_x_forwarded_for"'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
server { | |
listen 80; | |
server_name localhost; | |
#charset koi8-r; | |
#access_log logs/host.access.log main; | |
root html; | |
location / { | |
index index.html index.htm; | |
mruby_access_handler /usr/local/nginx/hook/modify_header.rb; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# fastcgi_index index.php; | |
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\.ht { | |
# deny all; | |
#} | |
} | |
# another virtual host using mix of IP-, name-, and port-based configuration | |
# | |
#server { | |
# listen 8000; | |
# listen somename:8080; | |
# server_name somename alias another.alias; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
# HTTPS server | |
# | |
#server { | |
# listen 443 ssl; | |
# server_name localhost; | |
# ssl_certificate cert.pem; | |
# ssl_certificate_key cert.key; | |
# ssl_session_cache shared:SSL:1m; | |
# ssl_session_timeout 5m; | |
# ssl_ciphers HIGH:!aNULL:!MD5; | |
# ssl_prefer_server_ciphers on; | |
# location / { | |
# root html; | |
# index index.html index.htm; | |
# } | |
#} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# guest:80 -> host:8080 | |
VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-8080,tcp,127.0.0.1,8080,,80" | |
# guest:443 -> host:8443 | |
VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-8443,tcp,127.0.0.1,8443,,443" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hook/remote_ip.rb | |
remote_ip = H2O::Connection.new.remote_ip | |
H2O.return 200, 'OK', remote_ip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------- --------- --------- -------- | |
| h20 | - (proxy) -> | nginx | - (add Link header) -> | h20 | - (server push) -> | client | | |
--------- --------- --------- -------- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
├── Dockerfile | |
├── conf | |
│ ├── build_config.rb | |
│ └── h2o.conf | |
├── hook | |
│ ├── hello.rb | |
│ └── remote_ip.rb | |
│── html | |
└── nginx | |
├── Dockerfile | |
├── build_config.rb | |
├── conf | |
│ └── nginx.conf | |
├── hook | |
│ └── mod_header.rb | |
├── html | |
│ ├── index.html | |
│ ├── lodash.js | |
│ └── normalize.css | |
└── initScript.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment