From 5d77188c05c875047e899cbbccd010d911955469 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sat, 26 Mar 2022 16:44:46 +0500 Subject: [PATCH] Add menu with shutdown button --- httpserver.go | 13 +++++++++++++ index.htm | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/httpserver.go b/httpserver.go index a773838..2aef4ec 100644 --- a/httpserver.go +++ b/httpserver.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "net/http" + "os" "time" log "github.com/sirupsen/logrus" @@ -11,6 +12,7 @@ import ( func httpServer(listenAddress string) { http.HandleFunc("/", handler) + http.HandleFunc("/shutdown", handleShutdown) http.HandleFunc("/start", handleForceStart) log.WithField("job", "http_server").Fatal(http.ListenAndServe(listenAddress, nil)) } @@ -56,3 +58,14 @@ func handleForceStart(w http.ResponseWriter, r *http.Request) { http.Error(w, fmt.Sprintf("there is no job with name %s", jobName), http.StatusBadRequest) } + +func handleShutdown(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("Application terminated.\n")) + + go func() { + time.Sleep(time.Second) + log.WithField("job", "http_server").Infoln("Shutdown requested") + os.Exit(0) + }() +} diff --git a/index.htm b/index.htm index 7dd44a8..6df378b 100644 --- a/index.htm +++ b/index.htm @@ -65,7 +65,7 @@ } th { - background-color: var(--base02); + background-color: var(--base01); } td, @@ -74,7 +74,7 @@ padding: 0.25em; } - button { + table button { width: 100%; color: #fff; background-color: var(--base01); @@ -99,11 +99,50 @@ .runningbg { background-color: var(--base0B); } + + .dropbtn { + background-color: var(--base01); + color: var(--base05); + padding: 0.5em; + cursor: pointer; + border: 0; + } + + .dropdown { + position: relative; + display: inline-block; + float: right; + } + + .dropdown-content { + display: none; + position: absolute; + right: 0; + background-color: var(--base01); + z-index: 1; + } + + .dropdown-content a { + color: var(--base05); + padding: 0.5em; + text-decoration: none; + display: block; + } + + .dropdown:hover .dropdown-content { + display: block; + }
+

Job list