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..895a81b 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; } @@ -83,5 +88,11 @@ 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; + + location = /maintenance.html { + root <%= @mastodon_path %>/public; + } + } diff --git a/site-cookbooks/kosmos-nginx/files/default/maintenance.html b/site-cookbooks/kosmos-nginx/files/default/maintenance.html new file mode 100644 index 0000000..1ef576c --- /dev/null +++ b/site-cookbooks/kosmos-nginx/files/default/maintenance.html @@ -0,0 +1,40 @@ + + + + Down for maintenance + + + + +
+ +

Back soon

+

+ This website is currently down for maintenance. +

+ +
+ + 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'