switchflip
switchflip

Reputation: 403

Unicorn periodically fails to restart after deploy - stale PID

I've been trying to solve this problem on my own for sometime and have not had any luck. It occurs when I redeploy my rails app about 10% of the time. The other 90% of the time the deploy goes smoothly.

I've tried and tried again, but have not succeeded. So I'm turning to the SO masses for some help.

A little about my stack: I'm using chef to generate my instance on vagrant running on Ubuntu 14.04 and using upstart to oversea unicorn.

The error:

srv/www/rails/releases/ef6a792a19f8bb9d36ef4d0ab15ee38ca91a0cd1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:206:in `pid=': Already running on PID:17694 (or pid=/srv/www/rails/shared/pids/unicorn.pid is stale) (ArgumentError)
from /srv/www/rails/releases/ef6a792a19f8bb9d36ef4d0ab15ee38ca91a0cd1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:135:in `start'
from /srv/www/rails/releases/ef6a792a19f8bb9d36ef4d0ab15ee38ca91a0cd1/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
from /srv/www/rails/releases/ef6a792a19f8bb9d36ef4d0ab15ee38ca91a0cd1/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'
from /srv/www/rails/releases/ef6a792a19f8bb9d36ef4d0ab15ee38ca91a0cd1/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'

My unicorn upstart script is here. And my unicorn configuration file can be viewed here.

Please let me know if you need any more information. And above thanks for your help and time.

Upvotes: 2

Views: 1828

Answers (1)

Riley Mills
Riley Mills

Reputation: 21

I've been running into this too. You need to clear out the old PID file in your upstart script, before you try running Unicorn.

rm /srv/www/rails/shared/pids/unicorn.pid

Alternatively, take a look at https://github.com/tablexi/capistrano3-unicorn for ways to determine server state and start/restart Unicorn appropriately.

Upvotes: 2

Related Questions