Add support for Systemd Socket Activation
This commit is contained in:
parent
7838870a0c
commit
af4c68feac
1 changed files with 18 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,6 +41,8 @@ func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHa
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case os.Getenv("LISTEN_PID") == strconv.Itoa(os.Getpid()):
|
||||||
|
startSystemdSocketServer(server)
|
||||||
case strings.HasPrefix(listenAddr, "/"):
|
case strings.HasPrefix(listenAddr, "/"):
|
||||||
startUnixSocketServer(server, listenAddr)
|
startUnixSocketServer(server, listenAddr)
|
||||||
case certDomain != "" && certCache != "":
|
case certDomain != "" && certCache != "":
|
||||||
|
@ -57,6 +60,21 @@ func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHa
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startSystemdSocketServer(server *http.Server) {
|
||||||
|
go func() {
|
||||||
|
f := os.NewFile(3, "systemd socket")
|
||||||
|
listener, err := net.FileListener(f)
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal(`Unable to create listener from systemd socket: %v`, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info(`Listening on systemd socket`)
|
||||||
|
if err := server.Serve(listener); err != http.ErrServerClosed {
|
||||||
|
logger.Fatal(`Server failed to start: %v`, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func startUnixSocketServer(server *http.Server, socketFile string) {
|
func startUnixSocketServer(server *http.Server, socketFile string) {
|
||||||
os.Remove(socketFile)
|
os.Remove(socketFile)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue