+ /control/update handler

This commit is contained in:
Simon Zolin
2019-04-25 14:57:03 +03:00
parent 788e91a51e
commit 2dd6ea5161
4 changed files with 397 additions and 46 deletions

18
app.go
View File

@@ -2,6 +2,7 @@ package main
import (
"bufio"
"context"
"crypto/tls"
"fmt"
"io"
@@ -30,6 +31,7 @@ var httpsServer struct {
server *http.Server
cond *sync.Cond // reacts to config.TLS.Enabled, PortHTTPS, CertificateChain and PrivateKey
sync.Mutex // protects config.TLS
shutdown bool // if TRUE, don't restart the server
}
var pidFileName string // PID file name. Empty if no PID file was created.
@@ -171,7 +173,7 @@ func run(args options) {
go httpServerLoop()
// this loop is used as an ability to change listening host and/or port
for {
for !httpsServer.shutdown {
printHTTPAddresses("http")
// we need to have new instance, because after Shutdown() the Server is not usable
@@ -186,10 +188,13 @@ func run(args options) {
}
// We use ErrServerClosed as a sign that we need to rebind on new address, so go back to the start of the loop
}
// wait indefinitely for other go-routines to complete their job
select {}
}
func httpServerLoop() {
for {
for !httpsServer.shutdown {
httpsServer.cond.L.Lock()
// this mechanism doesn't let us through until all conditions are met
for config.TLS.Enabled == false ||
@@ -367,6 +372,15 @@ func cleanup() {
}
}
// Stop HTTP server, possibly waiting for all active connections to be closed
func stopHTTPServer() {
httpsServer.shutdown = true
if httpsServer.server != nil {
httpsServer.server.Shutdown(context.TODO())
}
httpServer.Shutdown(context.TODO())
}
// This function is called before application exits
func cleanupAlways() {
if len(pidFileName) != 0 {