From a84eecc88893d81fa208c16007178610a914492a Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 11 Mar 2022 16:28:12 +0000 Subject: [PATCH] Platform sanity checks --- setup/base/base.go | 1 + setup/base/sanity_other.go | 8 ++++++++ setup/base/sanity_unix.go | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 setup/base/sanity_other.go create mode 100644 setup/base/sanity_unix.go diff --git a/setup/base/base.go b/setup/base/base.go index ef3b2be29..692a77d5c 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -100,6 +100,7 @@ const ( // The componentName is used for logging purposes, and should be a friendly name // of the compontent running, e.g. "SyncAPI" func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite { + platformSanityChecks() useHTTPAPIs := false cacheMetrics := true for _, opt := range options { diff --git a/setup/base/sanity_other.go b/setup/base/sanity_other.go new file mode 100644 index 000000000..48fe6e1f8 --- /dev/null +++ b/setup/base/sanity_other.go @@ -0,0 +1,8 @@ +//go:build !linux && !darwin && !netbsd && !freebsd && !openbsd && !solaris && !dragonfly && !aix +// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!solaris,!dragonfly,!aix + +package base + +func platformSanityChecks() { + // Nothing to do yet. +} diff --git a/setup/base/sanity_unix.go b/setup/base/sanity_unix.go new file mode 100644 index 000000000..de29a6b86 --- /dev/null +++ b/setup/base/sanity_unix.go @@ -0,0 +1,27 @@ +//go:build linux || darwin || netbsd || freebsd || openbsd || solaris || dragonfly || aix +// +build linux darwin netbsd freebsd openbsd solaris dragonfly aix + +package base + +import ( + "syscall" + + "github.com/sirupsen/logrus" +) + +func platformSanityChecks() { + // If Dendrite is running as root, that's probably bad. + if syscall.Geteuid() == 0 { + logrus.Warnf("IMPORTANT: Dendrite is currently running as root, this is potentially dangerous!") + } + + // Dendrite needs a relatively high number of file descriptors in order + // to function properly, particularly when federating with lots of servers. + // If we run out of file descriptors, we might run into problems accessing + // PostgreSQL amongst other things. Complain at startup if we think the + // number of file descriptors is too low. + var rLimit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err == nil && rLimit.Cur < 65535 { + logrus.Warnf("IMPORTANT: Process file descriptor limit is currently %d, it is recommended to raise the limit for Dendrite to at least 65535 to avoid issues", rLimit.Cur) + } +}