1.エラーの様子
まず、自動デプロイを設定し、実行コマンドを行いました。すると下記のようになりました。
Neverland:chat-space-kai kontatomoya$ bundle exec cap production deploy
#自動deployのコマンドを打ちました
#ここまでまでエラーなし(省略)
00:51 unicorn:start
unicorn is running...
unicorn restarting...
01 kill -s USR2 `cat /var/www/chat-space-kai/shared/tmp/pids/unicorn.pid`
✔ 01 ec2-user@13.112.68.204 0.609s
Skipping task `unicorn:restart'.
Capistrano tasks may only be invoked once. Since task `unicorn:restart' was previously invoked, invoke("unicorn:restart") at config/deploy.rb:43 will be skipped.
If you really meant to run this task again, use invoke!("unicorn:restart")
THIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
https://github.com/capistrano/capistrano/issues/1686
#↑エラーの全文
#以下エラーなし(省略)
黄色い文章(筆者の環境では赤文字でした)を読むとバージョン違うんじゃない?と書いてあって心当たりがなかったのでTHIS BEHAVIOR MAY CHANGE IN A FUTURE VERSION OF CAPISTRANO. Please join the conversation here if this affects you.
の部分で検索をかけたところ下記の記事を見つけました。
https://github.com/capistrano/capistrano/issues/1686
https://obel.hatenablog.jp/entry/20181030/1540880580
この中ではunicornのrestartができないのをどうにかすれば良い。とありましたが、restartコマンドは挿入した記憶があるため分からない。そしてgithubの更新を反映できないという状況になってました。
2.原因と解決策
結論から言いますと下記のファイルにrestartの実行を2回重複して記載していたためエラーを起こしており、その部分を取り除けば解決しました。
lock '3.11.2'
set :application, 'chat-space-kai'
set :repo_url, 'git@github.com:KONTA2019/chat-space-kai.git'
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
set :rbenv_type, :user
set :rbenv_ruby, '2.5.1'
set :ssh_options, auth_methods: ['publickey'],
keys: ['~/.ssh/ChatSpace.pem']
set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }
set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" }
set :keep_releases, 5
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
invoke 'unicorn:restart'
end
end
#↑この部分が不要です
set :linked_files, %w{ config/secrets.yml }
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
invoke 'unicorn:restart'
end
desc 'upload secrets.yml'
task :upload do
on roles(:app) do |host|
if test "[ ! -d #{shared_path}/config ]"
execute "mkdir -p #{shared_path}/config"
end
upload!('config/secrets.yml', "#{shared_path}/config/secrets.yml")
end
end
before :starting, 'deploy:upload'
after :finishing, 'deploy:cleanup'
end
3.この記事で伝えたかったこと
題名のエラーが目立つため、バージョンの間違いによる「互換性の問題に違いない」とドツボにはまってしまうことがあるかもしれませんが、もしかしたら筆者のように簡単なことで止まってるかもしれないので、'app/config/deploy.rb'を見直してみるとエラーが発見できるかもしれませんよ!ということを伝えたいと思ってこの記事を書きました。
何かのご参考になればと思います。