Unable to bind to port 80, but running on the current shell works without any issues

Rpj picture Rpj · Jul 16, 2013 · Viewed 15.9k times · Source

I get the following error while trying to run "cap production unicorn:start"

F, [2013-07-12T04:36:18.134045 #28998] FATAL -- : error adding listener addr=0.0.0.0:80
/home/ec2-user/apps/foo_prod/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/socket_helper.rb:147:in `initialize': Permission denied - bind(2) (Errno::EACCES)

Running the following command manually, does work without any issues. What could be the problem here?

rvmsudo unicorn_rails -c config/unicorn/production.rb -D --env production

Answer

Iuri G. picture Iuri G. · Jul 17, 2013

You need root access to bind to lower ports like port 80. Command rvmsudo executes in root context and therefore it works.

Cap task executes in a normal user context (probably deploy) depending on your configuration. You should add sudo ability to cap deploy user and make sure your cap task uses sudo to start unicorn.