-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sample apps under some supervisor tools
- Loading branch information
1 parent
460e104
commit 1295cb5
Showing
28 changed files
with
767 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM ruby:2.7.4 | ||
|
||
RUN apt-get update -qq && apt-get install wget && apt-get install psmisc | ||
|
||
WORKDIR /sample | ||
COPY ["./src/Gemfile", "./"] | ||
|
||
RUN gem install bundler --version 1.17.2 | ||
|
||
# See: http://cr.yp.to/daemontools/install.html | ||
# See: http://cr.yp.to/daemontools/start.html | ||
# See: http://thedjbway.b0llix.net/daemontools/installation.html | ||
RUN mkdir -p /package && chmod 1755 /package && cd /package && \ | ||
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz && gunzip daemontools-0.76.tar && tar -xpf daemontools-0.76.tar && rm -f daemontools-0.76.tar && \ | ||
cd admin/daemontools-0.76 && \ | ||
wget http://thedjbway.b0llix.net/patches/daemontools-0.76.sigq12.patch && patch -t -p1 < ./daemontools-0.76.sigq12.patch && \ | ||
wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch && patch -t -p1 < ./daemontools-0.76.errno.patch && \ | ||
package/install && \ | ||
mkdir -p /service && chmod 755 /service | ||
|
||
COPY ["./run", "/service/sample_server/run"] | ||
|
||
RUN mkdir -p /service/sample_server/log && echo "#!/bin/sh\\nexec multilog t ./main" >> /service/sample_server/log/run && chmod 755 /service/sample_server/log/run && \ | ||
chmod +t /service/sample_server | ||
|
||
COPY . /sample |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Playground: Unicorn Graceful Restart under daemontools | ||
|
||
```sh | ||
docker image build --file ./Dockerfile --tag sample_unicorn_daemontools:t01 --rm . | ||
docker container run -it --rm sample_unicorn_daemontools:t01 /bin/bash | ||
``` | ||
|
||
```bash | ||
/command/svscanboot & | ||
|
||
pstree --show-pids | ||
ps -f -o user,pid,ppid,start,command --forest | ||
|
||
svstat /service/sample_server/ | ||
|
||
curl localhost:8080 -w "\n" | ||
|
||
# Graceful Restart | ||
svc -2 /service/sample_server # SIGUSR2 + QUIT to old master. See unicorn.conf.rb | ||
pstree --show-pids | ||
ps -f -o user,pid,ppid,start,command --forest | ||
|
||
svstat /service/sample_server/ | ||
svstat /service/sample_server/ | ||
svstat /service/sample_server/ # => pid が毎回変わってることが確認できる | ||
|
||
cat unicorn_stderr.log # => エラーで永遠に失敗してるのがわかる | ||
|
||
tai64nlocal < /service/sample_server/log/main/current | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
exec 2>&1 \ | ||
sh -c ' | ||
cd /sample | ||
bundle install | ||
exec bundle exec unicorn ./src/config.ru --config-file ./src/unicorn.conf_with_fork_hook.rb | ||
' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'unicorn', '~> 6.0' | ||
gem 'rack', '~> 2.2', '>= 2.2.3' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# coding: utf-8 | ||
|
||
require_relative 'sample.rb' | ||
run Sample.new |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Sample | ||
def call(env) | ||
[ | ||
200, | ||
{ 'Content-Type' => 'text/html' }, | ||
['ok'], | ||
] | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# See: https://github.com/defunkt/unicorn/blob/master/examples/unicorn.conf.minimal.rb | ||
# See: https://github.com/defunkt/unicorn/blob/master/examples/unicorn.conf.rb | ||
|
||
worker_processes 2 | ||
|
||
stderr_path './unicorn_stderr.log' | ||
stdout_path './unicorn_stdout.log' | ||
|
||
pid 'unicorn.pid' | ||
|
||
listen 8080, :tcp_nopush => true | ||
|
||
# See: https://github.com/defunkt/unicorn/blob/93e154e16b87f943a20fa720e002c67c9d17c30b/examples/unicorn.conf.rb#L71 | ||
before_fork do |server, worker| | ||
# The following is only recommended for memory/DB-constrained | ||
# installations. It is not needed if your system can house | ||
# twice as many worker_processes as you have configured. | ||
|
||
# This allows a new master process to incrementally | ||
# phase out the old master process with SIGTTOU to avoid a | ||
# thundering herd (especially in the "preload_app false" case) | ||
# when doing a transparent upgrade. The last worker spawned | ||
# will then kill off the old master process with a SIGQUIT. | ||
old_pid = "#{server.config[:pid]}.oldbin" | ||
if old_pid != server.pid | ||
begin | ||
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU | ||
Process.kill(sig, File.read(old_pid).to_i) | ||
rescue Errno::ENOENT, Errno::ESRCH | ||
end | ||
end | ||
|
||
# Throttle the master from forking too quickly by sleeping. Due | ||
# to the implementation of standard Unix signal handlers, this | ||
# helps (but does not completely) prevent identical, repeated signals | ||
# from being lost when the receiving process is busy. | ||
sleep 1 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
FROM ruby:2.6.2 | ||
|
||
WORKDIR /sample | ||
|
||
RUN apt-get update -qq && apt-get install -y wget psmisc gcc perlbrew | ||
|
||
# See: http://cr.yp.to/daemontools/install.html | ||
# See: http://cr.yp.to/daemontools/start.html | ||
# See: http://thedjbway.b0llix.net/daemontools/installation.html | ||
RUN mkdir -p /package && chmod 1755 /package && cd /package && \ | ||
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz && gunzip daemontools-0.76.tar && tar -xpf daemontools-0.76.tar && rm -f daemontools-0.76.tar && \ | ||
cd admin/daemontools-0.76 && \ | ||
wget http://thedjbway.b0llix.net/patches/daemontools-0.76.sigq12.patch && patch -t -p1 < ./daemontools-0.76.sigq12.patch && \ | ||
wget http://qmail.org/moni.csi.hu/pub/glibc-2.3.1/daemontools-0.76.errno.patch && patch -t -p1 < ./daemontools-0.76.errno.patch && \ | ||
package/install && \ | ||
mkdir -p /service && chmod 755 /service | ||
|
||
RUN mkdir -p /service/sample_server/log && echo "#!/bin/sh\\nexec multilog t ./main" >> /service/sample_server/log/run && chmod 755 /service/sample_server/log/run && \ | ||
chmod +t /service/sample_server | ||
|
||
ENV PERLBREW_ROOT=/perl5 | ||
RUN perlbrew available && perlbrew init && \ | ||
echo ". ${PERLBREW_ROOT}/etc/bashrc" >> ~/.bashrc && \ | ||
mkdir -p ${PERLBREW_ROOT}/perl-5.16.1 && mkdir -p ${PERLBREW_ROOT}/dists && mkdir -p ${PERLBREW_ROOT}/build/perl-5.16.1 && \ | ||
perlbrew install perl-5.16.1 --notest && \ | ||
echo ". ${PERLBREW_ROOT}/perls/perl-5.16.1/bin" >> /.bashrc && \ | ||
echo ". ${PERLBREW_ROOT}/bin" >> /.bashrc && \ | ||
perlbrew switch perl-5.16.1 && \ | ||
perlbrew install-cpanm && \ | ||
/perl5/bin/cpanm KAZUHO/Server-Starter-0.35.tar.gz --notest | ||
|
||
COPY ["./src/Gemfile", "./"] | ||
COPY ["./src/Gemfile.lock", "./"] | ||
RUN gem install bundler --version 1.17.3 && bundle install | ||
|
||
COPY ["./run", "/service/sample_server/run"] | ||
|
||
COPY . /sample |
Oops, something went wrong.