diff options
Diffstat (limited to 'html/fruitvote')
-rw-r--r-- | html/fruitvote/main.go | 20 | ||||
-rwxr-xr-x | html/fruitvote/start.sh | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/html/fruitvote/main.go b/html/fruitvote/main.go index 73c1c17..b41c88f 100644 --- a/html/fruitvote/main.go +++ b/html/fruitvote/main.go @@ -3,11 +3,14 @@ package main import ( "flag" "fmt" + "log" "net" "net/http" "os" "os/exec" + "os/signal" "strings" + "syscall" ) func indexHandler(w http.ResponseWriter, r *http.Request) { @@ -15,6 +18,11 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello, this is a Unix socket HTTP server in Go!")) } +func healthCheckHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("healthy")) +} + func main() { socketPath, users := getArgs() os.Remove(socketPath) @@ -24,6 +32,17 @@ func main() { panic(err) } os.Chmod(socketPath, 0700) + + sigc := make(chan os.Signal, 1) + signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM) + go func(c chan os.Signal) { + // Wait for a SIGINT or SIGKILL: + sig := <-c + log.Printf("Caught signal %s: shutting down.", sig) + + listener.Close() + os.Exit(0) + }(sigc) defer listener.Close() for _, user := range strings.Split(users, ",") { @@ -32,6 +51,7 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/", indexHandler) + mux.HandleFunc("/health", healthCheckHandler) http.Serve(listener, mux) } diff --git a/html/fruitvote/start.sh b/html/fruitvote/start.sh index 3c274a8..dd3036b 100755 --- a/html/fruitvote/start.sh +++ b/html/fruitvote/start.sh @@ -3,5 +3,5 @@ nice -n 19 /home/simponic/fruitvote/fruitvote \ --users simponic,nginx \ --socket-path /home/simponic/fruitvote/http.sock \ - --database /home/simponic/fruitvote/db.sqlite \ - & + & +# --database /home/simponic/fruitvote/db.sqlite \ |