Skip to content

Commit

Permalink
ops
Browse files Browse the repository at this point in the history
  • Loading branch information
mangege committed Jan 8, 2013
1 parent 3a9df76 commit 3926a00
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Capfile
@@ -0,0 +1,3 @@
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,5 +1,4 @@
source 'https://rubygems.org'
#source 'http://ruby.taobao.org'

gem 'rails', '3.2.10'

Expand All @@ -19,6 +18,7 @@ gem "nokogiri", "~> 1.5.6"
gem "kaminari", "~> 0.14.1"
gem "settingslogic", "~> 2.0.9"
gem "exception_notification", "~> 3.0.0"
gem "capistrano", "~> 2.13.5"

group :assets do
gem 'sass-rails', '~> 3.2.3'
Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Expand Up @@ -31,6 +31,12 @@ GEM
addressable (2.3.2)
arel (3.0.2)
builder (3.0.4)
capistrano (2.13.5)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
celluloid (0.12.4)
facter (>= 1.6.12)
timers (>= 1.0.0)
Expand Down Expand Up @@ -76,6 +82,7 @@ GEM
guard (>= 1.1)
test-unit (~> 2.2)
hashie (1.2.0)
highline (1.6.15)
hike (1.2.1)
http_parser.rb (0.5.3)
httpauth (0.2.0)
Expand Down Expand Up @@ -112,6 +119,13 @@ GEM
multi_json (1.5.0)
multipart-post (1.1.5)
mysql2 (0.3.11)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.6.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.5.6)
oauth2 (0.8.0)
faraday (~> 0.8)
Expand Down Expand Up @@ -224,6 +238,7 @@ PLATFORMS
ruby

DEPENDENCIES
capistrano (~> 2.13.5)
coffee-rails (~> 3.2.1)
enumerize (~> 0.5.0)
exception_notification (~> 3.0.0)
Expand Down
21 changes: 21 additions & 0 deletions config/app.example.yml
@@ -0,0 +1,21 @@
default: &default
app_concurrency: 5
sidekiq_concurrency: 5
redis_url: "redis://127.0.0.1:6379/0"
site_domain: "test.111.0x6f.com:3000"
site_name: "111掌柜小助手"
test_user_nick: "sandbox_inav"
smtp_user: "noreply@mangege.com"
smtp_pass: "your_pass"

development:
<<: *default

test:
<<: *default

production:
<<: *default
app_concurrency: 16
sidekiq_concurrency: 25
site_domain: "111.0x6f.com"
85 changes: 85 additions & 0 deletions config/deploy.rb
@@ -0,0 +1,85 @@
require "bundler/capistrano"

set :application, "inav"
set :app_user, "inav"
set :nginx_user, "nginx"
set :deploy_user, "outman"

set :scm, :git
set :branch, "master"
set :repository, "git@bitbucket.org:mangege/inav.git"
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{deploy_user}/apps/#{application}"

set :use_sudo, false
default_run_options[:shell] = "bash -l"
default_run_options[:pty] = true

role :web, "h-jm.mangege.com" # Your HTTP server, Apache/etc
role :app, "h-jm.mangege.com" # This may be the same as your `Web` server
role :db, "h-jm.mangege.com", :primary => true # This is where Rails migrations will run

namespace :deploy do
task :start, :roles => :app do
desc "start puma"
run "cd #{current_path} ;rvmsudo -u #{app_user} bundle exec puma -b 'unix://#{shared_path}/tmp/sockets/puma.sock' -S #{shared_path}/tmp/sockets/puma.state --control 'unix://#{shared_path}/tmp/sockets/pumactl.sock' >> #{shared_path}/log/puma.log 2>&1 &", :pty => false
end

desc "stop puma"
task :stop, :roles => :app do
run "cd #{deploy_to}/current/; rvmsudo -u #{app_user} bundle exec thin -C config/thin.yml stop"
run "cd #{current_path} ; rvmsudo -u #{app_user} bundle exec pumactl -S #{shared_path}/tmp/sockets/puma.state stop"
end

desc "restar puma"
task :restart, :roles => :app do
run "cd #{current_path} ; rvmsudo -u #{app_user} bundle exec pumactl -S #{shared_path}/tmp/sockets/puma.state restart"
end
end

task :init_shared_path, :roles => :app do
run "mkdir -p #{deploy_to}/shared/config"

run "mkdir -p #{deploy_to}/shared/tmp"
%w[cache pids sessions sockets].each do |dir_name|
run "mkdir -p #{deploy_to}/shared/tmp/#{dir_name}"
end
end

task :link_shared_files, :roles => :app do
run "ln -sf #{deploy_to}/shared/config/*.yml #{latest_release}/config/"

run "rm -rf #{latest_release}/tmp"
run "ln -sf #{deploy_to}/shared/tmp #{latest_release}/tmp"
end

task :set_home_acl, :roles => :app do
run "setfacl -m u:#{app_user}:x /home/#{deploy_user}"
run "setfacl -m u:#{nginx_user}:x /home/#{deploy_user}"
end

task :set_app_acl, :roles => :app do
#disable other user access
run "find #{deploy_to} -user #{deploy_user} -type d -print0 | xargs -0 chmod o-rwx"
run "find #{deploy_to} -user #{deploy_user} -type f -print0 | xargs -0 chmod o-rwx"

#thin
run "find #{deploy_to} -user #{deploy_user} -type d -print0 | xargs -0 setfacl -m u:#{app_user}:rwx"
run "find #{deploy_to} -user #{deploy_user} -type f -print0 | xargs -0 setfacl -m u:#{app_user}:rw"
#exec file
run "find #{deploy_to}/shared/bundle/ruby/1.9.1/bin -user #{deploy_user} -type f -print0 | xargs -0 setfacl -m u:#{app_user}:rwx"

#nginx
run "find #{deploy_to} -user #{deploy_user} -type d -print0 | xargs -0 setfacl -m u:#{nginx_user}:rx"
run "find #{deploy_to} -user #{deploy_user} -type f -print0 | xargs -0 setfacl -m u:#{nginx_user}:r"
end

desc "upload assets"
task :upload_assets_to_oss, :roles => :app do
run "cd #{latest_release}; bundle exec rake assets:oss:upload"
end

after "deploy:setup", :init_shared_path, :set_home_acl
before "deploy:assets:precompile", :link_shared_files #after deploy:update_code
after "deploy:finalize_update", :set_app_acl
#after "deploy:assets:precompile", :upload_assets_to_oss
16 changes: 16 additions & 0 deletions config/taobao.example.yml
@@ -0,0 +1,16 @@
default: &default
app_key: <%= ENV['TBOP_APP_KEY'] %>
app_secret: <%= ENV['TBOP_APP_SECRET'] %>
oauth2_site: <%= ENV['TBOP_OAUTH2_SITE'] || 'https://oauth.tbsandbox.com' %>
api_site: <%= ENV['TBOP_API_SITE'] || 'http://gw.api.tbsandbox.com/router/rest' %>

development:
<<: *default

test:
<<: *default

production:
<<: *default
oauth2_site: <%= ENV['TBOP_OAUTH2_SITE'] || 'https://oauth.taobao.com' %>
api_site: <%= ENV['TBOP_API_SITE'] || 'http://gw.api.taobao.com/router/rest' %>

0 comments on commit 3926a00

Please sign in to comment.