From 8a870f6fd69f344391e2167e96f41f9aa27e0be7 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Wed, 13 Jan 2021 09:49:03 +0100 Subject: [PATCH] Don't fail on first run, when Tor hostname missing --- site-cookbooks/kosmos-mastodon/recipes/nginx.rb | 4 +++- .../kosmos-mastodon/templates/default/nginx_conf_mastodon.erb | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb index fde87cd..65717a1 100644 --- a/site-cookbooks/kosmos-mastodon/recipes/nginx.rb +++ b/site-cookbooks/kosmos-mastodon/recipes/nginx.rb @@ -24,6 +24,8 @@ template "#{node['nginx']['dir']}/snippets/mastodon.conf" do notifies :reload, 'service[nginx]', :delayed end +onion_address = File.read("/var/lib/tor/mastodon/hostname").strip rescue nil + template "#{node['nginx']['dir']}/sites-available/#{server_name}" do source 'nginx_conf_mastodon.erb' owner 'www-data' @@ -32,7 +34,7 @@ template "#{node['nginx']['dir']}/sites-available/#{server_name}" do ssl_cert: "/etc/letsencrypt/live/#{server_name}/fullchain.pem", ssl_key: "/etc/letsencrypt/live/#{server_name}/privkey.pem", shared_config_path: "#{node['nginx']['dir']}/snippets/mastodon.conf", - onion_address: File.read("/var/lib/tor/mastodon/hostname").strip + onion_address: onion_address notifies :reload, 'service[nginx]', :delayed end 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 c07686e..20d2efa 100644 --- a/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb +++ b/site-cookbooks/kosmos-mastodon/templates/default/nginx_conf_mastodon.erb @@ -1,8 +1,10 @@ +<% if @onion_address %> server { listen 80; server_name mastodon.<%= @onion_address %>; include <%= @shared_config_path %>; } +<% end %> map $http_upgrade $connection_upgrade { default upgrade;