带有 Systemd 的 Puma 无法启动

问题描述

我无法通过 systemd 启动 Puma。我已经尝试了以下所有操作(在 /etc/systemd/system/puma.service 中):

ExecStart=/home/deploy/.rvm/bin/rvm all do bundle exec puma -C /path/to/my/app/config/puma.rb

ExecStart=/usr/local/rvm/gems/ruby-2.6.3/bin/puma -C /path/to/my/app/config/puma.rb
-- Unit puma.service has begun starting up.
Dec 30 12:58:44 ip-172-31-13-117 puma[32147]: /usr/bin/env: 'ruby_executable_hooks': No such file or directory
Dec 30 12:58:44 ip-172-31-13-117 systemd[1]: puma.service: Control process exited,code=exited status=127
Dec 30 12:58:44 ip-172-31-13-117 systemd[1]: Failed to start Puma HTTP Server.

ExecStart=/usr/local/rvm/wrappers/ruby-2.6.3/puma -C /path/to/my/app/config/puma.rb
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/lib/puma/cli.rb:71:in `new'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/lib/puma/cli.rb:71:in `initialize'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/bin/puma:8:in `new'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/bin/puma:8:in `<top (required)>'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/puma:23:in `load'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/puma:23:in `<main>'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
Dec 30 12:06:31 ip-172-31-13-117 puma[27328]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'
Dec 30 12:06:31 ip-172-31-13-117 systemd[1]: puma.service: Main process exited,code=exited,status=1/FAILURE

ExecStart=/bin/bash -lc 'RAILS_ENV=production bundle exec puma -C /path/to/my/app/config/puma.rb --daemon'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/lib/puma/cluster.rb:436:in `run'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/lib/puma/launcher.rb:172:in `run'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/lib/puma/cli.rb:80:in `run'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/gems/puma-4.3.7/bin/puma:10:in `<top (required)>'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/puma:23:in `load'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/puma:23:in `<main>'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval'
Dec 30 12:03:31 ip-172-31-13-117 bash[27092]:         from /usr/local/rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>'

但没有任何效果.. 不知道如何从 .service 文件调用 Puma。我想是找不到合适的红宝石的问题?但 RVM 应该解决的问题只是我不知道如何设置。

这里是ruby.rb

max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count,max_threads_count

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port        ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

# Change to match your cpu core count
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'] || "production"
environment rails_env

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log","#{shared_dir}/log/puma.stderr.log",true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/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("#{app_dir}/config/database.yml")[rails_env])
end


plugin :tmp_restart

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)