-
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.
Merge pull request #17 from cre-ne-jp/add-unicorn
Rack サーバ (unicorn) を追加する
- Loading branch information
Showing
10 changed files
with
300 additions
and
9 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
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
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,61 @@ | ||
# Rails のルートパス | ||
rails_root = File.expand_path('../../', __FILE__) | ||
|
||
|
||
# 環境変数 RAILS_ENV を取得する | ||
rails_env = ENV['RAILS_ENV'] || 'development' | ||
|
||
|
||
# Unicorn のワーカー数 | ||
worker_processes 2 | ||
|
||
|
||
# ワーキングディレクトリ | ||
working_directory rails_root | ||
|
||
|
||
# 接続タイムアウト | ||
timeout 30 | ||
|
||
|
||
# ログファイルのパス | ||
stderr_path File.expand_path('../../log/unicorn_stderr.log', __FILE__) | ||
stdout_path File.expand_path('../../log/unicorn_stdout.log', __FILE__) | ||
|
||
|
||
# フロントエンドサーバとの接続設定 | ||
#listen File.expand_path('../../tmp/sockets/unicorn.sock', __FILE__) | ||
listen 8081 | ||
|
||
|
||
# pid ファイルのパス | ||
pid File.expand_path('../../tmp/pids/unicorn.pid', __FILE__) | ||
|
||
|
||
# 再起動時にダウンタイムを作るか | ||
preload_app true | ||
|
||
|
||
# nginx との連携に必要 | ||
# USR2 シグナルを受けたときに古いプロセスを停止させる | ||
before_fork do |server, worker| | ||
defined?(ActiveRecord::Base) and | ||
ActiveRecord::Base.connection.disconnect! | ||
|
||
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 | ||
end | ||
|
||
after_fork do |server, worker| | ||
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection | ||
end | ||
|
||
|
||
# ライブラリのパス | ||
ENV['BUNDLE_GEMFILE'] = rails_root + '/Gemfile' |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
[Unit] | ||
Description=LogArchiver IRC Bot - IRC Log Save and Viewer | ||
Documentation=https://github.com/cre-ne-jp/log-archiver | ||
After=network.target | ||
After=network.target, mariadb.service | ||
|
||
[Service] | ||
User=logarchiver | ||
Group=logarchiver | ||
User=log-archiver | ||
Group=log-archiver | ||
Environment=RAILS_ENV=production | ||
SyslogIdentifier=log-archiver-ircbot | ||
Type=simple | ||
PIDFile=/home/logarchiver/log-archiver/tmp/ircbot.pid | ||
WorkingDirectory=/home/logarchiver/log-archiver | ||
ExecStart=/home/logarchiver/log-archiver/bin/ircbot -v | ||
PIDFile=/home/log-archiver/log-archiver/tmp/pids/ircbot.pid | ||
WorkingDirectory=/home/log-archiver/log-archiver | ||
Restart=always | ||
|
||
ExecStart=/home/log-archiver/log-archiver/bin/ircbot -v -m production | ||
#ExecReload=/usr/bin/kill -HUP $MAINPID | ||
ExecStop=/usr/bin/kill $MAINPID | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,21 @@ | ||
[Unit] | ||
Description=LogArchiver Rack Server(Unicorn) - IRC Log Save and Viewer | ||
Documentation=https://github.com/cre-ne-jp/log-archiver | ||
After=network.target, mariadb.service | ||
|
||
[Service] | ||
User=log-archiver | ||
Group=log-archiver | ||
Environment=RAILS_ENV=production | ||
SyslogIdentifier=log-archiver-unicorn | ||
Type=simple | ||
PIDFile=/home/log-archiver/log-archiver/tmp/pids/unicorn.pid | ||
WorkingDirectory=/home/log-archiver/log-archiver | ||
Restart=always | ||
|
||
ExecStart=/usr/bin/bundle exec "unicorn_rails -c config/unicorn.rb -E production" | ||
ExecReload=/usr/bin/kill -USR2 $MAINPID | ||
ExecStop=/usr/bin/kill -QUIT $MAINPID | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,14 @@ | ||
/home/log-archiver/log-archiver/log/*.log { | ||
weekly | ||
rotate 4 | ||
missingok | ||
notifempty | ||
copytruncate | ||
create 0664 log-archiver log-archiver | ||
|
||
# unicorn master プロセスに、ログファイルの開き直しをさせる | ||
lastaction | ||
pid=/home/log-archiver/log-archiver/tmp/pids/unicorn.pid | ||
test -s $pid && kill -USR1 "$(cat $pid)" | ||
endscript | ||
} |
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,72 @@ | ||
## Log Archiver | ||
## | ||
## Lines starting with two hashes (##) are comments with information. | ||
## Lines starting with one hash (#) are configuration parameters that can be uncommented. | ||
## | ||
################################### | ||
## configuration ## | ||
################################### | ||
## | ||
|
||
upstream log-archiver { | ||
#server unix:/home/log-archiver/log-archiver/tmp/sockets/unicorn.sock fail_timeout=0; | ||
server 127.0.0.1:8081; | ||
} | ||
|
||
map $http_upgrade $connection_upgrade_gitlab { | ||
default upgrade; | ||
'' close; | ||
} | ||
|
||
## Normal HTTP host | ||
server { | ||
## Either remove "default_server" from the listen line below, | ||
## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab | ||
## to be served if you visit any address that your server responds to, eg. | ||
## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server; | ||
listen 0.0.0.0:80 default_server; | ||
listen [::]:80 default_server; | ||
server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com | ||
server_tokens off; ## Don't show the nginx version number, a security best practice | ||
|
||
## See app/controllers/application_controller.rb for headers set | ||
|
||
## Individual nginx logs for this GitLab vhost | ||
access_log /var/log/nginx/log-archiver_access.log; | ||
error_log /var/log/nginx/log-archiver_error.log; | ||
|
||
root /home/log-archiver/log-archiver/public; | ||
try_files $uri/index.html $uri.html $uri @app; | ||
|
||
location @app { | ||
client_max_body_size 0; | ||
gzip off; | ||
|
||
## https://github.com/gitlabhq/gitlabhq/issues/694 | ||
## Some requests take more than 30 seconds. | ||
proxy_read_timeout 300; | ||
proxy_connect_timeout 300; | ||
proxy_redirect off; | ||
|
||
proxy_http_version 1.1; | ||
|
||
proxy_set_header Host $http_host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection $connection_upgrade_gitlab; | ||
|
||
proxy_pass http://log-archiver; | ||
} | ||
|
||
error_page 404 /404.html; | ||
error_page 422 /422.html; | ||
error_page 500 /500.html; | ||
error_page 502 /502.html; | ||
error_page 503 /503.html; | ||
location ~ ^/(404|422|500|502|503)\.html$ { | ||
root /home/log-archiver/log-archiver/public; | ||
internal; | ||
} | ||
} |
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,114 @@ | ||
## GitLab | ||
## | ||
## Modified from nginx http version | ||
## Lines starting with two hashes (##) are comments with information. | ||
## Lines starting with one hash (#) are configuration parameters that can be uncommented. | ||
## | ||
################################### | ||
## configuration ## | ||
################################### | ||
## | ||
|
||
upstream log-archiver { | ||
#server unix:/home/log-archiver/log-archiver/tmp/sockets/unicorn.sock fail_timeout=0; | ||
server 127.0.0.1:8081; | ||
} | ||
|
||
map $http_upgrade $connection_upgrade_log-archiver_ssl { | ||
default upgrade; | ||
'' close; | ||
} | ||
|
||
## Redirects all HTTP traffic to the HTTPS host | ||
server { | ||
## Either remove "default_server" from the listen line below, | ||
## or delete the /etc/nginx/sites-enabled/default file. This will cause log-archiver | ||
## to be served if you visit any address that your server responds to, eg. | ||
## the ip address of the server (http://x.x.x.x/) | ||
listen 0.0.0.0:80; | ||
listen [::]:80 ipv6only=on default_server; | ||
server_name YOUR_SERVER_FQDN; ## Replace this with something like log-archiver.example.com | ||
server_tokens off; ## Don't show the nginx version number, a security best practice | ||
return 301 https://$http_host$request_uri; | ||
access_log /var/log/nginx/log-archiver_access.log; | ||
error_log /var/log/nginx/log-archiver_error.log; | ||
} | ||
|
||
## HTTPS host | ||
server { | ||
listen 0.0.0.0:443 ssl; | ||
listen [::]:443 ipv6only=on ssl default_server; | ||
server_name YOUR_SERVER_FQDN; ## Replace this with something like log-archiver.example.com | ||
server_tokens off; ## Don't show the nginx version number, a security best practice | ||
|
||
## Strong SSL Security | ||
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/ | ||
ssl on; | ||
ssl_certificate /etc/nginx/ssl/log-archiver.crt; | ||
ssl_certificate_key /etc/nginx/ssl/log-archiver.key; | ||
|
||
# GitLab needs backwards compatible ciphers to retain compatibility with Java IDEs | ||
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"; | ||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
ssl_prefer_server_ciphers on; | ||
ssl_session_cache shared:SSL:10m; | ||
ssl_session_timeout 5m; | ||
|
||
## See app/controllers/application_controller.rb for headers set | ||
|
||
## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL. | ||
## Replace with your ssl_trusted_certificate. For more info see: | ||
## - https://medium.com/devops-programming/4445f4862461 | ||
## - https://www.ruby-forum.com/topic/4419319 | ||
## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx | ||
# ssl_stapling on; | ||
# ssl_stapling_verify on; | ||
# ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt; | ||
# resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired | ||
# resolver_timeout 5s; | ||
|
||
## [Optional] Generate a stronger DHE parameter: | ||
## sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096 | ||
## | ||
# ssl_dhparam /etc/ssl/certs/dhparam.pem; | ||
|
||
## Individual nginx logs for this GitLab vhost | ||
access_log /var/log/nginx/log-archiver_access.log; | ||
error_log /var/log/nginx/log-archiver_error.log; | ||
|
||
root /home/log-archiver/log-archiver/public; | ||
try_files $uri/index.html $uri.html $uri @app; | ||
|
||
location @app { | ||
client_max_body_size 0; | ||
gzip off; | ||
|
||
## https://github.com/log-archiverhq/log-archiverhq/issues/694 | ||
## Some requests take more than 30 seconds. | ||
proxy_read_timeout 300; | ||
proxy_connect_timeout 300; | ||
proxy_redirect off; | ||
|
||
proxy_http_version 1.1; | ||
|
||
proxy_set_header Host $http_host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-Ssl on; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection $connection_upgrade_log-archiver_ssl; | ||
|
||
proxy_pass http://log-archiver; | ||
} | ||
|
||
error_page 404 /404.html; | ||
error_page 422 /422.html; | ||
error_page 500 /500.html; | ||
error_page 502 /502.html; | ||
error_page 503 /503.html; | ||
location ~ ^/(404|422|500|502|503)\.html$ { | ||
root /home/log-archiver/log-archiver/public; | ||
internal; | ||
} | ||
} |
Empty file.
Empty file.