2017-04-04 40 views
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 

回答

0

我曾经有过这样的问题。我结束了使用此命令每次添加轨道服务器实例作为守护我部署

cd current/app_dir rails s -d -p 3000 -e 'production'

PS:我杀了当前正在运行的做这个

轨之前实例
相关问题