aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/web.go
diff options
context:
space:
mode:
authorOdin Ugedal <odin@ugedal.com>2016-08-11 23:46:33 +0200
committer无闻 <u@gogs.io>2016-08-11 14:46:33 -0700
commit1dd003bd4c88f6125ec49286c9feab1f7d9b5a82 (patch)
tree1ee0c7f67c82fc92f1a4494e0582c0f568b3f42d /cmd/web.go
parent70fbcd2f27a027477dd18aef0d0f216bf0fb8230 (diff)
downloadgitea-1dd003bd4c88f6125ec49286c9feab1f7d9b5a82.tar.gz
gitea-1dd003bd4c88f6125ec49286c9feab1f7d9b5a82.zip
Add initial support for unix sockets (#2852)
Diffstat (limited to 'cmd/web.go')
-rw-r--r--cmd/web.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/cmd/web.go b/cmd/web.go
index f7ab661d41..9358dc1401 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -8,6 +8,7 @@ import (
"crypto/tls"
"fmt"
"io/ioutil"
+ "net"
"net/http"
"net/http/fcgi"
"os"
@@ -582,6 +583,9 @@ func runWeb(ctx *cli.Context) error {
var err error
listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
+ if setting.Protocol == setting.UNIX_SOCKET {
+ listenAddr = fmt.Sprintf("%s", setting.HttpAddr)
+ }
log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl)
switch setting.Protocol {
case setting.HTTP:
@@ -591,6 +595,20 @@ func runWeb(ctx *cli.Context) error {
err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
case setting.FCGI:
err = fcgi.Serve(nil, m)
+ case setting.UNIX_SOCKET:
+ os.Remove(listenAddr)
+ listener, err := net.ListenUnix("unix", &net.UnixAddr{listenAddr, "unix"})
+ if err != nil {
+ break
+ }
+ // FIXME add proper implementation of signal capture on all protocols
+ // execute this on SIGTERM or SIGINT: listener.Close()
+ err = os.Chmod(listenAddr, os.FileMode(setting.UnixSocketPermission))
+ if err != nil {
+ log.Fatal(4, "Failed to set permission of unix socket: %v", err)
+ }
+ err = http.Serve(listener, m)
+
default:
log.Fatal(4, "Invalid protocol: %s", setting.Protocol)
}