Mercurial Hosting > luan
changeset 2160:034b5f1b025c nginx_sites_addon
do_set_https returns needs_reload_nginx
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Wed, 28 Jan 2026 18:30:32 -0700 |
| parents | 967012bebfe0 |
| children | eb5bdf29a664 |
| files | src/luan/host/Https.luan |
| diffstat | 1 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
diff -r 967012bebfe0 -r 034b5f1b025c src/luan/host/Https.luan --- a/src/luan/host/Https.luan Wed Jan 28 17:42:16 2026 -0700 +++ b/src/luan/host/Https.luan Wed Jan 28 18:30:32 2026 -0700 @@ -104,7 +104,8 @@ <% end -local function reload_nginx(luanhost_dir_str) +local function reload_nginx(luanhost_dir) + local luanhost_dir_str = luanhost_dir.canonical().to_string() local cmd = `%> sudo $(which nginx) -t -c "<%=luanhost_dir_str%>/local/nginx.conf" && \ sudo $(which nginx) -s reload -c "<%=luanhost_dir_str%>/local/nginx.conf"; @@ -112,6 +113,7 @@ local s = uri("bash:"..cmd).read_text() logger.info("reload_nginx "..s) end +Https.reload_nginx = reload_nginx local function issue_cert(files, luanhost_dir, dry_run) local luanhost_dir_str = luanhost_dir.canonical().to_string() @@ -155,8 +157,6 @@ local s = uri("bash:"..cmd).read_text() logger.info("move temp output to fullchain.cer\n"..s) end - - reload_nginx(luanhost_dir_str) end @@ -164,6 +164,7 @@ files.csr_file.exists() or error "no CSR file, assuming local https cert" if time_now() - files.local_cer_file.last_modified() > renewal_period then issue_cert(files, luanhost_dir, dry_run) + reload_nginx(luanhost_dir) return end end @@ -182,6 +183,7 @@ end local function do_set_https(is_https,domain,site_dir,luanhost_dir,nginx_default_conf,dry_run) + local needs_reload_nginx = false local files = get_files(domain,site_dir) -- luan/host @@ -238,7 +240,6 @@ issue_cert(files, luanhost_dir, dry_run) - catch e logger.error("Error setting up ACME: "..e) end_try @@ -255,7 +256,7 @@ logger.info("writing nginx conf to "..files.nginx_file.canonical().to_string()) local nginx = ` nginx_ssl_conf(domain,files,nginx_default_conf) ` files.nginx_file.write(nginx) - reload_nginx(luanhost_dir_str) + needs_reload_nginx = true end else if not is_local then @@ -273,10 +274,10 @@ for _, file in pairs(files) do file.delete() end - reload_nginx(luanhost_dir_str) + needs_reload_nginx = true end end - --logger.info "done" + return needs_reload_nginx end Https.do_set_https = do_set_https -- for testing @@ -295,7 +296,10 @@ local dry_run = false if not try_synchronized( function() - do_set_https(is_https,domain,site_dir,luanhost_dir,nginx_default_conf,dry_run) + local needs_reload_nginx = do_set_https(is_https,domain,site_dir,luanhost_dir,nginx_default_conf,dry_run) + if needs_reload_nginx then + reload_nginx(luanhost_dir) + end end, domain..".lock", 0 )() then logger.info("set_https already running for "..domain..", skipping") end
