#
# Cookbook Name:: oc-graphite
# Recipe:: _nginx
#
# Copyright (C) 2014, Chef Software, Inc <legal@getchef.com>

package 'nginx'

node.default['oc-graphite']['uwsgi']['listen_ip'] = '127.0.0.1'
node.default['oc-graphite']['uwsgi']['listen_port'] = '8081'
include_recipe 'oc-graphite::_uwsgi'

service 'nginx' do
  action [:enable, :start]
  supports :restart => true, :start => true, :stop => true, :reload => true
end

template '/etc/nginx/sites-available/graphite' do
  source 'nginx-graphite.erb'
  owner 'root'
  group 'root'
  mode 0644

  notifies :reload, 'service[nginx]', :delayed
end

link '/etc/nginx/sites-enabled/graphite' do
  to '/etc/nginx/sites-available/graphite'
end

file '/etc/nginx/sites-enabled/default' do
  action :delete

  notifies :reload, 'service[nginx]', :delayed
  only_if { node['oc-graphite']['nginx']['disable_default_vhost'] }
end

#
# Cookbook Name:: oc-graphite
# Recipe:: _nginx
#
# Copyright (C) 2014, Chef Software, Inc <legal@getchef.com>

package 'nginx'

node.default['oc-graphite']['uwsgi']['listen_ip'] = '127.0.0.1'
node.default['oc-graphite']['uwsgi']['listen_port'] = '8081'
include_recipe 'oc-graphite::_uwsgi'

template '/etc/nginx/sites-available/graphite' do
  source 'nginx-graphite.erb'
  owner 'root'
  group 'root'
  mode 0644

  notifies :reload, 'service[nginx]', :delayed
end

link '/etc/nginx/sites-enabled/graphite' do
  to '/etc/nginx/sites-available/graphite'
end

file '/etc/nginx/sites-enabled/default' do
  action :delete

  notifies :reload, 'service[nginx]', :delayed
  only_if { node['oc-graphite']['nginx']['disable_default_vhost'] }
end

service 'nginx' do
  action [:enable, :start]
  supports :restart => true, :reload => true
end

Move nginx service to end of recipe
Move nginx service to end of recipe

Service resources generally should be at the end of recipes when they
have configuration files that can modify their behavior. If a
configuration file is broken, and the service fails to restart, it
will always fail to start before Chef has a chance to configure the
file/template that could fix whatever configuration was broken.
