divの閉じタグがないよ

映画/音楽/時々プログラミング

Capistrano備忘録

Capistranoデプロイでエラーがでた

デプロイ時にunicornをrestartするのだけれど、そこで何回も引っかかる。

sudo /etc/init.d/unicorn start

とすると

already unicorn started

と出る。

さらに、

sudo /etc/init.d/unicorn restart

sudo /etc/init.d/unicorn stop

とすると、

そのようなプロセスはありません

と出てくる。

いわゆるよくあるkillコマンドを叩いてもどうにもならないので、困っていました。 以下がcapistaranoエラーです。 ちなみにunicronは/init.d以下に自動起動スクリプトを書いていたので、さらに謎は深まるばかり….

00:26 unicorn:restart
      01 kill -s USR2 $(< /var/www/Vook/current/tmp/pids/unicorn.pid)
      01 kill:
      01 sending signal to 4082 failed
      01 :
      01 そのようなプロセスはありません
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as Daiki@52.198.21.134: kill exit status: 1
kill stdout: Nothing written
kill stderr: kill: sending signal to 4082 failed: そのようなプロセスはありません

SSHKit::Command::Failed: kill exit status: 1
kill stdout: Nothing written
kill stderr: kill: sending signal to 4082 failed: そのようなプロセスはありません
/Users/takayadaiki/projects/Vook/lib/capistrano/tasks/unicorn.rb:22:in `reload_unicorn'
/Users/takayadaiki/projects/Vook/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 Daiki@52.198.21.134: kill exit status: 1
kill stdout: Nothing written
kill stderr: kill: sending signal to 4082 failed: そのようなプロセスはありません


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


 DEBUG [e906a1b0] Command: if test ! -d /var/www/Vook/releases/20170125061945; then echo "Directory does not exist '/var/www/Vook/releases/20170125061945'" 1>&2; false; fi

 DEBUG [e906a1b0] Finished in 0.084 seconds with exit status 0 (successful).

  INFO [f744d9da] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate as Daiki@52.198.21.134

 DEBUG [f744d9da] Command: cd /var/www/Vook/releases/20170125061945 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.1.3" RAILS_ENV="staging" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate )

  INFO [f744d9da] Finished in 3.577 seconds with exit status 0 (successful).

  INFO [0223c969] Running /usr/bin/env ln -s /var/www/Vook/releases/20170125061945 /var/www/Vook/releases/current as Daiki@52.198.21.134

 DEBUG [0223c969] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.1.3" ; /usr/bin/env ln -s /var/www/Vook/releases/20170125061945 /var/www/Vook/releases/current )

  INFO [0223c969] Finished in 0.148 seconds with exit status 0 (successful).

  INFO [09437040] Running /usr/bin/env mv /var/www/Vook/releases/current /var/www/Vook as Daiki@52.198.21.134

 DEBUG [09437040] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.1.3" ; /usr/bin/env mv /var/www/Vook/releases/current /var/www/Vook )

  INFO [09437040] Finished in 0.127 seconds with exit status 0 (successful).

 DEBUG [07bf5446] Running [ -f /var/www/Vook/current/tmp/pids/unicorn.pid ] as Daiki@52.198.21.134

 DEBUG [07bf5446] Command: [ -f /var/www/Vook/current/tmp/pids/unicorn.pid ]

 DEBUG [07bf5446] Finished in 0.134 seconds with exit status 0 (successful).

  INFO [c30db33d] Running /usr/bin/env kill -s USR2 $(< /var/www/Vook/current/tmp/pids/unicorn.pid) as Daiki@52.198.21.134

 DEBUG [c30db33d] Command: ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.1.3" ; /usr/bin/env kill -s USR2 $(< /var/www/Vook/current/tmp/pids/unicorn.pid) )

 DEBUG [c30db33d]     kill: 

 DEBUG [c30db33d]     sending signal to 4082 failed

 DEBUG [c30db33d]     : 

 DEBUG [c30db33d]     そのようなプロセスはありません

結局、解決策としては

tmp/pids/unicorn.pid

を削除することで解決できた。

僕のアプリケーションではcapistrano3-unicornを使っていなかったためにunicorn:restartの例外処理の記述がなく、前のプロセスが残ってしまったまま?stopしようとしていたらしい。

完全な備忘録なので同じようなエラーに困ってる方がいれば、コメントください。