0
我已經設置了capistrano腳本來部署分段。我似乎無法找到一種方法來重啓Puma服務器,因爲部署完成並重啓Puma服務器,如果服務器因任何原因重啓。如何在ec2上使用capistrano部署代碼後啓動美洲獅服務器
我在ec2服務器上使用rails 4.2和Ubuntu 16.04。我嘗試了puma-manager的新貴腳本,但我認爲它在Ubuntu 16.04上不支持。
我跟着這個鏈接,彪馬經理http://blog.peterkw.me/automatic-start-for-puma-rails-and-postgresql/
我deploy.rb文件
lock "3.8.0"
set :application, 'pb-ruby'
set :repo_url, '[email protected]:url/pb-ruby.git' # Edit this to match your repository
set :branch, :staging_new
set :stages, %w(staging,dev_org)
set :default_stage, "dev_org"
set :deploy_to, '/home/pb/pb-ruby'
set :pty, true
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :bundle_binstubs, nil
set :keep_releases, 5
set :rvm_type, :user
set :rvm_ruby_version, '2.3.0' # Edit this if you are using MRI Ruby
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind
set :puma_conf, "#{shared_path}/config/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'staging'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
Capfile是:
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/rails/assets' # for asset handling add
require 'capistrano/rails/migrations' # for running migrations
require 'capistrano/puma'
puma.rb文件
workers 1
# Min and Max threads per worker
threads 1, 6
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
# Default to production
rails_env = ENV['RAILS_ENV'] || "staging"
environment rails_env
# Set up socket location
bind "unix:///home/pb/pb-ruby/shared/tmp/sockets/puma.sock"
# Logging
stdout_redirect "/home/pb/pb-ruby/shared/log/puma.stdout.log", "/home/pb/pb-ruby/shared/log/puma.stderr.log", true
# Set master PID and state locations
pidfile "/home/pb/pb-ruby/shared/tmp/pids/puma.pid"
state_path "/home/pb/pb-ruby/shared/tmp/pids/puma.state"
activate_control_app
on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("/home/pb/pb-ruby/shared/config/database.yml")[rails_env])
end