aboutsummaryrefslogtreecommitdiffhomepage
path: root/service
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-11-11 16:21:57 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-11-11 16:21:57 -0800
commit1315282c7ff46f1ac048022f7eeb0b4d09eedb57 (patch)
tree01a2121a840b0970a07d3c726437dfb29ee0c1f9 /service
parentbecd086865f35d64a80d01ffb1ca96d0493dfa03 (diff)
Add the possiblity to listen on Unix socket
Diffstat (limited to 'service')
-rw-r--r--service/httpd/httpd.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/service/httpd/httpd.go b/service/httpd/httpd.go
index 4ab7cfd..a365353 100644
--- a/service/httpd/httpd.go
+++ b/service/httpd/httpd.go
@@ -6,7 +6,10 @@ package httpd // import "miniflux.app/service/httpd"
import (
"crypto/tls"
+ "net"
"net/http"
+ "os"
+ "strings"
"time"
"miniflux.app/api"
@@ -29,27 +32,49 @@ func Serve(cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHa
keyFile := cfg.KeyFile()
certDomain := cfg.CertDomain()
certCache := cfg.CertCache()
+ listenAddr := cfg.ListenAddr()
server := &http.Server{
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 60 * time.Second,
- Addr: cfg.ListenAddr(),
Handler: setupHandler(cfg, store, feedHandler, pool),
}
- if certDomain != "" && certCache != "" {
+ switch {
+ case strings.HasPrefix(listenAddr, "/"):
+ startUnixSocketServer(server, listenAddr)
+ case certDomain != "" && certCache != "":
cfg.IsHTTPS = true
startAutoCertTLSServer(server, certDomain, certCache)
- } else if certFile != "" && keyFile != "" {
+ case certFile != "" && keyFile != "":
cfg.IsHTTPS = true
+ server.Addr = listenAddr
startTLSServer(server, certFile, keyFile)
- } else {
+ default:
+ server.Addr = listenAddr
startHTTPServer(server)
}
return server
}
+func startUnixSocketServer(server *http.Server, socketFile string) {
+ os.Remove(socketFile)
+
+ go func(sock string) {
+ listener, err := net.Listen("unix", sock)
+ if err != nil {
+ logger.Fatal(`Server failed to start: %v`, err)
+ }
+ defer listener.Close()
+
+ logger.Info(`Listening on Unix socket %q`, sock)
+ if err := server.Serve(listener); err != http.ErrServerClosed {
+ logger.Fatal(`Server failed to start: %v`, err)
+ }
+ }(socketFile)
+}
+
func startAutoCertTLSServer(server *http.Server, certDomain, certCache string) {
server.Addr = ":https"
certManager := autocert.Manager{