fork of whitequark.org/git-pages with mods for tangled

Reload configuration on SIGHUP (if supported by OS).

On Windows, there is no way to reload configuration at runtime.

+20
src/main.go
··· 303 303 } 304 304 305 305 default: 306 + // Hook a signal (SIGHUP on *nix, nothing on Windows) for reloading the configuration 307 + // at runtime. This is useful because it preserves S3 backend cache contents. Failed 308 + // configuration reloads will not crash the process; you may want to check the syntax 309 + // first with `git-pages -config ... -print-config` since there is no other feedback. 310 + OnReload(func() { 311 + if newConfig, err := Configure(*configTomlPath); err != nil { 312 + log.Println("config:", err) 313 + log.Println("config: reload failed") 314 + } else { 315 + log.Println("config: reloaded") 316 + // From https://go.dev/ref/mem: 317 + // > A read r of a memory location x holding a value that is not larger than 318 + // > a machine word must observe some write w such that r does not happen before 319 + // > w and there is no write w' such that w happens before w' and w' happens 320 + // > before r. That is, each read must observe a value written by a preceding or 321 + // > concurrent write. 322 + config = newConfig 323 + } 324 + }) 325 + 306 326 // Start listening on all ports before initializing the backend, otherwise if the backend 307 327 // spends some time initializing (which the S3 backend does) a proxy like Caddy can race 308 328 // with git-pages on startup and return errors for requests that would have been served
+7
src/signal_other.go
··· 1 + //go:build !unix 2 + 3 + package git_pages 4 + 5 + func OnReload(handler func()) { 6 + // not implemented 7 + }
+20
src/signal_posix.go
··· 1 + //go:build unix 2 + 3 + package git_pages 4 + 5 + import ( 6 + "os" 7 + "os/signal" 8 + "syscall" 9 + ) 10 + 11 + func OnReload(handler func()) { 12 + sighup := make(chan os.Signal, 1) 13 + signal.Notify(sighup, syscall.SIGHUP) 14 + go func() { 15 + for { 16 + <-sighup 17 + handler() 18 + } 19 + }() 20 + }