From c18ba1d499f46c96db548969281874de68dea7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20L=C3=A9on?= Date: Tue, 17 Mar 2015 17:06:54 +0100 Subject: [PATCH] feat: add an easy maintenance page support --- manifests/resource/vhost.pp | 1 + templates/vhost/vhost_header.erb | 8 ++++++++ templates/vhost/vhost_ssl_header.erb | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 9c655a91a..ab2cd217e 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -231,6 +231,7 @@ $owner = $::nginx::config::global_owner, $group = $::nginx::config::global_group, $mode = $::nginx::config::global_mode, + $maintenance = false, ) { validate_re($ensure, '^(present|absent)$', diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index e65ee89d9..3f577c5f9 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -102,6 +102,14 @@ server { add_header <%= key %> <%= @add_header[key] %>; <%- end -%> <% end -%> +<% if @maintenance -%> + set $maintenance "on"; +<% else -%> + set $maintenance "off"; +<% end -%> + if ($maintenance = "on") { + return 503; + } <% if @rewrite_to_https -%> if ($ssl_protocol = "") { return 301 https://$host<% if @ssl_port.to_i != 443 %>:<%= @ssl_port %><% end %>$request_uri; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index 2a4aab1c1..09c8aa16e 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -72,6 +72,14 @@ server { <%- end -%> <% end -%> +<% if @maintenance -%> + set $maintenance "on"; +<% else -%> + set $maintenance "off"; +<% end -%> + if ($maintenance = "on") { + return 503; + } <% if Array(@resolver).count > 0 -%> resolver <% Array(@resolver).each do |r| %> <%= r %><% end %>; <% end -%>