Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicorn unable to write pid file

I am using deploying a Ruby on Rails app to a Linode VPS using Capistrano. I am using Unicorn as the application server and Nginx as the proxy. My problem is that I am not able to start Unicorn because of an apparent permissions issue, but I'm having a hard time tracking it down.

Unicorn is started using this Capistrano task:

task :start, :roles => :app, :except => { :no_release => true } do
    run <<-CMD
      cd #{current_path} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D
    CMD
end

I get back and ArgumentError indicating that the path to the pid file is not writeable.

cap unicorn:start                                                                           master [d4447d3] modified
  * executing `unicorn:start'
  * executing "cd /home/deploy/apps/gogy/current && /home/deploy/apps/gogy/current/bin/unicorn -c /home/deploy/apps/gogy/shared/config/unicorn.rb -E production -D"
    servers: ["66.228.52.4"]
    [66.228.52.4] executing command
 ** [out :: 66.228.52.4] /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:88:in `reload':
 ** [out :: 66.228.52.4] directory for pid=/home/deploy/apps/shared/pids/unicorn.pid not writable (ArgumentError)
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:84:in `each'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:84:in `reload'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/configurator.rb:65:in `initialize'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:102:in `new'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/lib/unicorn/http_server.rb:102:in `initialize'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/bin/unicorn:121:in `new'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/shared/bundle/ruby/1.8/gems/unicorn-4.1.1/bin/unicorn:121
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/current/bin/unicorn:16:in `load'
 ** [out :: 66.228.52.4] from /home/deploy/apps/gogy/current/bin/unicorn:16
 ** [out :: 66.228.52.4] master failed to start, check stderr log for details
    command finished in 1032ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd /home/deploy/apps/gogy/current && /home/deploy/apps/gogy/current/bin/unicorn -c /home/deploy/apps/gogy/shared/config/unicorn.rb -E production -D'" on 66.228.52.4

Finally, here is the relevant sections of my Unicorn configuration file (unicorn.rb)

# Ensure that we're running in the production environment
rails_env = ENV['RAILS_ENV'] || 'production'

# User to run under
user 'deploy', 'deploy'

# We will spawn off two worker processes and one master process
worker_processes 2

# set the default working directory
working_directory "/home/deploy/apps/gogy/current"

# This loads the application in the master process before forking
# worker processes
# Read more about it here:
# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true

timeout 30

# This is where we specify the socket.
# We will point the upstream Nginx module to this socket later on
listen "/home/deploy/apps/shared/sockets/unicorn.sock", :backlog => 64

pid "/home/deploy/apps/shared/pids/unicorn.pid"

# Set the path of the log files 
stderr_path "/home/deploy/apps/gogy/current/log/unicorn.stderr.log"
stdout_path "/home/deploy/apps/gogy/current/log/unicorn.stdout.log"

I'm deploying with Capistrano under the 'deploy' user and group and that's what Unicorn should be run under also.

Does anyone have any ideas why Unicorn can't write out the pid file? Any help would be greatly appreciated!!!

  • Mike
like image 367
Mike Filbin Avatar asked Jan 02 '12 22:01

Mike Filbin


3 Answers

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.

like image 164
Limbo Peng Avatar answered Sep 21 '22 19:09

Limbo Peng


Unicorn process is running in background(-d), type

ps aux | grep unicorn

and kill running unicorn process then start once again.

like image 25
Pravin Mishra Avatar answered Sep 25 '22 19:09

Pravin Mishra


in capistrano 3; if we change roles to :all, then while deployment capistrano saying; WARN [SKIPPING] No Matching Host for ..... and after deployment all symlinks not working anymore. And if tmp/pids folder in symlink array, then unicorn can't find the tmp/pids folder and saying unicorn.pid is not writable.

So we must use; roles: %w{web app db} instead of roles :all.

Sample server line at production.rb;

server 'YOUR_SERVER_IP', user: 'YOUR_DEPLOY_USER', roles: %w{web app db}, ssh_options: { forward_agent: true }

like image 20
Farukca Avatar answered Sep 21 '22 19:09

Farukca