Commit 5a3bd5d8 by Tran Hoang Viet

VietTH: Update info for deploy

parent 97dbc504
...@@ -5,8 +5,6 @@ require 'capistrano/bundler' ...@@ -5,8 +5,6 @@ require 'capistrano/bundler'
require 'capistrano/rails/assets' require 'capistrano/rails/assets'
require 'capistrano/rails/migrations' require 'capistrano/rails/migrations'
require 'capistrano3/unicorn' require 'capistrano3/unicorn'
# require 'capistrano/sidekiq'
# require 'capistrano/sidekiq/monit' #to require monit tasks # Only for capistrano3
# Load custom tasks from `lib/capistrano/tasks' if you have any defined # Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
lock '3.4.0' lock '3.4.0'
set :application, 'vietth' set :application, 'vietth'
set :repo_url, 'git@bitbucket.org:alicuche/venshop.git'
set :pty, false set :pty, false
# set :branch, 'master' # set :branch, 'master'
...@@ -12,7 +11,17 @@ set :use_sudo, false ...@@ -12,7 +11,17 @@ set :use_sudo, false
set :bundle_binstubs, nil set :bundle_binstubs, nil
set :linked_files, fetch(:linked_files, []).push('config/database.yml') set :linked_files, fetch(:linked_files, []).push('config/database.yml')
set :linked_files, fetch(:linked_files, []).push('config/application.yml') set :linked_files, fetch(:linked_files, []).push('config/application.yml')
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads') set :linked_dirs, fetch(:linked_dirs, []).push(
'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'vendor/bundle',
'public/system',
'public/uploads'
)
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do namespace :deploy do
task :restart do task :restart do
...@@ -21,15 +30,10 @@ namespace :deploy do ...@@ -21,15 +30,10 @@ namespace :deploy do
if test("[ -f #{fetch(:unicorn_pid)} ]") if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, capture(:cat, fetch(:unicorn_pid)) execute :kill, capture(:cat, fetch(:unicorn_pid))
end end
# run "redis-server --daemonize yes"
with rails_env: fetch(:rails_env), wait: 3 do with rails_env: fetch(:rails_env), wait: 3 do
execute :bundle, "exec rake seed:migrate" execute :bundle, "exec rake seed:migrate"
config_file = if fetch(:rails_env) == :production config_file = "#{current_path}/config/unicorn/#{fetch(:rails_env)}.rb"
"/web/training/vietth/current/config/unicorn/production.rb"
else
"/home/alicuche/Web/venshop/current/config/unicorn/#{fetch(:rails_env)}.rb"
end
execute :bundle, "exec unicorn -c #{config_file} -D" execute :bundle, "exec unicorn -c #{config_file} -D"
end end
end end
...@@ -38,42 +42,4 @@ namespace :deploy do ...@@ -38,42 +42,4 @@ namespace :deploy do
end end
end end
namespace :sidekiq do
def sidekiq_pid
current_path + 'tmp/pids/sidekiq.pid'
end
def pid_file_exists?
test(*("[ -f #{sidekiq_pid} ]").split(' '))
end
def pid_process_exists?
pid_file_exists? and test(*("kill -0 $( cat #{sidekiq_pid} )").split(' '))
end
task :start do
on roles(:app) do
if !pid_process_exists?
execute "cd #{current_path} && RAILS_ENV=#{fetch(:rails_env)} ~/.rvm/bin/rvm default do bundle exec sidekiq -L log/sidekiq.log -P #{sidekiq_pid} -q default -q mailers -d"
end
end
end
task :stop do
on roles(:app) do
if pid_process_exists?
execute "kill `cat #{sidekiq_pid}`"
execute "rm #{sidekiq_pid}"
end
end
end
task :restart do
on roles(:app) do
invoke "sidekiq:stop"
invoke "sidekiq:start"
end
end
end
after 'deploy:publishing', 'deploy:restart' after 'deploy:publishing', 'deploy:restart'
...@@ -2,6 +2,7 @@ set :port, 22 ...@@ -2,6 +2,7 @@ set :port, 22
set :user, 'ventura' set :user, 'ventura'
set :deploy_via, :remote_cache set :deploy_via, :remote_cache
set :use_sudo, false set :use_sudo, false
set :repo_url, 'git@gitlab.zigexn.vn:vietth/VietTH-VenShop.git'
server '192.168.1.204', server '192.168.1.204',
roles: [:web, :app, :db], roles: [:web, :app, :db],
...@@ -14,7 +15,7 @@ set :deploy_to, "/web/training/#{fetch(:application)}" ...@@ -14,7 +15,7 @@ set :deploy_to, "/web/training/#{fetch(:application)}"
set :ssh_options, { set :ssh_options, {
forward_agent: true, forward_agent: true,
auth_methods: %w(publickey), auth_methods: %w(publickey),
user: 'ventura', user: fetch(:user)
} }
set :rails_env, :production set :rails_env, :production
......
...@@ -14,7 +14,7 @@ set :deploy_to, "/home/alicuche/Web/venshop" ...@@ -14,7 +14,7 @@ set :deploy_to, "/home/alicuche/Web/venshop"
set :ssh_options, { set :ssh_options, {
forward_agent: true, forward_agent: true,
auth_methods: %w(publickey), auth_methods: %w(publickey),
user: 'alicuche', user: fetch(:user)
} }
set :rails_env, :staging set :rails_env, :staging
......
...@@ -39,6 +39,16 @@ Rails.application.configure do ...@@ -39,6 +39,16 @@ Rails.application.configure do
# Raises error for missing translations # Raises error for missing translations
# config.action_view.raise_on_missing_translations = true # config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } # config.action_mailer.delivery_method = :letter_opener
config.action_mailer.delivery_method = :letter_opener config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 587,
:user_name => 'alicuche',
:password => 'alicuche1989'
}
# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
end end
...@@ -14,7 +14,7 @@ timeout 30 ...@@ -14,7 +14,7 @@ timeout 30
preload_app true preload_app true
########################################### ###########################################
before_fork do before_fork do |server, worker|
Signal.trap 'TERM' do Signal.trap 'TERM' do
Process.kill 'QUIT', Process.pid Process.kill 'QUIT', Process.pid
end end
...@@ -23,7 +23,7 @@ before_fork do ...@@ -23,7 +23,7 @@ before_fork do
ActiveRecord::Base.connection.disconnect! ActiveRecord::Base.connection.disconnect!
end end
after_fork do after_fork do |server, worker|
Signal.trap 'TERM' do Signal.trap 'TERM' do
end end
......
namespace :sidekiq do
def sidekiq_pid
current_path + 'tmp/pids/sidekiq.pid'
end
def pid_file_exists?
test(*("[ -f #{sidekiq_pid} ]").split(' '))
end
def pid_process_exists?
pid_file_exists? && test(*("kill -0 $( cat #{sidekiq_pid} )").split(' '))
end
task :start do
on roles(:app) do
if !pid_process_exists?
execute "cd #{current_path} && RAILS_ENV=#{fetch(:rails_env)} ~/.rvm/bin/rvm default do bundle exec sidekiq -L log/sidekiq.log -P #{sidekiq_pid} -q default -q mailers -d"
end
end
end
task :stop do
on roles(:app) do
if pid_process_exists?
execute "kill `cat #{sidekiq_pid}`"
execute "rm #{sidekiq_pid}"
end
end
end
task :restart do
on roles(:app) do
invoke "sidekiq:stop"
invoke "sidekiq:start"
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment