Capistranoでデプロイをじっこうしたところunicornの再起動taskでえらーがでてしまい、解決出来ずに困っております。
エラーの内容は以下になります。
[96e0a245] kill: sending signal to 3784 failed: No such process (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as kinoko@153.126.131.89: kill exit status: 1 kill stdout: kill: sending signal to 3784 failed: No such process kill stderr: Nothing written Caused by: SSHKit::Command::Failed: kill exit status: 1 kill stdout: kill: sending signal to 3784 failed: No such process kill stderr: Nothing written /home/vagrant/chibi/chibi/lib/capistrano/tasks/unicorn.rb:22:in `reload_unicorn' /home/vagrant/chibi/chibi/lib/capistrano/tasks/unicorn.rb:51:in `block (3 levels) in <top (required)>' Tasks: TOP => unicorn:restart (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as kinoko@153.126.131.89: kill exit status: 1 kill stdout: kill: sending signal to 3784 failed: No such process kill stderr: Nothing written
lib/capistrano/tasks/unicorn.rb #unicornのpidファイル、設定ファイルのディレクトリを指定 namespace :unicorn do task :environment do set :unicorn_pid, "#{current_path}/tmp/pids/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)})" # ここが22行目です。 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 # ここが51行目です。 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
エラーで22行目と51行目の記述が有り、def reload_unicornのところで発生したunicorn再起動のエラーのようです。
vim /usr/share/nginx/html/current/tmp/pids/unicorn.pid で確認すると 3784 とだけ記述されていました。 ここをkill出来ないというエラーかと思います。
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" と記述していますが、ここが間違っているのでしょうか?
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"の指定では
/usr/share/nginx/html/current/tmp/pids/unicorn.pidのファイルを取得出来ていないということなのでしょうか?
どなたか詳しい方のご教示お願いします。
追記 (Processが記述されているファイルがあるので追記します。)
config/unicorn/production.rb #ワーカーの数。後述 $worker = 2 #何秒経過すればワーカーを削除するのかを決める $timeout = 30 #自分のアプリケーション名、currentがつくことに注意。 $app_dir = "/usr/share/nginx/html/current" #リクエストを受け取るポート番号を指定。後述 $listen = File.expand_path 'tmp/sockets/.unicorn.sock', $app_dir #PIDの管理ファイルディレクトリ $pid = File.expand_path 'tmp/pids/unicorn.pid', $app_dir #エラーログを吐き出すファイルのディレクトリ $std_log = File.expand_path 'log/unicorn.log', $app_dir # 上記で設定したものが適応されるよう定義 worker_processes $worker working_directory $app_dir stderr_path $std_log stdout_path $std_log timeout $timeout listen $listen pid $pid #ホットデプロイをするかしないかを設定 preload_app true #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 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
追記 (回答に記述したファイル内容がわかりにくいので改めて追記しました。)
config/deploy.rb lock "~> 3.11.0" set :application, "XXXXXX" set :rails_env, "production" set :repo_url, "https://github.com/XXXXXXXXXXX/XXXXX.git" set :branch, 'master' set :conditionally_migrate, true set :user, 'XXXXX' set :pty, true set :use_sudo, false set :stage, :production set :deploy_via, :remote_cache set :deploy_to, "/usr/share/nginx/html" set :format, :pretty set :log_level, :debug set :keep_releases, 5 set :rbenv_type, :user set :rbenv_ruby_version, 'ruby_2.3.1' set :rbenv_custom_path, '/home/XXXXX/.rbenv' set :linked_dirs, fetch(:linked_dirs, []).push( 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads', 'public/tmp', 'db' ) set :linked_files, fetch(:linked_files, []).push( 'config/database.yml', 'config/secrets.yml', '.env' ) set :whenever_identifier, -> { "#{fetch(:application)}_#{fetch(:stage)}" } set :whenever_roles, ->{ :batch } namespace :deploy do desc 'Restart application' task :restart do invoke 'unicorn:restart' end desc 'Create database' task :db_create do on roles(:db) do |host| with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:create' end end end end desc 'Run seed' task :seed do on roles(:app) do with rails_env: fetch(:rails_env) do within current_path do execute :bundle, :exec, :rake, 'db:seed' end end end end after :publishing, :restart after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do end end end namespace :maintenance do desc 'start maintenance' task :on do on roles(:web) do target_dir = "#{shared_path}/public/tmp" target_path = "#{target_dir}/maintenance.html" source_path = "#{release_path}/public/maintenance.html" execute :mkdir, '-p', target_dir execute :cp, '-f', source_path, target_path end end desc 'stop maintenance' task :off do on roles(:web) do target = "#{shared_path}/public/tmp/maintenance.html" execute :rm, target if test "[ -f #{target} ]" end end end
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/23 02:37
2019/04/23 03:16
2019/04/23 05:40
2019/04/23 05:54
2019/04/23 13:31
2019/04/23 13:36
2019/04/23 13:47