sous-chefs / grafana

Development repository for the grafana cookbook
https://supermarket.chef.io/cookbooks/grafana
Other
77 stars 145 forks source link

nginx setup fails on ubuntu 14.04 #33

Closed runningman84 closed 9 years ago

runningman84 commented 9 years ago

There seems to be a problem with ubuntu 1404 and your cookbook.

I have tried some workarround for the pid problem but I still get the adress already in use error.

This is my wrapper cookbook:

# attributes
if platform == 'ubuntu' && platform_version == '14.04'
 override[:nginx][:pid] = '/run/nginx.pid'
end
# recipe
include_recipe "java"
include_recipe "elasticsearch"
include_recipe "grafana"
ubuntu@ip-10-90-yy-xx:/var/log/nginx$ tail error.log 
2015/01/12 16:59:36 [emerg] 31813#0: bind() to 10.90.13.107:80 failed (98: Address already in use)
2015/01/12 16:59:36 [emerg] 31813#0: bind() to 10.90.13.107:80 failed (98: Address already in use)
2015/01/12 16:59:36 [emerg] 31813#0: bind() to 10.90.13.107:80 failed (98: Address already in use)
2015/01/12 16:59:36 [emerg] 31813#0: bind() to 10.90.13.107:80 failed (98: Address already in use)
2015/01/12 16:59:36 [emerg] 31813#0: bind() to 10.90.13.107:80 failed (98: Address already in use)
2015/01/12 16:59:36 [emerg] 31813#0: still could not bind()
ubuntu@ip-10-90-13-107:/var/log/nginx$ tail i-59da03bf.access.log 
ubuntu@ip-10-90-13-107:/var/log/nginx$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
JonathanTron commented 9 years ago

Hi, from what I see in the log, you probably have another process running on the same port (80) as nginx... you can set the webserver port by setting the node['grafana']['webserver_port'] attribute to something else than 80, let's say 8080 for example.

runningman84 commented 9 years ago

No this is only nginx nothing else is running. You can see it in the curl output too.

JonathanTron commented 9 years ago

I will setup test-kitchen to test under 14.04 and see if I can reproduce it. Thanks for reporting the problem. :+1:

runningman84 commented 9 years ago

Hi Jonathan does it work for you?

JonathanTron commented 9 years ago

I'm sorry I added ubuntu 14.04 in test-kitchen but then ran into outdated cookbooks... and then I didn't had more time to debug it. I will try to come up with a solution as soon as possible.

JonathanTron commented 9 years ago

I confirm I can reproduce the issue on Ubuntu 14.04... though I'm not sure it's due to this cookbook directly, it seems like the nginx cookbook does not work well under 14.04 (their README display compatibility with 12.04 but not 14.04).

I think your best bet for now is to handle the nginx install yourself and not use this cookbook's nginx integration directly.

runningman84 commented 9 years ago

Could you please try this workaround in your cookbook?

if platform == 'ubuntu' && platform_version == '14.04'
 override[:nginx][:pid] = '/run/nginx.pid'
end

I use this workarround in my other cookbooks, unfortunatly I doesn't seem to work grafana-wrapper cookbook.

JonathanTron commented 9 years ago

Hi, I don't know if it's a typo or the real code but it looks to me you're missing something:

override[:nginx][:pid] = '/run/nginx.pid'

should be

node.override[:nginx][:pid] = '/run/nginx.pid'

unless you're setting it in the and attributes file.

JonathanTron commented 9 years ago

Sorry I've read your first message wrong, you're indeed using the code in attributes file...

JonathanTron commented 9 years ago

I can confirm it don't work, even with the pid path override.

JonathanTron commented 9 years ago

From what I've read, it seems it would work if you install nginx via the source recipe, otherwise the packages install a config and already start nginx, but then the config is changed by Chef and the pid location prevent the init script from restarting nginx properly. This is definitely a fix which needs to come from the nginx cookbook.

I think your best chance to get it working on 14.04 is to ensure nginx is installed correctly.

Thanks again for reporting this issue.

runningman84 commented 9 years ago

there is a new nginx cookbook release (2.7.6) which works on a vanilla Ubuntu 14.04. Funny enough it doesn't work with your cookook. Can you take another look? Thanks in advance...

lanyonm commented 9 years ago

It's kinda messy, but I've created serverspec tests for this bug: https://github.com/lanyonm/chef-grafana/commit/0332a5d41bd605d68a37fbd2a28e3c90caf2f013. The reason I structured the test this way is that I'm testing both locally with Vagrant and in EC2 - where curling localhost doesn't work. The extra test harnesses allows serverspec to use ohai to curl the node's ip.

I haven't found the root cause of the issue, but I have found that nginx on Ubuntu 14.04 seems to have trouble reloading configs when node['grafana']['listen_address'] is set. I have successfully provisioned ubuntu-14.04 nodes where node['grafana']['listen_address'] = nil - BUT I also had to modify grafana-nginx.conf.erb so that it respects a nil or empty value.

I have also found that specifying :restart instead of :reload within the grafana template in the _nginx recipe works for ubuntu-14.04.

I'd like to submit my branch as a PR so we can correctly set node['grafana']['listen_address'] to nil, but I invite advice as to whether we should make the default action for a template change a restart.

JonathanTron commented 9 years ago

Now that #39 has been merged can one of you confirm it does work on Ubuntu 14.04?

lanyonm commented 9 years ago

I have been able to confirm that with no changes, the new test correct catches the issue with Ubuntu 14.04.

When adding webserver_listen: '' to grafana's config in the ubuntu-14.04 platform attributes, the new test passes.

LGTM :+1:

JonathanTron commented 9 years ago

Yay! Thanks again for finding and providing the fix @lanyonm.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.