2018-8-2 Puma 一启动就马上退出的解决方法
Puma 是用于 Ruby on Rails 的服务器
问题
puma 一启动就退出。
问题截图
我用的命令是:
bundle exec puma -C ./deploy/puma-server-production.rb
这条命令的意思:让 puma 启动时使用 ./deploy/puma-server-production.rb
这个配置文件
我的 puma-server-production.rb 配置
bind 'tcp://0.0.0.0:9696'
threads 5, 5
environment ENV.fetch("RAILS_ENV") { "production" }
workers 2
prune_bundler
app_name = "witticism.com"
app_dir = File.expand_path("../..", __FILE__)
app_dir_parent = File.expand_path("../../", __FILE__)
app_path = "/var/www/#{app_name}/"
directory "#{app_path}current"
pidfile "#{app_path}/shared/tmp/pids/puma.pid"
state_path "#{app_path}/shared/tmp/sockets/puma.state"
stdout_redirect "#{app_path}/shared/log/puma.stdout.log", "#{app_path}/shared/log/puma.stderr.log"
on_restart do
puts 'Wittcism puma restart...'
end
before_fork do
ActiveRecord::Base.connection_pool.disconnect!
end
on_worker_boot do
ActiveRecord::Base.establish_connection
end
如何解决?
看日志解决。
用如下命令:
tail -f /var/www/witticism.com/shared/log/puma.stderr.log
(你的路径会不一样,自己改改路径就好)
错误信息:
uninitialized constant #<Class:#<Puma::DSL:0x00000001183d18>>::ActiveRecord (NameError)
解决方法:加上 if defined?(ActiveRecord)
before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end
on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
最后
其实配置文件默认就有 if defined?(ActiveRecord)。
是我手贱删掉了……