-
-
Save mangege/38256a51103152a112ab to your computer and use it in GitHub Desktop.
nginx+puma+mina+god
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
# /etc/god/conf.d/fmxcdemo.god file | |
rails_env = ENV['RAILS_ENV'] || 'production' | |
rails_root = ENV['RAILS_ROOT'] || "/home/fmxcdemo/app/current" | |
God.watch do |w| | |
w.name = "fmxcdemo" | |
w.interval = 30.seconds # default | |
w.start = "cd #{rails_root} && bundle exec puma --config #{rails_root}/config/puma.rb -e #{rails_env} -d" | |
w.stop = "kill -TERM `cat #{rails_root}/tmp/puma.pid`" | |
w.restart = "kill -USR2 `cat #{rails_root}/tmp/puma.pid`" | |
w.start_grace = 10.seconds | |
w.restart_grace = 10.seconds | |
w.pid_file = "#{rails_root}/tmp/puma.pid" | |
w.uid = 'fmxcdemo' | |
w.gid = 'fmxcdemo' | |
w.behavior(:clean_pid_file) | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 5.seconds | |
c.running = false | |
end | |
end | |
w.restart_if do |restart| | |
restart.condition(:memory_usage) do |c| | |
c.above = 300.megabytes | |
c.times = [3, 5] # 3 out of 5 intervals | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = 50.percent | |
c.times = 5 | |
end | |
end | |
# lifecycle | |
w.lifecycle do |on| | |
on.condition(:flapping) do |c| | |
c.to_state = [:start, :restart] | |
c.times = 5 | |
c.within = 5.minute | |
c.transition = :unmonitored | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
end | |
end | |
end | |
God.watch do |w| | |
w.dir = "#{rails_root}" | |
w.name = "fmxcdemo_clear" | |
w.interval = 60.seconds | |
w.env = {"RAILS_ENV"=>rails_env} | |
w.uid = 'fmxcdemo' | |
w.gid = 'fmxcdemo' | |
w.start = "bundle exec rake daemon:clear_queue" | |
w.keepalive | |
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
# config/deploy.rb file | |
require 'mina/bundler' | |
require 'mina/rails' | |
require 'mina/git' | |
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org) | |
# require 'mina/rvm' # for rvm support. (http://rvm.io) | |
# Basic settings: | |
# domain - The hostname to SSH to. | |
# deploy_to - Path to deploy into. | |
# repository - Git repo to clone from. (needed by mina/git) | |
# branch - Branch name to deploy. (needed by mina/git) | |
if ENV['RAILS_ENV'] == 'production' | |
set :base_name, 'fmxc' | |
set :domain, 'fmxc.local' | |
set :branch, 'master' | |
set :clear_task_name, 'clear_ticket' | |
else | |
set :base_name, 'fmxcdemo' | |
set :domain, 'ylg.local' | |
set :branch, 'dev' | |
set :clear_task_name, 'fmxcdemo_clear' | |
end | |
set :deploy_to, "/home/#{base_name}/app" | |
set :repository, 'git://git.tyt.com/fmxc/fmxcserver.git' | |
# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server. | |
# They will be linked in the 'deploy:link_shared_paths' step. | |
set :shared_paths, ['config/database.yml', 'config/app_config.yml', 'config/puma.rb', 'tmp', 'log', 'public/system'] | |
# Optional settings: | |
set :user, base_name # Username in the server to SSH to. | |
# set :port, '30000' # SSH port number. | |
set :term_mode, :system | |
# This task is the environment that is loaded for most commands, such as | |
# `mina deploy` or `mina rake`. | |
task :environment do | |
# If you're using rbenv, use this to load the rbenv environment. | |
# Be sure to commit your .rbenv-version to your repository. | |
# invoke :'rbenv:load' | |
# For those using RVM, use this to load an RVM version@gemset. | |
# invoke :'rvm:use[ruby-1.9.3-p125@default]' | |
end | |
# Put any custom mkdir's in here for when `mina setup` is ran. | |
# For Rails apps, we'll make some of the shared paths that are shared between | |
# all releases. | |
task :setup => :environment do | |
queue! %[mkdir -p "#{deploy_to}/shared/log"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"] | |
queue! %[mkdir -p "#{deploy_to}/shared/config"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"] | |
queue! %[mkdir -p "#{deploy_to}/shared/tmp"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"] | |
queue! %[mkdir -p "#{deploy_to}/shared/public/system"] | |
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/public/system"] | |
queue! %[touch "#{deploy_to}/shared/config/database.yml"] | |
queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."] | |
queue! %[touch "#{deploy_to}/shared/config/app_config.yml"] | |
queue %[echo "-----> Be sure to edit 'shared/config/app_config.yml'."] | |
queue! %[touch "#{deploy_to}/shared/config/puma.rb"] | |
queue %[echo "-----> Be sure to edit 'shared/config/puma.rb'."] | |
end | |
desc "Deploys the current version to the server." | |
task :deploy => :environment do | |
deploy do | |
# Put things that will set up an empty directory into a fully set-up | |
# instance of your project. | |
invoke :'git:clone' | |
invoke :'deploy:link_shared_paths' | |
invoke :'bundle:install' | |
invoke :'rails:db_migrate' | |
invoke :'rails:assets_precompile' | |
to :launch do | |
invoke :'puma:restart' | |
invoke :'clear_ticket:restart' | |
end | |
end | |
end | |
namespace :puma do | |
desc 'start puma' | |
task :start do | |
queue "sudo god start #{base_name}" | |
end | |
desc 'stop puma' | |
task :stop do | |
queue "sudo god stop #{base_name}" | |
end | |
desc 'restart puma' | |
task :restart do | |
queue "sudo god restart #{base_name}" | |
end | |
end | |
namespace :clear_ticket do | |
desc 'start clear_ticket' | |
task :start do | |
queue "sudo god start #{clear_task_name}" | |
end | |
desc 'stop clear_ticket' | |
task :stop do | |
queue "sudo god stop #{clear_task_name}" | |
end | |
desc 'restart clear_ticket' | |
task :restart do | |
queue "sudo god restart #{clear_task_name}" | |
end | |
end | |
# For help in making your deploy script, see the Mina documentation: | |
# | |
# - http://nadarei.co/mina | |
# - http://nadarei.co/mina/tasks | |
# - http://nadarei.co/mina/settings | |
# - http://nadarei.co/mina/helpers |
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
# /etc/nginx/conf.d/fmxcdemo.tyt.com.conf file | |
server { | |
listen 80; | |
server_name fmxcdemo.tyt.com; | |
#charset utf-8; | |
root /home/fmxcdemo/app/current/public; | |
access_log /var/log/nginx/fmxcdemo.tyt.com.access.log main; | |
error_page 404 /404.html; | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /usr/share/nginx/html; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires 30d; | |
access_log off; | |
} | |
location / { | |
index index.html; | |
try_files $uri @fmxcdemopuma; | |
} | |
location @fmxcdemopuma { | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
proxy_redirect off; | |
proxy_pass http://unix:/home/fmxcdemo/app/current/tmp/puma.sock; | |
} | |
} |
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
# config/puma.rb file | |
base_name = 'fmxc' | |
directory "/home/#{base_name}/app/current" | |
workers 2 | |
threads 16,16 | |
bind "unix:///home/#{base_name}/app/current/tmp/puma.sock?mask=0777" | |
pidfile "/home/#{base_name}/app/current/tmp/puma.pid" | |
state_path "/home/#{base_name}/app/current/tmp/puma.state" | |
preload_app! | |
on_worker_boot do | |
$redis.client.reconnect | |
ActiveRecord::Base.connection.reconnect! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍