Skip to content

Instantly share code, notes, and snippets.

@ono
Created August 3, 2011 15:49
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ono/1122965 to your computer and use it in GitHub Desktop.
Workaround to avoid "adding listener failed addr=0.0.0.0:8080 (in use)" error by unicorn on FreeBSD jail host
# If you run unicorn on FreeBSD Jail, you might experience the following error
# when you send some signals such as HUP, USR2 to master process.
# adding listener failed addr=0.0.0.0:8080 (in use)
#
# This snippet gives you a workaround without specifying IP address.
# Returns true if the host is in the Jail.
def in_jail?
`sysctl security.jail.jailed` =~ /security.jail.jailed: 1/ ? true : false
end
# Returns IP address of the host. You can consider using Socket.ip_address_list
# if you are on ruby 1.9.2. However the following method is good enough since it
# is only for the hosts in the Jail.
def getIP
require 'socket'
IPSocket.getaddress(Socket.gethostname)
end
if in_jail?
# You need to specify IP address for the host in Jail.
# http://rubyforge.org/pipermail/mongrel-unicorn/2009-December/000212.html
listen "#{getIP}:3010"
else
listen 3010
end
worker_processes 5
.... (write other configuration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment