我已经设置了capistrano脚本以在登台时进行部署。我似乎找不到一种方法来重新启动puma服务器,因为部署完成并重新启动puma服务器,如果服务器因任何原因重新启动。
我在ec2服务器上使用rails 4.2和Ubuntu 16.04。我用puma-manager尝试了upstart脚本,但我认为它在ubuntu 16.04上不受支持。
我关注了puma-manager http://blog.peterkw.me/automatic-start-for-puma-rails-and-postgresql/
的链接我的deploy.rb文件是
lock "3.8.0"
set :application, 'pb-ruby'
set :repo_url, 'git@bitbucket.org: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 :(得分:0)
我曾经遇到过这样的问题。每次部署
时,我都会使用此命令将rails服务器实例添加为守护程序
cd current/app_dir
rails s -d -p 3000 -e 'production'
PS:我在执行此操作之前杀死当前正在运行的rails实例