質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

セグメンテーション違反

セグメンテーション違反とは、ソフトウェア実行時に発生するエラーのひとつであり、許可されていないメモリにアクセスしたときに起きます。しばしば、ポインタの不適切な使用、またはバッファオーバーフローによって起こります。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

Q&A

解決済

1回答

1619閲覧

EC2でunicornを起動するとSegmentation faultになる

Baru_blog

総合スコア0

unicorn

Unicornは、汎用のRackアプリケーションサーバ。RackとWebサーバーの機能を併せ持ちます。レスポンス処理や、Nginx単体がRackの機能をサポートしていない事から、一般的にはNginx+Unicorn+Railsの構成を取って用います。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

セグメンテーション違反

セグメンテーション違反とは、ソフトウェア実行時に発生するエラーのひとつであり、許可されていないメモリにアクセスしたときに起きます。しばしば、ポインタの不適切な使用、またはバッファオーバーフローによって起こります。

Amazon EC2

Amazon EC2は“Amazon Elastic Compute Cloud”の略称です。Amazon Web Services(AWS)の一部であり、仮想化されたWebサーバーのコンピュータリソースをレンタルできるサービスです。

0グッド

0クリップ

投稿2021/02/19 08:44

編集2021/02/19 10:26

前提・実現したいこと

EC2に既存のアプリをデプロイしている最中です。

unicornを起動する際にSegmentation faultになってしまいました。

実行したコマンド

[name@****** app名]$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D

発生している問題・エラーメッセージ

# 起動に失敗しました。詳細については、stderrログを確認してください master failed to start, check stderr log for details
# unicorn_stderr.log INFO -- : Refreshing Gem list /home/name/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/unicorn-5.8.0/lib/unicorn.rb:80: [BUG] Segmentation fault at 0x0000000000000000 ruby 3.0.0p0 (2020-12-25 revision *******) [x86_64-linux]

該当のソースコード

rails

1 2# unicorn.rb 3 4worker_processes 1 5 6pid File.expand_path('../../tmp/pids/unicorn.pid', __FILE__) 7 8listen 3000 9 10stderr_path File.expand_path('../../log/unicorn_stderr.log', __FILE__) 11stdout_path File.expand_path('../../log/unicorn_stdout.log', __FILE__) 12 13timeout 60 14 15preload_app true 16 17check_client_connection false 18 19run_once = true 20 21before_fork do |server, worker| 22 defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect! 23 24 if run_once 25 run_once = false 26 end 27 28 old_pid = "#{server.config[:pid]}.oldbin" 29 if File.exist?(old_pid) && server.pid != old_pid 30 begin 31 sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU 32 Process.kill(sig, File.read(old_pid).to_i) 33 rescue Errno::ENOENT, Errno::ESRCH => e 34 logger.error e 35 end 36 end 37end 38 39after_fork do |_server, _worker| 40 defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection 41end 42

下記がエラーメッセージに記載されていたファイルです。

rails

1# /home/name/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/unicorn-5.8.0/lib/unicorn.rb 2 3# -*- encoding: binary -*- 4require 'etc' 5require 'stringio' 6require 'kgio' 7require 'raindrops' 8require 'io/wait' 9 10begin 11 require 'rack' 12rescue LoadError 13 warn 'rack not available, functionality reduced' 14end 15 16# :stopdoc: 17# Unicorn module containing all of the classes (include C extensions) for 18# running a Unicorn web server. It contains a minimalist HTTP server with just 19# enough functionality to service web application requests fast as possible. 20# :startdoc: 21 22# unicorn exposes very little of an user-visible API and most of its 23# internals are subject to change. unicorn is designed to host Rack 24# applications, so applications should be written against the Rack SPEC 25# and not unicorn internals. 26module Unicorn 27 28 # Raised inside TeeInput when a client closes the socket inside the 29 # application dispatch. This is always raised with an empty backtrace 30 # since there is nothing in the application stack that is responsible 31 # for client shutdowns/disconnects. This exception is visible to Rack 32 # applications unless PrereadInput middleware is loaded. This 33 # is a subclass of the standard EOFError class and applications should 34 # not rescue it explicitly, but rescue EOFError instead. 35 ClientShutdown = Class.new(EOFError) 36 37 # :stopdoc: 38 39 # This returns a lambda to pass in as the app, this does not "build" the 40 # app (which we defer based on the outcome of "preload_app" in the 41 # Unicorn config). The returned lambda will be called when it is 42 # time to build the app. 43 def self.builder(ru, op) 44 # allow Configurator to parse cli switches embedded in the ru file 45 op = Unicorn::Configurator::RACKUP.merge!(:file => ru, :optparse => op) 46 if ru =~ /.ru$/ && !defined?(Rack::Builder) 47 abort "rack and Rack::Builder must be available for processing #{ru}" 48 end 49 50 # always called after config file parsing, may be called after forking 51 lambda do |_, server| 52 inner_app = case ru 53 when /.ru$/ 54 raw = File.read(ru) 55 raw.sub!(/^__END__\n.*/, '') 56 eval("Rack::Builder.new {(\n#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru) 57 else 58 require ru 59 Object.const_get(File.basename(ru, '.rb').capitalize) 60 end 61 62 if $DEBUG 63 require 'pp' 64 pp({ :inner_app => inner_app }) 65 end 66 67 return inner_app unless server.default_middleware 68 69 middleware = { # order matters 70 ContentLength: nil, 71 Chunked: nil, 72 CommonLogger: [ $stderr ], 73 ShowExceptions: nil, 74 Lint: nil, 75 TempfileReaper: nil, 76 } 77 78 # return value, matches rackup defaults based on env 79 # Unicorn does not support persistent connections, but Rainbows! 80 # and Zbatery both do. Users accustomed to the Rack::Server default 81 # middlewares will need ContentLength/Chunked middlewares. 82 case ENV["RACK_ENV"] 83 when "development" 84 when "deployment" 85 middleware.delete(:ShowExceptions) 86 middleware.delete(:Lint) 87 else 88 return inner_app 89 end 90 Rack::Builder.new do 91 middleware.each do |m, args| 92 use(Rack.const_get(m), *args) if Rack.const_defined?(m) 93 end 94 run inner_app 95 end.to_app 96 end 97 end 98 99 # returns an array of strings representing TCP listen socket addresses 100 # and Unix domain socket paths. This is useful for use with 101 # Raindrops::Middleware under Linux: https://yhbt.net/raindrops/ 102 def self.listener_names 103 Unicorn::HttpServer::LISTENERS.map do |io| 104 Unicorn::SocketHelper.sock_name(io) 105 end + Unicorn::HttpServer::NEW_LISTENERS 106 end 107 108 def self.log_error(logger, prefix, exc) 109 message = exc.message 110 message = message.dump if /[[:cntrl:]]/ =~ message 111 logger.error "#{prefix}: #{message} (#{exc.class})" 112 exc.backtrace.each { |line| logger.error(line) } 113 end 114 F_SETPIPE_SZ = 1031 if RUBY_PLATFORM =~ /linux/ 115 116 def self.pipe # :nodoc: 117 Kgio::Pipe.new.each do |io| 118 io.close_on_exec = true # remove this when we only support Ruby >= 2.0 119 120 # shrink pipes to minimize impact on /proc/sys/fs/pipe-user-pages-soft 121 # limits. 122 if defined?(F_SETPIPE_SZ) 123 begin 124 io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE) 125 rescue Errno::EINVAL 126 # old kernel 127 rescue Errno::EPERM 128 # resizes fail if Linux is close to the pipe limit for the user 129 # or if the user does not have permissions to resize 130 end 131 end 132 end 133 end 134 # :startdoc: 135end 136# :enddoc: 137 138%w(const socket_helper stream_input tee_input http_request configurator 139 tmpio util http_response worker http_server).each do |s| 140 require_relative "unicorn/#{s}" 141end

試したこと

・ unicorn.rbのpidやstderr_pathのパスを変えてみる → 書き込みエラーが出るだけ

・ メモリの容量が足りない可能生から、EC2のインスタンスタイプをt2.microからt2.xlargeに変えてみる → 変化なし

・ unicornのバージョンを落としてみる → rubyが3.0.0のため落とせない

補足情報(FW/ツールのバージョンなど)

・ MacOS
・ Rails 6.1.0
・ Ruby 3.0.0
・ MySQL 8.0.23
・ unicron 5.8.0
・ nginx 1.18.0
・ Amazon Linux 2 AMI (HVM), SSD Volume Type
・ インスタンスタイプ t2.micro

下記のQiita1を参考にデプロイを進めました。

デプロイ参考記事

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Rubyのバージョンを2.7.2、unicornのバージョンを5.4.1にダウングレードしたら動きました。

どうやらRubyの3.0.0にunicornが対応していないらしいです。

投稿2021/02/20 08:54

Baru_blog

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問