Skip to content

Commit

Permalink
0.1.0: Rename site's :install action to :create, implement :delete
Browse files Browse the repository at this point in the history
* Make `certs_dir` an attribute
* Add support for a `custom` hash on site, for use in passing extra data to
  custom templates
  • Loading branch information
Eric Richardson committed Jan 15, 2014
1 parent 340a9f7 commit 66be8b7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
default.nginx_passenger.log_dir = "/var/log/nginx"
default.nginx_passenger.cert_dir = "/etc/nginx/certs"
default.nginx_passenger.ruby = "/usr/bin/ruby"
default.nginx_passenger.max_pool_size = 8

Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
license "BSD"
description "Installs/Configures nginx and Passenger"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.5"
version "0.1.0"

depends "apt"
34 changes: 30 additions & 4 deletions providers/site.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
action :install do
action :create do
# -- Are we installing an SSL site? -- #

cert_exists = false
Expand All @@ -9,14 +9,14 @@

if cert
# TODO: Need to make sure cert has cert and key
# TODO: Should certs dir be an attribute?

directory "/etc/nginx/certs" do
directory node.nginx_passenger.certs_dir do
action :create
recursive true
end

cert.keys.each do |k|
file "/etc/nginx/certs/#{new_resource.name}.#{k}" do
file "#{node.nginx_passenger.certs_dir}/#{new_resource.name}.#{k}" do
backup 1
mode 0644
content cert[k]
Expand Down Expand Up @@ -46,4 +46,30 @@

notifies :reload, "service[nginx]"
end
end

#----------

action :delete do
# -- Define nginx service (just in case) -- #

service "nginx" do
provider Chef::Provider::Service::Upstart
action :nothing
supports :start => true, :restart => true, :reload => true
end

# -- Delete nginx site file -- #

file "/etc/nginx/sites-enabled/#{new_resource.name}" do
action :delete
notifies :reload, "service[nginx]", :immediately
end

# -- Delete any certs -- #

execute "remove-#{new_resource.name}-certs" do
command "rm -f #{node.nginx_passenger.certs_dir}/#{new_resource.name}*"
action :run
end
end
3 changes: 2 additions & 1 deletion resources/site.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
actions :delete
default_action :install
default_action :create
attribute :name, :kind_of => String
attribute :server, :kind_of => String
attribute :rails_env, :kind_of => String
Expand All @@ -11,3 +11,4 @@
attribute :min_instances, :kind_of => Integer
attribute :max_body_size, :kind_of => String
attribute :env, :kind_of => String
attribute :custom, :kind_of => Hash
4 changes: 2 additions & 2 deletions templates/default/site.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ server {
listen 443 ssl;
server_name <%= @resource.server %>;

ssl_certificate /etc/nginx/certs/<%= @resource.name %>.cert;
ssl_certificate_key /etc/nginx/certs/<%= @resource.name %>.key;
ssl_certificate <%= node.nginx_passenger.certs_dir %>/<%= @resource.name %>.cert;
ssl_certificate_key <%= node.nginx_passenger.certs_dir %>/<%= @resource.name %>.key;

access_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.ssl.access.log;
error_log <%= node.nginx_passenger.log_dir %>/<%= @resource.name %>.ssl.error.log;
Expand Down

0 comments on commit 66be8b7

Please sign in to comment.