From cb667e2472867666fe1d87059e00078797e182f6 Mon Sep 17 00:00:00 2001 From: Elena Balakhonova Date: Tue, 3 Dec 2019 16:12:12 +0300 Subject: [PATCH] Refresh -passwd file while working --- README | 7 +++++++ gocheese.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/README b/README index 555b19b..d128489 100644 --- a/README +++ b/README @@ -63,6 +63,13 @@ hashed passwords: foo:$sha256$fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9 foo:$argon2i$v=19$m=32768,t=3,p=4$OGU5MTM3YjVlYzQwZjhkZA$rVn53v6Ckpf7WH0676ZQLr9Hbm6VH3YnL6I9ONJcIIU +While daemon working you can refresh -passwd file with SIGHUP: + + $ kill -HUP `pidof gocheese` + +Before refreshing it's recommended to check -passwd file with -passwd-check +option to prevent daemon failure + On-disk storage format ====================== diff --git a/gocheese.go b/gocheese.go index 6ca3ad5..fa3b430 100644 --- a/gocheese.go +++ b/gocheese.go @@ -31,10 +31,12 @@ import ( "net/http" "net/url" "os" + "os/signal" "path/filepath" "regexp" "runtime" "strings" + "syscall" ) const ( @@ -462,6 +464,13 @@ func main() { } refreshPasswd() log.Println("root:", *root, "bind:", *bind) + needsRefreshPasswd := make(chan os.Signal, 0) + signal.Notify(needsRefreshPasswd, syscall.SIGHUP) + go func() { + for range needsRefreshPasswd { + refreshPasswd() + } + }() http.HandleFunc(*norefreshURLPath, handler) http.HandleFunc(*refreshURLPath, handler) log.Fatal(http.ListenAndServe(*bind, nil)) -- 2.44.0