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 -%>