From 9811490aada70ef3e6e4c051ff695b6e31f59617 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 7 May 2019 15:11:26 +0200 Subject: [PATCH 1/5] Add self-contained maintenance web page This can be used for any of our services when doing planned maintenance or migrations. --- .../files/default/maintenance.html | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 site-cookbooks/kosmos-base/files/default/maintenance.html diff --git a/site-cookbooks/kosmos-base/files/default/maintenance.html b/site-cookbooks/kosmos-base/files/default/maintenance.html new file mode 100644 index 0000000..1ef576c --- /dev/null +++ b/site-cookbooks/kosmos-base/files/default/maintenance.html @@ -0,0 +1,40 @@ + + + + Down for maintenance + + + + +
+ +

Back soon

+

+ This website is currently down for maintenance. +

+ +
+ + From 36a50489d084da5628c3fd0fc642d10d990b7365 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 7 May 2019 15:41:27 +0200 Subject: [PATCH 2/5] Add maintenance page to nginx default recipe --- .../files/default/maintenance.html | 0 site-cookbooks/kosmos-nginx/recipes/default.rb | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) rename site-cookbooks/{kosmos-base => kosmos-nginx}/files/default/maintenance.html (100%) diff --git a/site-cookbooks/kosmos-base/files/default/maintenance.html b/site-cookbooks/kosmos-nginx/files/default/maintenance.html similarity index 100% rename from site-cookbooks/kosmos-base/files/default/maintenance.html rename to site-cookbooks/kosmos-nginx/files/default/maintenance.html diff --git a/site-cookbooks/kosmos-nginx/recipes/default.rb b/site-cookbooks/kosmos-nginx/recipes/default.rb index 12fb1c6..bee6c27 100644 --- a/site-cookbooks/kosmos-nginx/recipes/default.rb +++ b/site-cookbooks/kosmos-nginx/recipes/default.rb @@ -60,6 +60,22 @@ cookbook_file "#{node['nginx']['dir']}/conf.d/tls_config.conf" do notifies :restart, 'service[nginx]' end +directory node["nginx"]["user_home"] do + owner node["nginx"]["user"] + group node["nginx"]["group"] + action :create + recursive true +end + +# Maintenance page, to be copied or served when putting things in maintenance +# mode +cookbook_file "#{node["nginx"]["user_home"]}/maintenance.html" do + source "maintenance.html" + owner node['nginx']['user'] + group node['nginx']['group'] + mode "0640" +end + unless node.chef_environment == "development" include_recipe 'kosmos-base::firewall' From 1ee2b5ad41a5a27892435e81317dd3b035572902 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 7 May 2019 15:49:01 +0200 Subject: [PATCH 3/5] Add maintenance page feature to Mastodon nginx site --- .../templates/default/nginx_conf_mastodon.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 297c858..6068844 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -35,6 +35,11 @@ server { add_header Strict-Transport-Security "max-age=31536000"; location / { + # If the maintenance file is present, show maintenance page + if (-f <%= @mastodon_path %>/public/maintenance.html) { + return 503; + } + try_files $uri @proxy; } From 99a677ec4785a04a262a26adef22db103d32f1a9 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 7 May 2019 15:52:58 +0200 Subject: [PATCH 4/5] Configure maintenance error page for 503 --- .../templates/default/nginx_conf_mastodon.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 6068844..80bb668 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -36,7 +36,7 @@ server { location / { # If the maintenance file is present, show maintenance page - if (-f <%= @mastodon_path %>/public/maintenance.html) { + if (-f /maintenance.html) { return 503; } @@ -88,5 +88,6 @@ server { tcp_nodelay on; } - error_page 500 501 502 503 504 /500.html; + error_page 500 501 502 504 /500.html; + error_page 503 /maintenance.html; } From 89027f1f32db88bff7cde388b595da9acc76b2c3 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 7 May 2019 16:10:23 +0200 Subject: [PATCH 5/5] Fix maintenance page paths --- .../templates/default/nginx_conf_mastodon.erb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb index 80bb668..895a81b 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -36,7 +36,7 @@ server { location / { # If the maintenance file is present, show maintenance page - if (-f /maintenance.html) { + if (-f <%= @mastodon_path %>/public/maintenance.html) { return 503; } @@ -90,4 +90,9 @@ server { error_page 500 501 502 504 /500.html; error_page 503 /maintenance.html; + + location = /maintenance.html { + root <%= @mastodon_path %>/public; + } + }