update deploy info
This commit is contained in:
parent
2129ab60fb
commit
a27ac6278c
|
@ -17,4 +17,4 @@ production:
|
|||
host: localhost
|
||||
encoding: unicode
|
||||
database: wblog_production
|
||||
pool: 5
|
||||
pool: 50
|
||||
|
|
|
@ -4,22 +4,23 @@ set :default_stage, 'zh'
|
|||
require 'mina/bundler'
|
||||
require 'mina/rails'
|
||||
require 'mina/git'
|
||||
require 'mina/rvm'
|
||||
require 'mina/rbenv'
|
||||
require 'mina/puma'
|
||||
require "mina_sidekiq/tasks"
|
||||
require 'mina/logs'
|
||||
require 'mina/multistage'
|
||||
|
||||
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'public/uploads', 'public/personal')
|
||||
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'public/uploads', 'node_modules', 'public/personal')
|
||||
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/application.yml')
|
||||
|
||||
set :puma_config, ->{ "#{fetch(:current_path)}/config/puma.rb" }
|
||||
set :sidekiq_pid, ->{ "#{fetch(:shared_path)}/tmp/pids/sidekiq.pid" }
|
||||
|
||||
task :environment do
|
||||
invoke :'rvm:use', '2.3.1'
|
||||
task :remote_environment do
|
||||
invoke :'rbenv:load'
|
||||
end
|
||||
|
||||
task :setup => :environment do
|
||||
task :setup do
|
||||
command %[mkdir -p "#{fetch(:shared_path)}/tmp/sockets"]
|
||||
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/tmp/sockets"]
|
||||
|
||||
|
@ -32,6 +33,9 @@ task :setup => :environment do
|
|||
command %[mkdir -p "#{fetch(:shared_path)}/public/uploads"]
|
||||
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/public/uploads"]
|
||||
|
||||
command %[mkdir -p "#{fetch(:shared_path)}/node_modules"]
|
||||
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/node_modules"]
|
||||
|
||||
command %[mkdir -p "#{fetch(:shared_path)}/config"]
|
||||
command %[chmod g+rx,u+rwx "#{fetch(:shared_path)}/config"]
|
||||
|
||||
|
@ -43,7 +47,7 @@ task :setup => :environment do
|
|||
end
|
||||
|
||||
desc "Deploys the current version to the server."
|
||||
task :deploy => :environment do
|
||||
task :deploy do
|
||||
command %[echo "-----> Server: #{fetch(:domain)}"]
|
||||
command %[echo "-----> Path: #{fetch(:deploy_to)}"]
|
||||
command %[echo "-----> Branch: #{fetch(:branch)}"]
|
||||
|
@ -58,15 +62,15 @@ task :deploy => :environment do
|
|||
invoke :'deploy:cleanup'
|
||||
|
||||
on :launch do
|
||||
invoke :'rvm:use', '2.3.1'
|
||||
invoke :'rbenv:load'
|
||||
invoke :'puma:hard_restart'
|
||||
invoke :'sidekiq:restart'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Deploys the current version to the server."
|
||||
task :first_deploy => :environment do
|
||||
desc "Prepare the first deploy on server."
|
||||
task :first_deploy do
|
||||
command %[echo "-----> Server: #{fetch(:domain)}"]
|
||||
command %[echo "-----> Path: #{fetch(:deploy_to)}"]
|
||||
command %[echo "-----> Branch: #{fetch(:branch)}"]
|
||||
|
@ -75,11 +79,13 @@ task :first_deploy => :environment do
|
|||
invoke :'git:clone'
|
||||
invoke :'deploy:link_shared_paths'
|
||||
invoke :'bundle:install'
|
||||
invoke :'rails:assets_precompile'
|
||||
invoke :'deploy:cleanup'
|
||||
|
||||
on :launch do
|
||||
invoke :'rvm:use', '2.3.1'
|
||||
invoke :'rbenv:load'
|
||||
invoke :'rails:db_create'
|
||||
invoke :'rails:db_migrate'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# truncate your rails log every day
|
||||
# Usage:
|
||||
# `cp logrotate.conf.example /etc/logrotate.d/wblog`
|
||||
/data/www/wblog/current/log/*.log {
|
||||
daily
|
||||
missingok
|
||||
rotate 7
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
copytruncate
|
||||
su ruby ruby
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
# Watch your rails app & sidekiq process and restart it automatically
|
||||
# Usage:
|
||||
# `sudo apt-get install monit -y`
|
||||
# `cp monit.conf.example /etc/monit/conf.d/`
|
||||
# `service monit restart`
|
||||
check process wblog_puma
|
||||
with pidfile /data/www/wblog/shared/tmp/pids/puma.pid
|
||||
start program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV="production" bundle exec puma -q -d -e production -C config/puma.rb'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
stop program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV="production" bundle exec pumactl -F /data/www/wblog/current/config/puma.rb stop'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
group wblog
|
||||
|
||||
check process wblog_sidekiq
|
||||
with pidfile /data/www/wblog/shared/tmp/pids/sidekiq.pid
|
||||
start program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV="production" bundle exec sidekiq -d -e production -C /data/www/wblog/current/config/sidekiq.yml -i 0 -P /data/www/wblog/shared/tmp/pids/sidekiq.pid -L /data/www/wblog/current/log/sidekiq.log'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
stop program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV="production" bundle exec sidekiqctl stop /data/www/wblog/shared/tmp/pids/sidekiq.pid 11'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
group wblog
|
||||
|
||||
#check process wblog_clockwork
|
||||
# with pidfile /data/www/wblog/shared/tmp/pids/clockworkd.clock.pid
|
||||
# start program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV=production bundle exec clockworkd -c /data/www/wblog/current/config/clock.rb -i clock -d /data/www/wblog/current --pid-dir /data/www/wblog/shared/tmp/pids --log --log-dir /data/www/wblog/shared/log start'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
# stop program = "/bin/sh -c 'cd /data/www/wblog/current; PATH=bin:/home/ruby/.rbenv/shims:/home/ruby/.rbenv/bin:$PATH LC_ALL=en_US.UTF-8 RAILS_ENV=production bundle exec clockworkd -c /data/www/wblog/current/config/clock.rb -i clock -d /data/www/wblog/current --pid-dir /data/www/wblog/shared/tmp/pids --log --log-dir /data/www/wblog/shared/log stop'" as uid ruby and gid ruby with timeout 90 seconds
|
||||
# group wblog
|
|
@ -0,0 +1,44 @@
|
|||
upstream wblog {
|
||||
server unix:///data/www/wblog/shared/tmp/sockets/puma.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name example.com;
|
||||
root /data/www/wblog/current/public;
|
||||
|
||||
location ^~ /assets/ {
|
||||
gzip_static on;
|
||||
expires max;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
location /cable {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://wblog;
|
||||
}
|
||||
|
||||
location ~ ^/(uploads)/ {
|
||||
expires max;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
try_files $uri/index.html $uri @wblog;
|
||||
location @wblog {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://wblog;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /500.html;
|
||||
client_max_body_size 20M;
|
||||
keepalive_timeout 10;
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
upstream wblog {
|
||||
server unix:///data/www/wblog/shared/tmp/sockets/puma.sock fail_timeout=0;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
# FIXME: update your domain here
|
||||
server_name example.com;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl;
|
||||
# FIXME: update your domain here
|
||||
server_name example.com;
|
||||
root /data/www/wblog/current/public;
|
||||
|
||||
ssl on;
|
||||
|
||||
# FIXME: update your domain here
|
||||
ssl_certificate /etc/nginx/sslkeys/yourdomain.com.key.pem;
|
||||
ssl_certificate_key /etc/nginx/sslkeys/yourdomain.com.key;
|
||||
ssl_dhparam /etc/nginx/sslkeys/dhparam.pem;
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
|
||||
# ssl optimizations
|
||||
ssl_session_cache shared:SSL:30m;
|
||||
ssl_session_timeout 30m;
|
||||
add_header Strict-Transport-Security "max-age=31536000";
|
||||
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
|
||||
|
||||
location ^~ /assets/ {
|
||||
gzip_static on;
|
||||
expires max;
|
||||
add_header Cache-Control public;
|
||||
}
|
||||
|
||||
location ~ ^/(uploads)/ {
|
||||
expires max;
|
||||
break;
|
||||
}
|
||||
|
||||
location /cable {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_pass http://wblog;
|
||||
}
|
||||
|
||||
try_files $uri/index.html $uri @wblog;
|
||||
location @wblog {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://wblog;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /500;
|
||||
error_page 404 /404;
|
||||
client_max_body_size 20M;
|
||||
keepalive_timeout 10;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
if ENV['RAILS_ENV'] == 'production'
|
||||
app_root = '/data/www/wblog/shared'
|
||||
pidfile "#{app_root}/tmp/pids/puma.pid"
|
||||
state_path "#{app_root}/tmp/pids/puma.state"
|
||||
bind "unix://#{app_root}/tmp/sockets/puma.sock"
|
||||
activate_control_app "unix://#{app_root}/tmp/sockets/pumactl.sock"
|
||||
daemonize true
|
||||
workers 1
|
||||
threads 4, 8
|
||||
preload_app!
|
||||
|
||||
stdout_redirect "#{app_root}/log/puma_access.log", "#{app_root}/log/puma_error.log", true
|
||||
|
||||
on_worker_boot do
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
ActiveRecord::Base.establish_connection
|
||||
end
|
||||
end
|
||||
|
||||
before_fork do
|
||||
ActiveRecord::Base.connection_pool.disconnect!
|
||||
end
|
||||
else
|
||||
plugin :tmp_restart
|
||||
end
|
Loading…
Reference in New Issue