Ubuntu 18.04 + Rbenv + Rails 5.2.4 + Puma + Nginx + systemd:无法启动Puma服务器

时间:2019-12-13 02:16:55

标签: puma

我将Rails应用程序从 Passenger 切换到 Puma ,以便可以使Rails应用程序在512mb EC2实例上运行。它每隔几分钟崩溃一次,因此我想让systemd自动重新启动它。但是,当我尝试运行puma.service时出现错误:

puma.service - Puma HTTP Server
   Loaded: loaded (/etc/systemd/system/puma.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2019-12-13 01:32:53 UTC; 2min 15s ago
  Process: 2084 ExecStart=/home/ubuntu/.rbenv/bin/rbenv exec bundle exec puma -C /home/ubuntu/app/config/puma/production.rb (code=exited, status=1/
 Main PID: 2084 (code=exited, status=1/FAILURE)

systemd[1]: puma.service: Service hold-off time over, scheduling restart.
systemd[1]: puma.service: Scheduled restart job, restart counter is at 5.
systemd[1]: Stopped Puma HTTP Server.
systemd[1]: puma.service: Start request repeated too quickly.
systemd[1]: puma.service: Failed with result 'exit-code'.
systemd[1]: Failed to start Puma HTTP Server.

我的配置是:

# config/puma/production.rb
bind "unix:///home/ubuntu/app/tmp/puma.sock"
threads_count = 2
threads threads_count, threads_count
port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "production" }
pidfile ENV.fetch("PIDFILE") { "tmp/server.pid" }
plugin :tmp_restart
daemonize true

# nginx
upstream myapp {
  server unix:/home/ubuntu/app/tmp/puma.sock fail_timeout=0;    
}
server {
  listen 80;
  server_name _;
  root /home/ubuntu/app/public;
  try_files $uri/index.html $uri @myapp;
  location /cable {
    proxy_pass http://myapp/cable;
    proxy_http_version 1.1;
  }
  location @myapp {
     proxy_pass http://myapp;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_redirect off;
  }
  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

# puma.service
[Unit]
Description=Puma HTTP Server
After=network.target
Requires=puma.socket
[Service]
Type=simple
WorkingDirectory=/home/ubuntu/app
ExecStart=/home/ubuntu/.rbenv/bin/rbenv exec bundle exec bundle exec puma -C /home/ubuntu/app/config/puma/production.rb
Restart=always
[Install]
WantedBy=multi-user.target

# puma.socket
[Unit]
Description=Puma HTTP Server Accept Sockets
[Socket]
ListenStream=0.0.0.0:3000
NoDelay=true
ReusePort=true
Backlog=1024
[Install]
WantedBy=sockets.target

这是我第一次使用systemd

0 个答案:

没有答案