aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorBoris Rybalkin <ribalkin@gmail.com>2023-03-01 21:57:30 +0000
committerGitHub <noreply@github.com>2023-03-01 22:57:30 +0100
commit6b1c9eafa97cb02dd902ddbf2676c709c86f9625 (patch)
tree143506c78aa0ece86f1838de79ace4b060912606 /cmd
parent6c20f8f742a7e03710fae81df6ef98bac31da2b1 (diff)
unix socket support (#2974)
### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `Boris Rybalkin <ribalkin@gmail.com>` I need this for Syncloud project (https://github.com/syncloud/platform) where I run multiple apps behind an nginx on the same RPi like device so unix socket is very convenient to not have port conflicts between apps. Also someone opened this Issue: https://github.com/matrix-org/dendrite/issues/2924 --------- Co-authored-by: kegsay <kegan@matrix.org> Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dendrite/main.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/cmd/dendrite/main.go b/cmd/dendrite/main.go
index e8ff0a47..1ae348cf 100644
--- a/cmd/dendrite/main.go
+++ b/cmd/dendrite/main.go
@@ -16,6 +16,7 @@ package main
import (
"flag"
+ "io/fs"
"github.com/sirupsen/logrus"
@@ -30,6 +31,12 @@ import (
)
var (
+ unixSocket = flag.String("unix-socket", "",
+ "EXPERIMENTAL(unstable): The HTTP listening unix socket for the server (disables http[s]-bind-address feature)",
+ )
+ unixSocketPermission = flag.Int("unix-socket-permission", 0755,
+ "EXPERIMENTAL(unstable): The HTTP listening unix socket permission for the server",
+ )
httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server")
httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server")
certFile = flag.String("tls-cert", "", "The PEM formatted X509 certificate to use for TLS")
@@ -38,8 +45,23 @@ var (
func main() {
cfg := setup.ParseFlags(true)
- httpAddr := config.HTTPAddress("http://" + *httpBindAddr)
- httpsAddr := config.HTTPAddress("https://" + *httpsBindAddr)
+ httpAddr := config.ServerAddress{}
+ httpsAddr := config.ServerAddress{}
+ if *unixSocket == "" {
+ http, err := config.HTTPAddress("http://" + *httpBindAddr)
+ if err != nil {
+ logrus.WithError(err).Fatalf("Failed to parse http address")
+ }
+ httpAddr = http
+ https, err := config.HTTPAddress("https://" + *httpsBindAddr)
+ if err != nil {
+ logrus.WithError(err).Fatalf("Failed to parse https address")
+ }
+ httpsAddr = https
+ } else {
+ httpAddr = config.UnixSocketAddress(*unixSocket, fs.FileMode(*unixSocketPermission))
+ }
+
options := []basepkg.BaseDendriteOptions{}
base := basepkg.NewBaseDendrite(cfg, options...)
@@ -92,7 +114,7 @@ func main() {
base.SetupAndServeHTTP(httpAddr, nil, nil)
}()
// Handle HTTPS if certificate and key are provided
- if *certFile != "" && *keyFile != "" {
+ if *unixSocket == "" && *certFile != "" && *keyFile != "" {
go func() {
base.SetupAndServeHTTP(httpsAddr, certFile, keyFile)
}()