Unicorn unable to write pid file
Actually, the error message has already told you why:
directory for pid=/home/deploy/apps/shared/pids/unicorn.pid not writable
So, does the directory /home/deploy/apps/shared/pids
exist? If not, you should call mkdir
to create it.
Write error when trying to run unicorn: directory for pid=/var/www/twimpush/pids/unicorn.pid not writable (ArgumentError)
When I cloned my git repo, it didn't include the empty pids
folder inside my repo. I added it with mkdir pids
, in addition to the other required folders mentioned in the first guide, and it worked.
How should I manage the path to unicorn pid file on production?
The simplest way to manage paths that differ between environments is via environment variables. Eg: ENV['PIDS']
...
From the unicorn config file above, pids
are always going to be dumped into #{APP_ROOT}/tmp
, no matter what the environment...
Check out Foreman and in particular the upstart export (if you're on Ubuntu) - (Introducing Foreman)
Unicorn PID is stale on initial deploy
Your problem is when you're deploying you aren't probably killing the unicorn master pid before you run unicorn again. I think the problem is in your capistrano recipe...
With unicorn we usually save the pid in a shared folder in production environment when we start the server, where you save also the logs, uploads and other sfuff that is independent of each environment.
see this two tasks of one of my deploy.rb:
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
run "ps aux | grep unicorn_rails | head -n 1 | awk '{print $2}' > #{deploy_to}/shared/tmp/pids/unicorn.pid"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat #{deploy_to}/shared/tmp/pids/unicorn.pid`"
end
so when i stop unicorn i always kill the master pid that is in the shared folder and when i start it, i make a copy of this pid to a shared folder in the production project.
In this case, my restart task is calling first the stop and then the start, but this isn't zero down time...
The following link have a recipe with zero down time if want to give a try:
https://github.com/railscasts/373-zero-downtime-deployment/blob/master/blog-after/config/recipes/templates/unicorn.rb.erb
Nginx and Unicorn not working due to unicorn.sock file error
A socket is a special kind of file used for inter process communication.
If you you run ls -la
sockets have a leading s
in the mode string.
Yours should look something like this:
srwxrwxrwx /tmp/unicorn.sock
If you have created /tmp/unicorn.sock
as a file manually, delete it.
As a side note: The tutorial you are using is 3 years old and so your setup is outdated from the start.
Unicorn/Nginx process missing, socket open
Still not sure how this happens, but the following solution seems to work:
lsof /tmp/my_app.socket
- lists the pids
kill -9 pid
- (replace 'pid' with one of those listed)
Then cap deploy:start
from the local terminal.
Related Topics
Ruby Koan 151 Raising Exceptions
Ruby Concatenate Strings and Add Spaces
No Database Connection in Rails Console
Simple_Form: Remove Outer Label for an Inline Checkbox with Label
Ruby Class with Static Method Calling a Private Method
Passing Param Values to Redirect_To as Querystring in Rails
Ruby: Get All Keys in a Hash (Including Sub Keys)
How to Introspect Things in Ruby
Can't Convert Fixnum to String During Rake Db:Create
How to Get a List of All Tags While Using the Gem 'Acts-As-Taggable-On' in Rails (Not the Counts)
How to Render a Partial in Sinatra View (Haml in Haml)
Rails: Respond_To JSON and HTML
Ruby: Cannot Parse Excel File Exported as CSV in Os X