简体   繁体   English

无法启动Puma Ubuntu 16.04

[英]Cannot Start Puma Ubuntu 16.04

Hi i followed this thread of digitalocean to deploy my RubyOnRails app on digitalocean vps https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04 嗨,我遵循了digitalocean的这一线程,将我的RubyOnRails应用程序部署在digitalocean vps上https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on -ubuntu-14-04

My Config: 512 MB RAM(with 1 gb swap) ubuntu 16.04 Ruby2.33(with rbenv) 我的配置:512 MB RAM(具有1 gb交换)ubuntu 16.04 Ruby2.33(具有rbenv)

This tutorial lists usage of upstart but as i searched i found ubuntu 16.04 uses systemd. 本教程列出了新贵的用法,但是当我搜索时发现ubuntu 16.04使用systemd。 I found this thread but still could start Puma Server https://github.com/puma/puma/issues/1211 我找到了这个线程,但是仍然可以启动Puma Server https://github.com/puma/puma/issues/1211

when i run which puma it gives /home/ashish/.rbenv/shims/puma 当我运行哪个彪马时,它会给出/home/ashish/.rbenv/shims/puma

Also here is my puma.service file 这也是我的puma.service文件

[Unit]
Description=Puma HTTP Server
After=network.target

# Uncomment for socket activation (see below)
# Requires=puma.socket

[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple

# Preferably configure a non-privileged user
User=www-data

# The path to the puma application root
# Also replace the "<WD>" place holders below with this path.
WorkingDirectory=/var/www/mystore.rentcallcenter.com

# Helpful for debugging socket activation, etc.
Environment=PUMA_DEBUG=1

# The command to start Puma. This variant uses a binstub generated via
# `bundle binstubs puma --path ./sbin` in the WorkingDirectory
# (replace "<WD>" below)
ExecStart=/home/ashish/.rbenv/shims/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem

# Variant: Use config file with `bind` directives instead:
# ExecStart=<WD>/sbin/puma -C config.rb
# Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub

Restart=always

[Install]
WantedBy=multi-user.target

and here is my puma.rb in rails config folder 这是我的puma.rb在rails config文件夹中

# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads 1, 6

# 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") { "production" }

# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY") { 1 }



# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!

# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
#   ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end

# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
#   ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#

# Allow puma to be restarted by `rails restart` command.
#plugin :tmp_restart

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"

# 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

I want to start using systemd since its preferred for ubuntu 16.04 我想开始使用systemd,因为它是Ubuntu 16.04的首选

I Managed To start Puma but 我设法开始了彪马,但

hi i managed to make puma server run. 嗨,我设法使彪马服务器运行。 but now i am getting nginx upstream connection timed out. 但是现在我正在使nginx上游连接超时。 here is out put from systemctl status puma 这是从systemctl状态彪马出来的

/system.slice/puma.service
       ├─ 1258 puma: cluster worker 0: 15954 [mystore2.rentcallcenter.com]
       └─15954 puma 3.10.0 (unix:///var/www/mystore2.rentcallcenter.com/shared/sockets/puma.sock)

here is my nginx server block file 这是我的nginx服务器阻止文件

    upstream app {
    # Path to Puma SOCK file, as defined previously
    server unix:///var/www/mystore2.rentcallcenter.com/shared/sockets/puma.sock fail_timeout=0;
}

server {
    listen 80;
    listen [::]:80;
    server_name mystore2.rentcallcenter.com;

    root /var/www/mystore2.rentcallcenter.com/public;

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_pass http://app;
        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;
}`

i managed to connect to make my rails app run with puma and nginx final config 我设法连接以使我的rails应用程序与puma和nginx最终配置一起运行

nginx server block file
 upstream app {
    # Path to Puma SOCK file, as defined previously
    server unix:///var/www/mystore2.rentcallcenter.com/shared/sockets/puma.sock fail_timeout=0;
}

server {
    listen 80;
    listen [::]:80;
    server_name mystore2.rentcallcenter.com;

    root /var/www/mystore2.rentcallcenter.com/public;

    try_files $uri/index.html $uri @app;

    location @app {
        proxy_pass http://app;
        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;
}

and puma.service 和puma.service

[Unit]
Description=Puma HTTP Server
After=network.target

# Uncomment for socket activation (see below)
# Requires=puma.socket

[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple

# Preferably configure a non-privileged user
User=www-data

# The path to the puma application root
# Also replace the "<WD>" place holders below with this path.
WorkingDirectory=/var/www/mystore2.rentcallcenter.com

# Helpful for debugging socket activation, etc.
# Environment=PUMA_DEBUG=1

# The command to start Puma. This variant uses a binstub generated via
# `bundle binstubs puma --path ./sbin` in the WorkingDirectory
# (replace "<WD>" below)
# ExecStart=/home/ashish/.rbenv/shims/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem

# Variant: Use config file with `bind` directives instead:
ExecStart= /home/ashish/.rbenv/shims/puma -C /var/www/mystore2.rentcallcenter.com/config/puma.rb
# Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub

Restart=always

[Install]
WantedBy=multi-user.target

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM