Workaround to avoid "adding listener failed addr=0.0.0.0:8080 (in use)" error by unicorn on FreeBSD jail host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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