Capistrano3でデプロイのトライ中です。
sockファイルとpidファイルのところで様々なエラーで困っています。
デプロイ中のエラーは以下になります。
log/unicorn.log I, [2019-05-10T10:31:46.865146 #15282] INFO -- : Refreshing Gem list F, [2019-05-10T10:31:50.271210 #15282] FATAL -- : error adding listener addr=/var/run/unicorn.sock bundler: failed to load command: unicorn (/usr/share/nginx/html/shared/bundle/ruby/2.3.0/bin/unicorn) Errno::EACCES: Permission denied - connect(2) for /var/run/unicorn.sock
/var/log/nginx/error.log 2019/05/10 11:22:56 [crit] 13780#13780: *2786 connect() to unix:/var/run/unicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 209.17.97.74, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/var/run/unicorn.sock:/", host: "XXXX-XXXX.com" 2019/05/10 11:51:07 [notice] 19265#19265: signal process started ファイルが無いとエラーが出ています。
パーミッションのエラーみたいなので$ ls -l /var/run/unicorn.sockで確認しようとすると
ls: cannot access /var/run/unicorn.sock: No such file or directoryとなり
どうやらファイルが作成されていないようです。
Nginxとunicornの設定は以下のようにしています。
config/unicorn/production.rb ワーカーの数。後述 $worker = 2 #何秒経過すればワーカーを削除するのかを決める $timeout = 30 #自分のアプリケーション名、currentがつくことに注意。 $app_dir = "/usr/share/nginx/html/current" #リクエストを受け取るポート番号を指定。後述 listen "/var/run/unicorn.sock" pid "/var/run/unicorn.pid" #PIDの管理ファイルディレクトリ #$pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir #エラーログを吐き出すファイルのディレクトリ $std_log = File.expand_path 'log/unicorn.log', $app_dir $err_log = File.expand_path 'log/unicorn.log', $app_dir # 上記で設定したものが適応されるよう定義 worker_processes $worker working_directory $app_dir #stderr_path $std_log stderr_path $err_log stdout_path $std_log timeout $timeout listen $listen pid $pid #ホットデプロイをするかしないかを設定 preload_app true root = "/usr/share/nginx/html/current" before_exec do |server| ENV['BUNDLE_GEMFILE'] = "#{root}/Gemfile" end #fork前に行うことを定義。後述 before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! old_pid = "#{server.config[:pid]}.oldbin" if old_pid != server.pid begin sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU Process.kill :QUIT, File.read(old_pid).to_i rescue Errno::ENOENT, Errno::ESRCH end end end #fork後に行うことを定義。後述 after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
lib/capistrano/taske/unicorn.rb #unicornのpidファイル、設定ファイルのディレクトリを指定 namespace :unicorn do task :environment do set :unicorn_pid, "/var/run/unicorn.pid" set :unicorn_config, "#{current_path}/config/unicorn/production.rb" end #unicornをスタートさせるメソッド def start_unicorn within current_path do execute :bundle, :exec, :unicorn, "-c #{fetch(:unicorn_config)} -E #{fetch(:rails_env)} -D" end end #unicornを停止させるメソッド def stop_unicorn execute :kill, "-s QUIT $(< #{fetch(:unicorn_pid)})" end #unicornを再起動するメソッド def reload_unicorn execute :kill, "-s USR2 $(< #{fetch(:unicorn_pid)})" end #unicronを強制終了するメソッド def force_stop_unicorn execute :kill, "$(< #{fetch(:unicorn_pid)})" end #unicornをスタートさせるtask desc "Start unicorn server" task start: :environment do on roles(:app) do start_unicorn end end #unicornを停止させるtask desc "Stop unicorn server gracefully" task stop: :environment do on roles(:app) do stop_unicorn end end #既にunicornが起動している場合再起動を、まだの場合起動を行うtask desc "Restart unicorn server gracefully" task restart: :environment do on roles(:app) do if test("[ -f #{fetch(:unicorn_pid)} ]") reload_unicorn else start_unicorn end end end #unicornを強制終了させるtask desc "Stop unicorn server immediately" task force_stop: :environment do on roles(:app) do force_stop_unicorn end end end
/etc/nginx/conf.d/https.conf upstream app_server { server unix:/var/run/unicorn.sock; } map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 443 ssl http2; server_name wonder-gate.com; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { root /usr/share/nginx/html/current/public; index index.html index.htm; try_files $uri/index.html $uri @app; } ssl_protocols TLSv1.2; ssl_ciphers EECDH+AESGCM:EECDH+AES; ssl_ecdh_curve prime256v1; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/letsencrypt/live/wonder-gate.com/fullchain.pem; upstream app_server { ssl_certificate_key /etc/letsencrypt/live/wonder-gate.com/privkey.pem; #error_page 500 502 504 /50x.html; #location = /50x.html { #root /usr/share/nginx/html; #} proxy_connect_timeout 130; proxy_read_timeout 130; proxy_send_timeout 130; client_max_body_size 2G; error_page 404 /404.html; error_page 500 502 504 /500.html; #try_files $uri/index.html $uri @app; location @app { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_pass http://app_server; } set $maintenance false; if (-e /var/tmp/do_maintenance) { set $maintenance true; } if ($uri ~ "^/maintenance/") { set $maintenance false; } if ($remote_addr = 153.126.131.89) { set $maintenance false; } error_page 503 /maintenance/maintenance.html; location /maintenance/ { root /var/www; } if ($maintenance = true) { return 503; } }
Nginxの設定の部分の
upstream app_server {
server unix:/var/run/unicorn.sock;
}
のところでファイルが作成されると思っていたのですが違うのでしょうか?
デプロイ中に/var/run/unicorn.sockのファイルが作成されれば、また違う展開になると思うのですがどなかたご教授お願いできませんでしょうか?
また/ver/run/unicorn.pidファイルも作成されていません。
宜しくお願いいたします。
回答1件
あなたの回答
tips
プレビュー