aboutsummaryrefslogtreecommitdiffhomepage
path: root/service
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-11-25 17:41:16 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-11-25 17:41:23 -0800
commitaf4c68feac8e01631cc156ee3b48b85b75e59085 (patch)
tree23ec7b088a8464f9429eea0986f4d64d28cabf80 /service
parent7838870a0ca57d48ed230e9dd58c79b0cfd9f809 (diff)
Add support for Systemd Socket Activation
Diffstat (limited to 'service')
-rw-r--r--service/httpd/httpd.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/service/httpd/httpd.go b/service/httpd/httpd.go
index dbe2c1a..612418d 100644
--- a/service/httpd/httpd.go
+++ b/service/httpd/httpd.go
@@ -9,6 +9,7 @@ import (
"net"
"net/http"
"os"
+ "strconv"
"strings"
"time"
@@ -40,6 +41,8 @@ func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHa
}
switch {
+ case os.Getenv("LISTEN_PID") == strconv.Itoa(os.Getpid()):
+ startSystemdSocketServer(server)
case strings.HasPrefix(listenAddr, "/"):
startUnixSocketServer(server, listenAddr)
case certDomain != "" && certCache != "":
@@ -57,6 +60,21 @@ func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHa
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) {
os.Remove(socketFile)